Skip to content

Commit 31cfb33

Browse files
wrote tests to handle 0 and negative numbers
1 parent 6b58b56 commit 31cfb33

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,32 @@ 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, ensuring that a count of 1 results in no repetition.
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+
});
2329

2430
// case: Handle Count of 0:
2531
// Given a target string str and a count equal to 0,
2632
// When the repeatStr function is called with these inputs,
2733
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
34+
test("should repeat the string count times", () => {
35+
const str = "hello";
36+
const count = 0;
37+
const repeatedStr = repeatStr(str, count);
38+
expect(repeatedStr).toEqual("");
39+
});
2840

2941
// case: Negative Count:
3042
// Given a target string str and a negative integer count,
3143
// When the repeatStr function is called with these inputs,
3244
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
45+
test("should repeat the string count times", () => {
46+
const str = "hello";
47+
const count = -1;
48+
expect(() => repeatStr(str, count)).toThrow(
49+
"Only positive integers accepted"
50+
);
51+
});

0 commit comments

Comments
 (0)