# Path: elem/score/score_manager.py
# class ScoreManager(object):
#     def __init__(self):
#         self.scores = dict()
# 
#     def add_score(self, name, pattern, example=None):
#         if name not in self.scores.keys():
#             self.scores[name] = Score(name, pattern, example)
# 
#     def delete_score(self, name):
#         self.scores.pop(name)
# 
#     def get_pattern(self, name):
#         return self.scores[name].pattern
# 
#     def update_score(self, name, pattern):
#         self.scores[name] = Score(name, pattern)
# 
#     def is_valid(self, name, value):
#         return self.scores[name].is_valid(value)
# 
#     def __str__(self):
#         score_strings = ['name,pattern,example']
#         for _, score in self.scores.iteritems():
#             score_strings.append(str(score))
#         return '\n'.join(score_strings)
# 
#     def __iter__(self):
#         return iter(self.scores)
# 
# Path: elem/score/score.py
# class InvalidExample(Exception):
#     def __init__(self, name, pattern, example):
#         message = "For score {0}, example {1} does not match pattern {2}.".format(name, example, pattern)
#         super(InvalidExample, self).__init__(message)


import unittest
from elem.score import ScoreManager
from elem.score import InvalidExample

class TestScoreManager(unittest.TestCase):
    def setUp(self):
        self.stride_pattern = r'^(\d)(\d)(\d)(\d)(\d)(\d)$'
        self.skipped_pattern = r'^(19|20)(\d\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$|^(19|20)(\d\d)(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'
        self.manager = ScoreManager()

    def test_add(self):
        self.assertEqual(len(self.manager.scores), 0)
        self.manager.add_score('stride', self.stride_pattern)
        self.assertEqual(len(self.manager.scores), 1)
        self.assertIn('stride', self.manager.scores.keys())
        #Add again, ensure it doesn't grow and the patter doesn't change
        self.manager.add_score('stride', r'\d\d\d\d\d\d\d')
        self.assertEqual(len(self.manager.scores), 1)
        self.assertEqual(self.stride_pattern, self.manager.get_pattern('stride'))
        #Add new score
        self.manager.add_score('skipped', self.skipped_pattern)
        self.assertEqual(len(self.manager.scores), 2)
        self.assertIn('stride', self.manager.scores.keys())
        self.assertIn('skipped', self.manager.scores.keys())


# Path: elem/score/score_manager.py
# class ScoreManager(object):
#     def __init__(self):
#         self.scores = dict()
# 
#     def add_score(self, name, pattern, example=None):
#         if name not in self.scores.keys():
#             self.scores[name] = Score(name, pattern, example)
# 
#     def delete_score(self, name):
#         self.scores.pop(name)
# 
#     def get_pattern(self, name):
#         return self.scores[name].pattern
# 
#     def update_score(self, name, pattern):
#         self.scores[name] = Score(name, pattern)
# 
#     def is_valid(self, name, value):
#         return self.scores[name].is_valid(value)
# 
#     def __str__(self):
#         score_strings = ['name,pattern,example']
#         for _, score in self.scores.iteritems():
#             score_strings.append(str(score))
#         return '\n'.join(score_strings)
# 
#     def __iter__(self):
#         return iter(self.scores)
# 
# Path: elem/score/score.py
# class InvalidExample(Exception):
#     def __init__(self, name, pattern, example):
#         message = "For score {0}, example {1} does not match pattern {2}.".format(name, example, pattern)
#         super(InvalidExample, self).__init__(message)


# Path: tests/score/test_score_manager.py
import unittest
from elem.score import ScoreManager
from elem.score import InvalidExample


class TestScoreManager(unittest.TestCase):
    def setUp(self):
        self.stride_pattern = r'^(\d)(\d)(\d)(\d)(\d)(\d)$'
        self.skipped_pattern = r'^(19|20)(\d\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$|^(19|20)(\d\d)(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'
        self.manager = ScoreManager()

    def test_add(self):
        self.assertEqual(len(self.manager.scores), 0)
        self.manager.add_score('stride', self.stride_pattern)
        self.assertEqual(len(self.manager.scores), 1)
        self.assertIn('stride', self.manager.scores.keys())
        #Add again, ensure it doesn't grow and the patter doesn't change
        self.manager.add_score('stride', r'\d\d\d\d\d\d\d')
        self.assertEqual(len(self.manager.scores), 1)
        self.assertEqual(self.stride_pattern, self.manager.get_pattern('stride'))
        #Add new score
        self.manager.add_score('skipped', self.skipped_pattern)
        self.assertEqual(len(self.manager.scores), 2)
        self.assertIn('stride', self.manager.scores.keys())
        self.assertIn('skipped', self.manager.scores.keys())


    def test_delete_no_key(self):