Repository navigation
London | 26-ITP-Sep | Mahir Shah | Sprint 1 | Format clock edge cases - #1653
MahirShah300 wants to merge 3 commits into
Conversation
| test("can correctly convert time after using one digit for hour and . for time separator", function () { | ||
| assert.equal(formatAs12HourClock("3.30"), "03:30 am"); | ||
| }); | ||
|
|
There was a problem hiding this comment.
I have removed the accidental extra test
| }); | ||
|
|
||
| test("can correctly convert time after 12 with minutes that are not 00", function () { | ||
| assert.equal(formatAs12HourClock("23:46"), "23:46 pm"); |
There was a problem hiding this comment.
This tests fails for me. Can you explain why?
AssertionError [ERR_ASSERTION]: '11:46 pm' == '23:46 pm'
at TestContext.<anonymous> (Module-Structuring-and-Testing-Data/format-clock-edge-cases/timeConverter.test.js:14:10)
at Test.runInAsyncScope (node:async_hooks:228:14)
at Test.run (node:internal/test_runner/test:1118:25)
at Test.processPendingSubtests (node:internal/test_runner/test:787:18)
at Test.postRun (node:internal/test_runner/test:1247:19)
at Test.run (node:internal/test_runner/test:1175:12)
at async Test.processPendingSubtests (node:internal/test_runner/test:787:7) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: '11:46 pm',
expected: '23:46 pm',
operator: '==',
diff: 'simple'
}
There was a problem hiding this comment.
The problem is that in my test I incorrectly put the 24 hour time 23:46 pm instead of what should be 11:46 pm
| }); | ||
|
|
||
| test("can correctly convert time using . as time separator", function () { | ||
| assert.equal(formatAs12HourClock("01.30"), "1:30 am"); |
There was a problem hiding this comment.
This tests fails for me. Can you explain why?
actual: '01:30 am',
expected: '1:30 am',
There was a problem hiding this comment.
Because in test I was meant to say the expected value is "01:30 am", I forgot to set the hour to 2 significant figures
|
|
||
| let colonPeriodIndex = 0; | ||
| if (time.indexOf(":") === -1) { | ||
| colonPeriodIndex = time.indexOf("."); |
There was a problem hiding this comment.
What does this line do and why is it needed?
There was a problem hiding this comment.
In this line I get the index of the time separator. First I initialise colonPeriodIndex to 0, then I check if the ":" separator is not in the input string, and then set colonPeriodIndex to the index of "." . It's because I chose to accept "." as a valid separator.
Self checklist
Task code
CYF-1197
Changelist
Made changes to the code to fix bugs, and wrote tests for different inputs