Skip to content

Commit 5939d12

Browse files
Add tests for edge cases in repeatStr function: handle count of 1, 0, and negative values
1 parent d4aba95 commit 5939d12

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,32 @@ test("should repeat the string count times", () => {
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
2323

24+
test("should return the original string when count is 1", () => {
25+
const str = "CYF";
26+
const count = 1;
27+
const repeatedStr = repeatStr(str, count);
28+
expect(repeatedStr).toEqual("CYF");
29+
});
30+
2431
// Case: Handle count of 0:
2532
// Given a target string `str` and a `count` equal to 0,
2633
// When the repeatStr function is called with these inputs,
2734
// Then it should return an empty string.
2835

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

0 commit comments

Comments
 (0)