# Path: elem/score/score.py
# class Score(object):
#     def __init__(self, name, pattern, example=None):
#         self.name = name
#         self.pattern = pattern
#         self.regex = re.compile(pattern)
#         self.example = example
#         if self.example and not self.is_valid(self.example):
#             raise InvalidExample(self.name, self.pattern, self.example)
# 
#     def is_valid(self, score_string):
#         if not isinstance(score_string, str):
#             score_string = str(score_string)
#         matches = re.search(self.regex, score_string)
#         if not matches:
#             return False
#         return True
# 
#     def __str__(self):
#         return "{0},{1},{2}".format(self.name, self.pattern, self.example or '')
# 
#     def __iter__(self):
#         score_dict = dict()
#         score_dict[self.name] = dict(pattern=self.pattern, example=self.example or '')
#         return iter(score_dict)
# 
# 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 Score
from elem.score import InvalidExample

class TestStrideScore(unittest.TestCase):
    def setUp(self):
        self.pattern = r'^(\d)(\d)(\d)(\d)(\d)(\d)$'
        self.stride = Score('stride', self.pattern)

    def test_name(self):
        self.assertEqual('stride', self.stride.name)

    def test_valid(self):
        self.assertTrue(self.stride.is_valid(123456))
        self.assertTrue(self.stride.is_valid("000000"))

    def test_invalid(self):
        self.assertFalse(self.stride.is_valid('1234567'))
        self.assertFalse(self.stride.is_valid('ABCDEF'))
        self.assertFalse(self.stride.is_valid(''))
        self.assertFalse(self.stride.is_valid('2017-10-27'))

    def test_example(self):
        with self.assertRaises(InvalidExample) as error:

# Path: elem/score/score.py
# class Score(object):
#     def __init__(self, name, pattern, example=None):
#         self.name = name
#         self.pattern = pattern
#         self.regex = re.compile(pattern)
#         self.example = example
#         if self.example and not self.is_valid(self.example):
#             raise InvalidExample(self.name, self.pattern, self.example)
# 
#     def is_valid(self, score_string):
#         if not isinstance(score_string, str):
#             score_string = str(score_string)
#         matches = re.search(self.regex, score_string)
#         if not matches:
#             return False
#         return True
# 
#     def __str__(self):
#         return "{0},{1},{2}".format(self.name, self.pattern, self.example or '')
# 
#     def __iter__(self):
#         score_dict = dict()
#         score_dict[self.name] = dict(pattern=self.pattern, example=self.example or '')
#         return iter(score_dict)
# 
# 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.py
import unittest
from elem.score import Score
from elem.score import InvalidExample


class TestStrideScore(unittest.TestCase):
    def setUp(self):
        self.pattern = r'^(\d)(\d)(\d)(\d)(\d)(\d)$'
        self.stride = Score('stride', self.pattern)

    def test_name(self):
        self.assertEqual('stride', self.stride.name)

    def test_valid(self):
        self.assertTrue(self.stride.is_valid(123456))
        self.assertTrue(self.stride.is_valid("000000"))

    def test_invalid(self):
        self.assertFalse(self.stride.is_valid('1234567'))
        self.assertFalse(self.stride.is_valid('ABCDEF'))
        self.assertFalse(self.stride.is_valid(''))
        self.assertFalse(self.stride.is_valid('2017-10-27'))

    def test_example(self):
        with self.assertRaises(InvalidExample) as error:

            stride = Score('stride', self.pattern, '1234568')