London | 26-ITP-Sept | Fung Nin Lee | Sprint 1| formatAs12HourClock - #1631
leerogerfn wants to merge 7 commits into
Conversation
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Your fix works for all three bugs in the starter. Minutes are kept after noon, 12:xx is now pm, and 00:xx is now 12 am.
Three things before I can mark this Complete:
- The two tests from the starter are gone. See my comment on
timeConverter.test.jsline 5. - Some edge cases have no test yet. See my comment on line 21.
- Both files fail Prettier. Prettier is a tool that formats your code to one agreed style. Then a reviewer only sees the changes you meant to make. Open each file you changed, right click, and choose Format Document. Pick Prettier if VS Code asks. To format every time you save, follow the steps here: https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data#2-enable-formatting-on-save
Add the Needs Review label again once you've pushed.
|
|
||
| test("correctly convert time after 12:00", function(){ | ||
| assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); | ||
| test("can return 'invalid input.'", function(){ |
There was a problem hiding this comment.
The starter file had two tests here:
"23:00"should give"11:00 pm""08:00"should give"08:00 am"
These tests show the format the function must give. There is a space before am and pm, and 08 keeps its zero.
Your code now gives "11:00pm" and "8:00am". So your tests check a different format.
Please put the two starter tests back. Then run the tests. Do they pass? If not, change the function, not the tests.
There was a problem hiding this comment.
The two tests are back, but the expected values are not the starter's:
- Line 6 expects
"11:00pm". The starter expects"11:00 pm". - Line 10 expects
"8:00am". The starter expects"08:00 am".
The tests describe what the function must return, so they stay as the starter wrote them. Please put back those exact two values, run the tests, and change timeConverter.js until they pass. Then check your other tests use the same format.
There was a problem hiding this comment.
Line 6 looks good. Line 10 should still be "08:00 am" like the starter, with the zero.
Your test will fail once you change it back, and that's fine. It means the function is what needs fixing. Line 14 uses hours, which is a number, so 08 turns into 8. Have a look at how the starter returned morning times. It used time instead.
| assert.equal(formatAs12HourClock("00:12"), "12:12am"); | ||
| }); | ||
|
|
||
| test("can correctly convert afternoon time 12:12", function() { |
There was a problem hiding this comment.
You test 12:12 and 00:12. Bugs often hide at the exact point where something changes. Here, that is where am changes to pm, and back again.
Which times are right at that point? For example, what about 11:59, 12:00, 23:59 and 00:00? Can you add a test for each one?
There was a problem hiding this comment.
Good, these are the right times. One typo: line 18 passes "23:159", not "23:59". The test still passes, because your function only reads the last two characters for the minutes. Please fix the input.
There was a problem hiding this comment.
Thanks, that's sorted.
| assert.equal(formatAs12HourClock("-01:00"), "invalid input."); | ||
| }) | ||
|
|
||
| test("can correctly convert morning time 24:12", function() { |
There was a problem hiding this comment.
Not needed for Complete, just a question. On a 24-hour clock, is 24:12 a real time? What comes one minute after 23:59?
The README says you do not need to handle invalid inputs. So you can also remove the invalid-input code and tests if you want.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Thanks. Both files pass Prettier now, and 11:59, 12:00, 23:59 and 00:00 are exactly the right edge cases to test.
Two things before I can mark this Complete:
timeConverter.test.jslines 6 and 10: the starter tests are back, but their expected values changed. See my reply on line 5.timeConverter.test.jsline 18: the input has a typo. See my reply on line 21.
Add the Needs Review label again once you've pushed.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Nearly there, the typo on line 18 is sorted. Just line 10 left, see my reply on line 5. Once that's done I'll mark this Complete.
Learners, PR Template
Self checklist
Task code
CYF-1197
Changelist
fixed the bugs for the formatAs12HourClock. Tested all edge-cases.
Questions
.