-
-
Notifications
You must be signed in to change notification settings - Fork 273
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?
Changes from 1 commit
9d43b8b
8558783
ea7e00c
7b64029
f290799
aee6a4f
ae47b0c
4792575
3bd121a
c9b1c7d
65578d2
589841c
fd74934
41893ad
4fc59b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Writing tests to cover edge cases will protect your implementation from unexpected situations and make your code more robust. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ test("should count multiple occurrences of a character", () => { | |
| const str = "aaaaa"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| expect(parseInt(count)).toEqual(5); | ||
| }); | ||
|
|
||
| // Scenario: No Occurrences | ||
|
|
@@ -27,5 +27,29 @@ test("should return 0 when character does not exist in the string", () => { | |
| const str = "abcdefg"; | ||
| const char = "h"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| expect(parseInt(count)).toEqual(0); | ||
| }); | ||
|
|
||
| // test for empty string | ||
| test("should return 0 when string is empty", () => { | ||
| const str = ""; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(parseInt(count)).toEqual(0); | ||
| }); | ||
|
|
||
| // test for str is an array | ||
| test("should return 0 when str is an array", () => { | ||
|
||
| const str = ["a", "b", "c"]; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(parseInt(count)).toEqual(1); | ||
| }); | ||
|
|
||
| // test for str is a number | ||
| test("should return 0 when str is a number", () => { | ||
|
||
| const str = 12345; | ||
| const char = "3"; | ||
| const count = countChar(str, char); | ||
| expect(parseInt(count)).toEqual(1); | ||
| }); | ||
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.