West Midlands | 26-Jan-ITP | Fida H Ali Zada | Sprint 3 | TDD#1134
West Midlands | 26-Jan-ITP | Fida H Ali Zada | Sprint 3 | TDD#1134alizada-dev wants to merge 11 commits intoCodeYourFuture:mainfrom
Conversation
| test(`should return 0 for no occurances of 'char' in 'str'`, () => { | ||
| const str = "code your future"; | ||
| const char = "x"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }) |
There was a problem hiding this comment.
-
Could consider testing more samples.
-
Could consider testing these cases:
- A case to show that the match is case sensitive
- A case to show that the function is expected to work also for non-alphabets
There was a problem hiding this comment.
Thank you, sir, for the review. I fixed all the suggested changes.
| if (count >= 0) { | ||
| return str.repeat(count); | ||
| } else { | ||
| throw new Error(""); |
There was a problem hiding this comment.
Why not include an informative error message to inform the caller what the error is?
| test("should throw an error", () => { | ||
| const str = "responsibility"; | ||
| const count = -5; | ||
| // const repeatedStr = repeatStr(str, count); |
There was a problem hiding this comment.
Why keep the code as comment on line 48?
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
| test(`in case sensitive case, should also return the number of character in the string`, () => { | ||
| expect(countChar("Code Your Future!", "Y")).toEqual(1); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Could include a lower case y in the input to demonstrate and ensure the match is indeed case-sensitive.
| test(`should return the count for unusual characters`, () => { | ||
| expect(countChar("code& $future £your", "$")).toEqual(1) | ||
| }) No newline at end of file |
There was a problem hiding this comment.
I think there is a more common name that describes characters that are neither alphabets nor digits, than "unusual characters".
|
Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it. |
Learners, PR Template
Self checklist
Changelist
Wrote tests before the code that will make them pass.