Skip to content

Commit 0704fa3

Browse files
mrcfpscmccandless
authored andcommitted
clock: update tests to v2.2.1 (exercism#1324)
* clock: update tests to v2.2.1 * Test 'subtract' instead of 'add negative' * clock: add necessary methods to clock in stub * clock: improve example to pass tests v2.2.1 * clock: fix mistaken test cases Fix following three tests: * subtract to previous hour * subtract more than an hour * subtract across midnight
1 parent 3bab7f6 commit 0704fa3

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

exercises/clock/clock.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@ class Clock(object):
22
def __init__(self, hour, minute):
33
pass
44

5-
def __add__(self, other):
5+
def __repr__(self):
6+
pass
7+
8+
def __eq__(self, other):
9+
pass
10+
11+
def __add__(self, minutes):
12+
pass
13+
14+
def __sub__(self, minutes):
615
pass

exercises/clock/clock_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from clock import Clock
44

5-
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1
65

6+
# Tests adapted from `problem-specifications//canonical-data.json` @ v2.2.1
77

88
class ClockTest(unittest.TestCase):
99
# Test creating a new clock with an initial time.
@@ -90,28 +90,28 @@ def test_add_more_than_two_days(self):
9090
self.assertEqual(str(Clock(1, 1) + 3500), '11:21')
9191

9292
def test_subtract_minutes(self):
93-
self.assertEqual(str(Clock(10, 3) + -3), '10:00')
93+
self.assertEqual(str(Clock(10, 3) - 3), '10:00')
9494

9595
def test_subtract_to_previous_hour(self):
96-
self.assertEqual(str(Clock(10, 3) + -3), '10:00')
96+
self.assertEqual(str(Clock(10, 3) - 30), '09:33')
9797

9898
def test_subtract_more_than_an_hour(self):
99-
self.assertEqual(str(Clock(10, 3) + -30), '09:33')
99+
self.assertEqual(str(Clock(10, 3) - 70), '08:53')
100100

101101
def test_subtract_across_midnight(self):
102-
self.assertEqual(str(Clock(10, 3) + -70), '08:53')
102+
self.assertEqual(str(Clock(0, 3) - 4), '23:59')
103103

104104
def test_subtract_more_than_two_hours(self):
105-
self.assertEqual(str(Clock(0, 0) + -160), '21:20')
105+
self.assertEqual(str(Clock(0, 0) - 160), '21:20')
106106

107107
def test_subtract_more_than_two_hours_with_borrow(self):
108-
self.assertEqual(str(Clock(6, 15) + -160), '03:35')
108+
self.assertEqual(str(Clock(6, 15) - 160), '03:35')
109109

110110
def test_subtract_more_than_one_day(self):
111-
self.assertEqual(str(Clock(5, 32) + -1500), '04:32')
111+
self.assertEqual(str(Clock(5, 32) - 1500), '04:32')
112112

113113
def test_subtract_more_than_two_days(self):
114-
self.assertEqual(str(Clock(2, 20) + -3000), '00:20')
114+
self.assertEqual(str(Clock(2, 20) - 3000), '00:20')
115115

116116
# Construct two separate clocks, set times, test if they are equal.
117117
def test_clocks_with_same_time(self):

exercises/clock/example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class Clock(object):
32
'Clock that displays 24 hour clock that rollsover properly'
43

@@ -17,6 +16,10 @@ def __add__(self, minutes):
1716
self.minute += minutes
1817
return self.cleanup()
1918

19+
def __sub__(self, minutes):
20+
self.minute -= minutes
21+
return self.cleanup()
22+
2023
def cleanup(self):
2124
self.hour += self.minute // 60
2225
self.hour %= 24

0 commit comments

Comments
 (0)