Skip to content

Commit 56d5d43

Browse files
committed
add tests for handling zero and negative counts in repeatStr function
1 parent 1d03850 commit 56d5d43

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,22 @@ test("should repeat the string one time", () => {
3333
// When the repeatStr function is called with these inputs,
3434
// Then it should return an empty string.
3535

36+
test("should return empty string if count is zero", () => {
37+
const str = "hello";
38+
const count = 0;
39+
const repeatedStr = repeatStr(str, count);
40+
expect(repeatedStr).toEqual("");
41+
});
42+
3643
// Case: Handle negative count:
3744
// Given a target string `str` and a negative integer `count`,
3845
// When the repeatStr function is called with these inputs,
3946
// Then it should throw an error, as negative counts are not valid.
47+
48+
test("should throw an error when count is negative integer", () => {
49+
const str = "hello";
50+
const count = -5;
51+
expect(() => {
52+
repeatStr(str, count);
53+
}).toThrow("Error");
54+
});

0 commit comments

Comments
 (0)