Repository navigation
Conversation
hackertainment
left a comment
There was a problem hiding this comment.
Thank you for your coursework. Please keep it up.
| test("should count multiple occurrences of a character", () => { | ||
| const str = "aaaaa"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| }); |
There was a problem hiding this comment.
This is a special case of str where it is all the char to count. Would it still count correctly if the char just exists in some part of the str?
There was a problem hiding this comment.
This proves i still have a long way to go in developing an eye for detail when looking at code
| test("should count zero occurrences of a character", () => { | ||
| const str = "aaaa"; | ||
| const char = "b"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); |
There was a problem hiding this comment.
There is a special str that would give 0 anyway. Please add that test case as well. Thank you.
| test("should append 'th' for the rest of the numbers", () => { | ||
| expect(getOrdinalNumber(9)).toEqual("9th"); | ||
| expect(getOrdinalNumber(20)).toEqual("20th"); | ||
| expect(getOrdinalNumber(108)).toEqual("108th"); | ||
| }); |
There was a problem hiding this comment.
Lines 13-15 of your code has not been included in this test suite. Please add test cases specifically for that part of the code. Thank you.
There was a problem hiding this comment.
I see you have added 11th, 12th, and 13th. Just it would be better to also include 3-digit number (e.g. 211th, 112th, and 213) ended in 11 or 12 or 13 as well. I will let you pass this time because your code is correct, but please improve test cases coverage in the future. Thank you.
| if (Number.isInteger(count) && count < 0) { | ||
| throw new Error(`Invalid input`); | ||
| } |
There was a problem hiding this comment.
I don't think this part is accurate. Consider count = 4.5, would the result be the same as expected?
There was a problem hiding this comment.
Thanks for that! You got me reading about the distinction between the tasks where one is required to take what's given and implement to handle only specific cases, and where one has to handle edge cases, validate inputs, throw errors for invalid.. . If the task required me to 'Handle edge cases' or, more specifically, 'handle non-integers', then it would be a must to rewrite my implementation and add a test accordingly. I would change that part into if (!Number.isInteger(count) || count < 0) { throw new Error(Invalid input); }
| test("should repeat the string count times", () => { | ||
| const str = "hello"; | ||
| const count = 3; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("hellohellohello"); | ||
| }); | ||
|
|
||
| // Case: handle count of 1: | ||
| // Given a target string `str` and a `count` equal to 1, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return the original `str` without repetition. | ||
|
|
||
| test("should repeat the string 1 time", () => { | ||
| const str = "hello"; | ||
| const count = 1; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("hello"); | ||
| }); | ||
|
|
||
| // Case: Handle count of 0: | ||
| // Given a target string `str` and a `count` equal to 0, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return an empty string. | ||
|
|
||
| test("should repeat the string 0 times", () => { | ||
| const str = "hello"; | ||
| const count = 0; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); |
There was a problem hiding this comment.
Your test cases are correct. Just for you to think a little bit more, besides const str = "hello", what special string should also be added to each of the test cases?
|
Congratulation, you have completed this PR successfully. |
Learners, PR Template
Self checklist
Task code
CYF-1060
Changelist
Implemented functions and wrote required tests in Jest for 'Count', 'Repeat string' and 'Get ordinal number' exercises.