Skip to content

Commit affdd56

Browse files
committed
Fix repeatStr implementation and tests
1 parent 7d01f24 commit affdd56

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎practice-tdd/repeat-str.test.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ test("should repeat the string count times", () => {
2020
// Given a target string `str` and a `count` equal to 1,
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
23+
test("should return the original string when count is 1", () => {
24+
expect(repeatStr("hello", 1)).toEqual("hello");
25+
});
2326

2427
// Case: Handle count of 0:
2528
// Given a target string `str` and a `count` equal to 0,
2629
// When the repeatStr function is called with these inputs,
2730
// Then it should return an empty string.
31+
test("should return an empty string when count is 0", () => {
32+
expect(repeatStr("hello", 0)).toEqual("");
33+
});
2834

2935
// Case: Handle negative count:
3036
// Given a target string `str` and a negative integer `count`,
3137
// When the repeatStr function is called with these inputs,
3238
// Then it should throw an error, as negative counts are not valid.
39+
test("should throw an error for negative count", () => {
40+
expect(() => repeatStr("hello", -1)).toThrow("count must be non-negative");
41+
});

0 commit comments

Comments
 (0)