Пример #1
0
    def test_duration_init_correctly_initializes_an_object(self):
        test1 = Duration('5:55')
        test2 = Duration('6:23:11')

        self.assertEqual(test1.hours, '0')
        self.assertEqual(test1.minutes, '5')
        self.assertEqual(test1.seconds, '55')

        self.assertEqual(test2.hours, '6')
        self.assertEqual(test2.minutes, '23')
        self.assertEqual(test2.seconds, '11')
Пример #2
0
    def test_length_validation_raises_exception_if_hours_less_than_zero(self):
        length = '-3:45:2'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Hours cannot be negative.')
Пример #3
0
    def test_length_validation_raises_exception_if_less_than_4_characters(
            self):
        length = ':22'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Length cannot be less than 4 symbols.')
Пример #4
0
    def test_length_validation_raises_exception_if_seconds_greater_than_sixty(
            self):
        length = '20:65'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Seconds cannot be more than 59.')
Пример #5
0
    def test_length_validation_raises_exception_if_more_than_2_dots(self):
        length = '5:3:5:'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc), 'Length can only include seconds, minutes and hours.')
Пример #6
0
    def test_length_validation_raises_exception_if_Duration_length_is_zero(
            self):
        length = '00:00'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), "Duration's length cannot be zero.")
Пример #7
0
    def test_length_validation_raises_exception_if_seconds_not_represented_by_two_digits(
            self):
        length = '45:2'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Two digits represent seconds.')
Пример #8
0
    def test_length_validation_raises_exception_if_dots_are_not_placed_correctly(
            self):
        length = '5::5'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc),
                         'Error: Found ":" in an unexpected position.')
Пример #9
0
    def test_length_validation_raises_exception_if_no_dots(self):
        length = '5555'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc),
            'Length must have ":" to distinguish seconds, minutes and hours.')
Пример #10
0
    def test_length_validation_raises_exception_if_mins_not_represented_by_two_digits_if_hour(
            self):
        length = '1:5:22'
        exc = None

        try:
            Duration.is_valid_length(length)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc),
            "Two digits represent minutes, if duration is more than an hour.")
Пример #11
0
 def test_duration_eq_dunder_correctly_compares_duration_objects(self):
     test1 = Duration('5:55')
     test2 = Duration('5:55')
     test3 = Duration('6:23:11')
     self.assertEqual(test1, test2)
     self.assertNotEqual(test2, test3)
Пример #12
0
    def test_duration_str_dunder_representation_is_as_expected(self):
        test1 = Duration('5:55')
        test2 = Duration('6:23:11')

        self.assertEqual(str(test1), '5:55')
        self.assertEqual(str(test2), '6:23:11')
Пример #13
0
 def test_length_validation_passes_with_correct_input(self):
     Duration.is_valid_length('0:01')
     Duration.is_valid_length('50:21')
     Duration.is_valid_length('1:10:01')
     Duration.is_valid_length('10:00')
     Duration.is_valid_length('0:55')