Skip to content

Commit e751012

Browse files
committed
clock: add more test cases to canonical test data
In the Go track I've seen a lot of people who only account for a clock overflowing once in either direction. As the README describes the problem, any overflow should be corrected, even if it accounts for several days. The second problem that I've seen a lot is people who adjust in the display method, which means that the clocks would fail the equality check. We weren't verifying equality against overflow, however, so we didn't catch this. I also removed two redundant test cases.
1 parent 411222f commit e751012

File tree

1 file changed

+187
-23
lines changed

1 file changed

+187
-23
lines changed

clock.json

Lines changed: 187 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@
1717
"minute": 0,
1818
"expected": "08:00"
1919
},
20-
{
21-
"description": "on the hour",
22-
"hour": 9,
23-
"minute": 0,
24-
"expected": "09:00"
25-
},
2620
{
2721
"description": "past the hour",
2822
"hour": 11,
2923
"minute": 9,
3024
"expected": "11:09"
3125
},
32-
{
33-
"description": "past the hour",
34-
"hour": 11,
35-
"minute": 19,
36-
"expected": "11:19"
37-
},
3826
{
3927
"description": "midnight is zero hours",
4028
"hour": 24,
@@ -47,6 +35,12 @@
4735
"minute": 0,
4836
"expected": "01:00"
4937
},
38+
{
39+
"description": "hour rolls over continuously",
40+
"hour": 100,
41+
"minute": 0,
42+
"expected": "04:00"
43+
},
5044
{
5145
"description": "sixty minutes is next hour",
5246
"hour": 1,
@@ -59,12 +53,30 @@
5953
"minute": 160,
6054
"expected": "02:40"
6155
},
56+
{
57+
"description": "minutes roll over continuously",
58+
"hour": 0,
59+
"minute": 1723,
60+
"expected": "04:43"
61+
},
6262
{
6363
"description": "hour and minutes roll over",
6464
"hour": 25,
6565
"minute": 160,
6666
"expected": "03:40"
6767
},
68+
{
69+
"description": "hour and minutes roll over continuously",
70+
"hour": 201,
71+
"minute": 3001,
72+
"expected": "11:01"
73+
},
74+
{
75+
"description": "hour and minutes roll over to exactly midnight",
76+
"hour": 72,
77+
"minute": 8640,
78+
"expected": "00:00"
79+
},
6880
{
6981
"description": "negative hour",
7082
"hour": -1,
@@ -77,6 +89,12 @@
7789
"minute": 0,
7890
"expected": "23:00"
7991
},
92+
{
93+
"description": "negative hour rolls over continuously",
94+
"hour": -91,
95+
"minute": 0,
96+
"expected": "05:00"
97+
},
8098
{
8199
"description": "negative minutes",
82100
"hour": 1,
@@ -89,11 +107,23 @@
89107
"minute": -160,
90108
"expected": "22:20"
91109
},
110+
{
111+
"description": "negative minutes roll over continuously",
112+
"hour": 1,
113+
"minute": -4820,
114+
"expected": "16:40"
115+
},
92116
{
93117
"description": "negative hour and minutes both roll over",
94118
"hour": -25,
95119
"minute": -160,
96120
"expected": "20:20"
121+
},
122+
{
123+
"description": "negative hour and minutes both roll over continuously",
124+
"hour": -121,
125+
"minute": -5810,
126+
"expected": "22:10"
97127
}
98128
]
99129
},
@@ -123,6 +153,13 @@
123153
"add": 61,
124154
"expected": "11:01"
125155
},
156+
{
157+
"description": "add more than two hours with carry",
158+
"hour": 0,
159+
"minute": 45,
160+
"add": 160,
161+
"expected": "03:25"
162+
},
126163
{
127164
"description": "add across midnight",
128165
"hour": 23,
@@ -138,11 +175,11 @@
138175
"expected": "06:32"
139176
},
140177
{
141-
"description": "add more than two hours with carry",
142-
"hour": 0,
143-
"minute": 45,
144-
"add": 160,
145-
"expected": "03:25"
178+
"description": "add more than two days",
179+
"hour": 1,
180+
"minute": 1,
181+
"add": 3500,
182+
"expected": "11:21"
146183
},
147184
{
148185
"description": "subtract minutes",
@@ -179,6 +216,13 @@
179216
"add": -160,
180217
"expected": "21:20"
181218
},
219+
{
220+
"description": "subtract more than two hours with borrow",
221+
"hour": 6,
222+
"minute": 15,
223+
"add": -160,
224+
"expected": "03:35"
225+
},
182226
{
183227
"description": "subtract more than one day (1500 min = 25 hrs)",
184228
"hour": 5,
@@ -187,11 +231,11 @@
187231
"expected": "04:32"
188232
},
189233
{
190-
"description": "subtract more than two hours with borrow",
191-
"hour": 6,
192-
"minute": 15,
193-
"add": -160,
194-
"expected": "03:35"
234+
"description": "subtract more than two days",
235+
"hour": 2,
236+
"minute": 20,
237+
"add": -3000,
238+
"expected": "00:20"
195239
}
196240
]
197241
},
@@ -237,7 +281,7 @@
237281
"expected": false
238282
},
239283
{
240-
"description": "clocks set 24 hours apart",
284+
"description": "clocks with hour overflow",
241285
"clock1": {
242286
"hour": 10,
243287
"minute": 37
@@ -248,6 +292,54 @@
248292
},
249293
"expected": true
250294
},
295+
{
296+
"description": "clocks with hour overflow by several days",
297+
"clock1": {
298+
"hour": 3,
299+
"minute": 11
300+
},
301+
"clock2": {
302+
"hour": 99,
303+
"minute": 11
304+
},
305+
"expected": true
306+
},
307+
{
308+
"description": "clocks with negative hour",
309+
"clock1": {
310+
"hour": 22,
311+
"minute": 40
312+
},
313+
"clock2": {
314+
"hour": -2,
315+
"minute": 40
316+
},
317+
"expected": true
318+
},
319+
{
320+
"description": "clocks with negative hour that wraps",
321+
"clock1": {
322+
"hour": 17,
323+
"minute": 3
324+
},
325+
"clock2": {
326+
"hour": -31,
327+
"minute": 3
328+
},
329+
"expected": true
330+
},
331+
{
332+
"description": "clocks with negative hour that wraps multiple times",
333+
"clock1": {
334+
"hour": 13,
335+
"minute": 49
336+
},
337+
"clock2": {
338+
"hour": -83,
339+
"minute": 49
340+
},
341+
"expected": true
342+
},
251343
{
252344
"description": "clocks with minute overflow",
253345
"clock1": {
@@ -259,6 +351,78 @@
259351
"minute": 1441
260352
},
261353
"expected": true
354+
},
355+
{
356+
"description": "clocks with minute overflow by several days",
357+
"clock1": {
358+
"hour": 2,
359+
"minute": 2
360+
},
361+
"clock2": {
362+
"hour": 2,
363+
"minute": 4322
364+
},
365+
"expected": true
366+
},
367+
{
368+
"description": "clocks with negative minute",
369+
"clock1": {
370+
"hour": 2,
371+
"minute": 40
372+
},
373+
"clock2": {
374+
"hour": 3,
375+
"minute": -20
376+
},
377+
"expected": true
378+
},
379+
{
380+
"description": "clocks with negative minute that wraps",
381+
"clock1": {
382+
"hour": 4,
383+
"minute": 10
384+
},
385+
"clock2": {
386+
"hour": 5,
387+
"minute": -1490
388+
},
389+
"expected": true
390+
},
391+
{
392+
"description": "clocks with negative minute that wraps multiple times",
393+
"clock1": {
394+
"hour": 6,
395+
"minute": 15
396+
},
397+
"clock2": {
398+
"hour": 6,
399+
"minute": -4305
400+
},
401+
"expected": true
402+
},
403+
{
404+
"description": "clocks with negative hours and minutes",
405+
"clock1": {
406+
"hour": 7,
407+
"minute": 32
408+
},
409+
"clock2": {
410+
"hour": -12,
411+
"minute": -268
412+
},
413+
"expected": true
414+
},
415+
{
416+
"description": "clocks with negative hours and minutes that wrap",
417+
"clock1": {
418+
"hour": 18,
419+
"minute": 7
420+
},
421+
"clock2": {
422+
"hour": -54,
423+
"minute": -11513
424+
},
425+
"expected": true
262426
}
263427
]
264428
}

0 commit comments

Comments
 (0)