Skip to content

Commit 5d0e895

Browse files
I wrote different test cases to handel repeating string for times more than 1, and to give empty out put for (0)
and 'invalid count' output for negative counts.
1 parent f012a52 commit 5d0e895

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,29 @@ 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-
23+
test("should repeat the string count times", () => {
24+
const str = "hello";
25+
const count = 1;
26+
const repeatedStr = repeatStr(str, count);
27+
expect(repeatedStr).toEqual("hello");
28+
});
2429
// Case: Handle count of 0:
2530
// Given a target string `str` and a `count` equal to 0,
2631
// When the repeatStr function is called with these inputs,
2732
// Then it should return an empty string.
28-
33+
test("should repeat the string count times", () => {
34+
const str = "hello";
35+
const count = 0;
36+
const repeatedStr = repeatStr(str, count);
37+
expect(repeatedStr).toEqual(" ");
38+
});
2939
// Case: Handle negative count:
3040
// Given a target string `str` and a negative integer `count`,
3141
// When the repeatStr function is called with these inputs,
3242
// Then it should throw an error, as negative counts are not valid.
43+
test("should repeat the string count times", () => {
44+
const str = "hello";
45+
const count = -1;
46+
const repeatedStr = repeatStr(str, count);
47+
expect(repeatedStr).toEqual("invalid count");
48+
});

0 commit comments

Comments
 (0)