Skip to content

Commit 552c37c

Browse files
Add comprehensive edge case tests for 12-hour clock
1 parent a4bab84 commit 552c37c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎Sprint-3/5-stretch-extend/format-time.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,38 @@ console.assert(
2323
currentOutput2 === targetOutput2,
2424
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2525
);
26+
// Test 3: Edge case for 12:00 (Noon)
27+
// The current function logic thinks 12 > 12 is false, so it returns "12:00 am".
28+
// This is technically a bug in the provided function, but a good test case!
29+
const currentOutput3 = formatAs12HourClock("12:00");
30+
const targetOutput3 = "12:00 pm"; // Correct expectation
31+
console.assert(
32+
currentOutput3 === targetOutput3,
33+
`Noon Test Failed -> current output: ${currentOutput3}, target output: ${targetOutput3}`
34+
);
35+
36+
// Test 4: Check for formatting bug (dropping minutes)
37+
// The current function returns `${hours - 12}:00 pm` which ignores the minutes.
38+
const currentOutput4 = formatAs12HourClock("13:45");
39+
const targetOutput4 = "01:45 pm";
40+
console.assert(
41+
currentOutput4 === targetOutput4,
42+
`Minute Formatting Failed -> current output: ${currentOutput4}, target output: ${targetOutput4}`
43+
);
44+
45+
// Test 5: Test single digit hour formatting
46+
// Usually, 12-hour clocks are written as "01:00 pm", not "1:00 pm"
47+
const currentOutput5 = formatAs12HourClock("13:00");
48+
const targetOutput5 = "01:00 pm";
49+
console.assert(
50+
currentOutput5 === targetOutput5,
51+
`Hour Padding Failed -> current output: ${currentOutput5}, target output: ${targetOutput5}`
52+
);
53+
54+
// Test 6: Midnight check
55+
const currentOutput6 = formatAs12HourClock("00:00");
56+
const targetOutput6 = "12:00 am";
57+
console.assert(
58+
currentOutput6 === targetOutput6,
59+
`Midnight Test Failed -> current output: ${currentOutput6}, target output: ${targetOutput6}`
60+
);

0 commit comments

Comments
 (0)