def test_sub_positive_from_negative(self):
     time_1 = Time.from_string(self._str_negative_large)
     time_2 = Time.from_string(self._str_positive_huge)
     res = time_1 - time_2
     self.assertEqual(141, res.hours())
     self.assertEqual(30, res.minutes())
     self.assertTrue(res.is_negative())
 def test_sub_negatives_result_positive(self):
     time_1 = Time.from_string(self._str_negative_small)
     time_2 = Time.from_string(self._str_negative_huge)
     res = time_1 - time_2
     self.assertEqual(117, res.hours())
     self.assertEqual(15, res.minutes())
     self.assertTrue(res.is_positive())
 def test_sub_negative_from_positive(self):
     time_1 = Time.from_string(self._str_positive_large)
     time_2 = Time.from_string(self._str_negative_small)
     res = time_1 - time_2
     self.assertEqual(24, res.hours())
     self.assertEqual(15, res.minutes())
     self.assertTrue(res.is_positive())
 def test_add_result_negative(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = Time.from_string(self._str_negative_large)
     res = time_1 + time_2
     self.assertEqual(7, res.hours())
     self.assertEqual(25, res.minutes())
     self.assertTrue(res.is_negative())
 def test_add_huge_negatives(self):
     time_1 = Time.from_string(self._str_negative_huge)
     time_2 = Time.from_string(self._str_negative_huge)
     res = time_1 + time_2
     self.assertEqual(251, res.hours())
     self.assertEqual(20, res.minutes())
     self.assertTrue(res.is_negative())
 def test_add_large_positives(self):
     time_1 = Time.from_string(self._str_positive_large)
     time_2 = Time.from_string(self._str_positive_large)
     res = time_1 + time_2
     self.assertEqual(31, res.hours())
     self.assertEqual(40, res.minutes())
     self.assertTrue(res.is_positive())
 def test_add_small_positives(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = Time.from_string(self._str_positive_small)
     res = time_1 + time_2
     self.assertEqual(16, res.hours())
     self.assertEqual(50, res.minutes())
     self.assertTrue(res.is_positive())
Example #8
0
 def test_time_input_valid(self, mock_print):
     with patch('builtins.input', return_value='6:12'):
         self.assertEqual(Time(6, 12, False), time_input('Time please.'))
     with patch('builtins.input', return_value='13:42'):
         self.assertEqual(Time(13, 42, False), time_input('Time please.'))
     with patch('builtins.input', return_value='-2:34'):
         self.assertEqual(Time(2, 34, True), time_input('Time please.'))
     with patch('builtins.input', return_value='-21:16'):
         self.assertEqual(Time(21, 16, True), time_input('Time please.'))
def time_input(request: str):
    input_invalid = True
    response = ''
    valid_time_regex = re.compile('-?[0-9]{1,2}:[0-9]{2}')
    while input_invalid:
        response = input(format_time_input(request))
        input_invalid = not valid_time_regex.match(response)
        if input_invalid:
            print(
                'The input was invalid, please enter the time in the format hh:mm (h = hour, m = minute).'
            )
    return Time.from_string(response)
 def test_value_positive(self):
     time = Time.from_string(self._str_positive_small)
     self.assertEqual(505, time.value())
 def test_value_negative(self):
     time = Time.from_string(self._str_negative_huge)
     self.assertEqual(-7540, time.value())
 def test_str_positive(self):
     time = Time.from_string(self._str_positive_large)
     self.assertEqual('15:50', str(time))
 def test_repr_negative(self):
     time = Time.from_string(self._str_negative_large)
     self.assertEqual('-15:50', repr(time))
 def test_as_string_large_negative(self):
     time = Time.from_string(self._str_negative_large)
     self.assertEqual('-15:50', time.as_string())
 def test_as_string_huge_negative(self):
     time = Time.from_string(self._str_negative_huge)
     self.assertEqual('-125:40', time.as_string())
 def test_ge_invalid_type(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = 45
     with self.assertRaises(AssertionError):
         time_1 >= time_2
 def test_ne(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = Time.from_string(self._str_negative_small)
     self.assertTrue(time_1 != time_2)
 def test_gt_negatives(self):
     time_1 = Time.from_string(self._str_negative_small)
     time_2 = Time.from_string(self._str_negative_large)
     self.assertFalse(time_1 > time_1)
     self.assertFalse(time_2 > time_1)
     self.assertTrue(time_1 > time_2)
 def test_ge(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = Time.from_string(self._str_negative_small)
     self.assertTrue(time_1 >= time_2)
     self.assertFalse(time_2 >= time_1)
 def test_from_string_negative(self):
     time = Time.from_string(self._str_negative_huge)
     self.assertEqual(125, time.hours())
     self.assertEqual(40, time.minutes())
     self.assertTrue(time.is_negative())
 def test_time_required_calculation(self):
     time = Time.required_time_calculation(21, 11.5)
     self.assertEqual(34, time.hours())
     self.assertEqual(30, time.minutes())
     self.assertTrue(time.is_positive())
 def test_le_positives(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = Time.from_string(self._str_positive_large)
     self.assertTrue(time_1 <= time_2)
     self.assertTrue(time_1 <= time_1)
     self.assertFalse(time_2 <= time_1)
 def test_hash_negative(self):
     time = Time.from_string(self._str_negative_huge)
     self.assertEqual(hash(-7540), hash(time))
 def test_as_string_small_negative(self):
     time = Time.from_string(self._str_negative_small)
     self.assertEqual('-08:25', time.as_string())
 def test_lt_invalid_type(self):
     time_1 = Time.from_string(self._str_negative_small)
     time_2 = 45
     with self.assertRaises(AssertionError):
         time_1 < time_2
 def test_eq(self):
     time_1 = Time.from_string(self._str_positive_small)
     time_2 = Time.from_string(self._str_negative_small)
     self.assertFalse(time_1 == time_2)