Skip to content

Commit 0845d0b

Browse files
committed
test cases fixed and passing tests
1 parent 1e36bac commit 0845d0b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
1-
21
// Implement a function repeatStr
32
const repeatStr = require("./repeat-str");
43
// Given a target string str and a positive integer count,
54
// When the repeatStr function is called with these inputs,
65
// Then it should:
76

8-
// case: repeat String:
7+
// case 1: repeat String:
98
// Given a target string str and a positive integer count,
109
// When the repeatStr function is called with these inputs,
1110
// Then it should repeat the str count times and return a new string containing the repeated str values.
1211

1312
test("should repeat the string count times", () => {
1413
const str = "hello";
1514
const count = 3;
16-
const repeatedStr = repeatStr(str, count);
17-
expect(repeatedStr).toEqual("hellohellohello");
15+
expect(repeatStr(str, count)).toEqual("hellohellohello");
1816
});
1917

20-
// case: handle Count of 1:
18+
// case 2: handle Count of 1:
2119
// Given a target string str and a count equal to 1,
2220
// When the repeatStr function is called with these inputs,
2321
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
2422
test("should return the original string when count is 1", () => {
2523
const str = "hello";
2624
const count = 1;
27-
const repeatedStr = repeat(str, count);
28-
expect(repeatedStr).toEqual("hello");
25+
expect(repeatStr(str, count)).toEqual("hello");
2926
});
3027

31-
// case: Handle Count of 0:
28+
// case 3: Handle Count of 0:
3229
// Given a target string str and a count equal to 0,
3330
// When the repeatStr function is called with these inputs,
3431
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
3532
test("should return an empty string when count is 0", () => {
3633
const str = "hello";
3734
const count = 0;
38-
const repeatedStr = repeat(str, count);
39-
expect(repeatedStr).toEqual("");
35+
expect(repeatStr(str, count)).toEqual("");
4036
});
4137

42-
// case: Negative Count:
38+
// case 4: Negative Count:
4339
// Given a target string str and a negative integer count,
4440
// When the repeatStr function is called with these inputs,
4541
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
4642
test("should throw an error for negative count", () => {
4743
const str = "hello";
4844
const count = -2;
49-
expect(() => {
50-
repeat(str, count);
51-
}).toThrow("Invalid count value");
45+
expect(() => repeatStr(str, count)).toThrow("Invalid count value");
46+
});
47+
48+
// case 5: Non-integer Count:
49+
// Given a target string str and a non-integer count (e.g., a float or a string),
50+
// When the repeatStr function is called with these inputs,
51+
// Then it should throw an error or return an appropriate error message, as non-integer counts are not valid.
52+
test("should throw an error for non-integer count", () => {
53+
const str = "hello";
54+
const count = 2.5;
55+
expect(() => repeatStr(str, count)).toThrow("Invalid count value");
5256
});

0 commit comments

Comments
 (0)