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')
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.')
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.')
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.')
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.')
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.")
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.')
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.')
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.')
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.")
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)
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')
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')