NW | 25-ITP-Sep | TzeMing Ho | Sprint 3 | coursework/sprint-3-practice-tdd#710
NW | 25-ITP-Sep | TzeMing Ho | Sprint 3 | coursework/sprint-3-practice-tdd#710TzeMingHo wants to merge 15 commits intoCodeYourFuture:mainfrom
Conversation
jenny-alexander
left a comment
There was a problem hiding this comment.
Great job @TzeMingHo following the principles of TDD. I added a few comments that wll help you write more reliable code.
There was a problem hiding this comment.
It might have been a leftover from debugging, but console logs should be removed before submitting your PR.
There was a problem hiding this comment.
You have written some good tests cases that cover the main cases. However, can you think of some edge cases that should be tested?
- what if str is not a string (i.e. a number)
- what if count is not a number (i.e. "2")
- what if string is empty or null, what should it return?
There was a problem hiding this comment.
@TzeMingHo For this exercise, it says:
"Given a target string str and a positive integer count,"
This means that a number, boolean, null (basically anything not a string), should be considered invalid input.
Converting a non-string to a string would be considered out of scope for this exercise :)
The count should be a positive integer (1,2,3,4,5, etc) and can't have a decimal.
There was a problem hiding this comment.
Your test case covers the most basic cases - but can you think of some edge cases you should write tests for?
- what is count is 2.5?
- what if the count is null or undefined
- what if the string is an array or an object instead of a string?
Writing tests to cover edge cases will protect your implementation from unexpected situations and make your code more robust.
| }); | ||
|
|
||
| // test for str is an array | ||
| test("should return 0 when str is an array", () => { |
There was a problem hiding this comment.
Maybe a typo in your test assertion here (should be a 1 instead of 0)?
| }); | ||
|
|
||
| // test for str is a number | ||
| test("should return 0 when str is a number", () => { |
There was a problem hiding this comment.
Maybe a typo in your test assertion here (should be a 1 instead of 0)?
There was a problem hiding this comment.
@TzeMingHo For this exercise, it says:
"Given a target string str and a positive integer count,"
This means that a number, boolean, null (basically anything not a string), should be considered invalid input.
Converting a non-string to a string would be considered out of scope for this exercise :)
The count should be a positive integer (1,2,3,4,5, etc) and can't have a decimal.
|
Your test cases are very thorough now. Great job 😃 |
|
Thank you, Jenny. |
Learners, PR Template
Self checklist
Changelist
In the exercises, I wrote tests first, followed by writing functions to fulfill them. Some edge cases were also attempted to be implemented in the tests.