Repository navigation
Conversation
…ent exit in the string,test failed
…given more than one character
… and added a test for empty string
…h a decimal input
mayowaolokun
left a comment
There was a problem hiding this comment.
Thank you for the updates, this is great progress. The main issues from the first review have been addressed: the 111, 112 and 113 cases now work, the zero case in repeatStr returns an empty string, and the test names are much clearer.
I’ve left a few smaller comments.
You’re very close, so keep up the good work!
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of `char` were found. | ||
|
|
||
| test(" Should count 0", () => { |
There was a problem hiding this comment.
“Should count 0” is clearer than before. It might help to describe the scenario, for example, that the character doesn’t appear in the string. There’s also still a space at the start of the name.
| const count = countChar(str, char); | ||
| expect(count).toEqual(1); | ||
| }); | ||
| test("should count multiple occurences of character empty space", () => { |
There was a problem hiding this comment.
“Empty space” could be confused with an empty string. Would “space character” describe this test more clearly?
| const count = countChar(str, char); | ||
| expect(count).toEqual(2); | ||
| }); | ||
| test("should count multiple occurences of character in an empty string", () => { |
There was a problem hiding this comment.
Nice addition. Since this test expects 0, it might be worth removing “multiple occurrences” from the name.
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| test("should count multiple occurences of character in a sentence", () => { |
There was a problem hiding this comment.
This test seems to share its name with the one on line 52, so it might be worth giving it a unique name that describes its scenario.
| throw new Error("Invalid Input"); | ||
| } | ||
|
|
||
| if (numStr.slice(-1) == "1" && numStr.slice(-2) != 11) { |
There was a problem hiding this comment.
numStr.slice(-2) gives you a string, but it’s compared with the number 11. This currently works because != converts types before comparing. What would happen if you switched to !==, as suggested earlier? It might be worth comparing like with like so the code doesn’t depend on type conversion. Applicable to lines 11 and 14.
| count = Math.floor(count); | ||
|
|
||
| if (str === " ") { | ||
| throw new Error("String shoild not be empty"); |
There was a problem hiding this comment.
Small typo: “shoild” should be “should”.
|
|
||
| test("should repeat the string count times", () => { | ||
| expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); | ||
| }); |
There was a problem hiding this comment.
Thank you for adding this test. One thing to check: the input here is a single space " " rather than an empty string "". Please see my comment on line 9 of repeat-str.js, as the two are linked.
| expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); | ||
| }); | ||
| test(`should throw an error when string is empty`, () => { | ||
| expect(() => repeatStr(" ", 1)).toThrow("String shoild not be empty"); |
There was a problem hiding this comment.
The test name says “empty string”, but the input is a space. Once you’ve decided whether an empty string or a space should be an error, it might be worth updating this test to match. Also, if you fix the “shoild” typo in the error message, remember to update it here too.
|
|
||
| // 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. | ||
|
|
There was a problem hiding this comment.
The Given/When/Then comments for the count of 1 and count of 0 cases are still removed. It might be worth restoring them, as you’ve done for the other cases.
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
| //case: Handle decimal count: | ||
| test("should repeat the stringthe whole number in the count times", () => { |
There was a problem hiding this comment.
There’s a missing space in “stringthe”. It might also help to make the name clearer, for example, by saying that a decimal count is rounded down.
Learners, PR Template
Self checklist
Task code
CYF-1060
Changelist
I practiced writing a code based on Test driven development.
Questions