Skip to content

Commit 4e8e08c

Browse files
committed
practice tdd repeat more
1 parent ad2bc20 commit 4e8e08c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Sprint-3/2-practice-tdd/repeat.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,34 @@ test("should repeat the string count times", () => {
2020
// Given a target string str and a count equal to 1,
2121
// When the repeat function is called with these inputs,
2222
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
23+
test("should return original string when count is 1", () => {
24+
const str = "hello";
25+
const count = 1;
26+
const repeatedStr = repeat(str, count);
27+
expect(repeatedStr).toEqual("hello");
28+
});
29+
30+
2331

2432
// case: Handle Count of 0:
2533
// Given a target string str and a count equal to 0,
2634
// When the repeat function is called with these inputs,
2735
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
36+
test("should return an empty string when count is 0", () => {
37+
const str = "world";
38+
const count = 0;
39+
const repeatedStr = repeat(str, count);
40+
expect(repeatedStr).toEqual("");
41+
});
42+
43+
2844

2945
// case: Negative Count:
3046
// Given a target string str and a negative integer count,
3147
// When the repeat function is called with these inputs,
3248
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
49+
test("should throw an error when count is negative", () => {
50+
const str = "test";
51+
const count = -3;
52+
expect(() => repeat(str, count)).toThrow("Count must be non-negative");
53+
});

0 commit comments

Comments
 (0)