-
-
Notifications
You must be signed in to change notification settings - Fork 218
NW | 25-ITP-Sep | TzeMing Ho | Sprint 3 | coursework/sprint-3-practice-tdd #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
NW | 25-ITP-Sep | TzeMing Ho | Sprint 3 | coursework/sprint-3-practice-tdd #710
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a typo in your test assertion here (should be a 1 instead of 0)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
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.