Manchester | 26-ITP-Jan | Liban Jama | Sprint 3 | Practice tdd#1198
Manchester | 26-ITP-Jan | Liban Jama | Sprint 3 | Practice tdd#1198libanj0161 wants to merge 5 commits intoCodeYourFuture:mainfrom
Conversation
| function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("invalid count"); | ||
| } | ||
| return str.repeat(count); | ||
| } |
There was a problem hiding this comment.
This function does not cover all the edge cases as expected to be implemented for the task. Then, your test would not run successfully becauase it's not working according to the task brief. Please, look at it again and read the comments
There was a problem hiding this comment.
I realised once reading the task brief and changed it to meet the requirements, thanks for the reminder.
| test("should repeat the string count times", () => { | ||
| 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 count times", () => { | ||
| const str = "hello"; | ||
| const count = 0; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
|
|
There was a problem hiding this comment.
let your function be implemented to suit these test cases
| const lastdigit = num % 10; | ||
| if (lastdigit === 1) { | ||
| return `${num}st`; | ||
| } | ||
|
|
||
| if (lastdigit === 2) { | ||
| return `${num}nd`; | ||
| } | ||
|
|
||
| if (lastdigit === 3) { | ||
| return `${num}rd`; | ||
| } else { | ||
| return `${num}th`; | ||
| } | ||
| } |
There was a problem hiding this comment.
Your function needs to handle edge cases for other groups of numbers that depend on the last two digits as well. After this, your test should run successfully.
There was a problem hiding this comment.
Ive changed the function and added tests to handle edge cases.
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "house"; | ||
| const char = "e"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(1); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "playful"; | ||
| const char = "l"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(2); | ||
| }); |
There was a problem hiding this comment.
Be careful about using a duplicated test description when writing different tests.
There was a problem hiding this comment.
i've changed up the description so they are different.
Theoreoluwa
left a comment
There was a problem hiding this comment.
You've done well, Liban. Look at the comments and make it better. Rooting for you.
Learners, PR Template
Self checklist
Changelist
Complete practice tdd.
Questions
No.