Skip to content

Commit 7470027

Browse files
committed
implement repeatStr function and tests
1 parent 5b52894 commit 7470027

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Implement a function repeat
2-
const repeat = require("./repeat");
2+
const repeatStr = require("./repeat");
33
// Given a target string str and a positive integer count,
44
// When the repeat function is called with these inputs,
55
// Then it should:
@@ -12,7 +12,7 @@ const repeat = require("./repeat");
1212
test("should repeat the string count times", () => {
1313
const str = "hello";
1414
const count = 3;
15-
const repeatedStr = repeat(str, count);
15+
const repeatedStr = repeatStr(str, count);
1616
expect(repeatedStr).toEqual("hellohellohello");
1717
});
1818

@@ -21,12 +21,32 @@ test("should repeat the string count times", () => {
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.
2323

24+
test("returns the original string when count is 1", () => {
25+
const str = "hello";
26+
const count = 1;
27+
const repeatedStr = repeatStr(str, count);
28+
expect(repeatedStr).toBe("hello");
29+
});
30+
2431
// case: Handle Count of 0:
2532
// Given a target string str and a count equal to 0,
2633
// When the repeat function is called with these inputs,
2734
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
2835

36+
test("returns an empty string when count is 0", () => {
37+
const str = "hello";
38+
const count = 0;
39+
const repeatedStr = repeatStr(str, count);
40+
expect(repeatedStr).toBe("");
41+
});
42+
2943
// case: Negative Count:
3044
// Given a target string str and a negative integer count,
3145
// When the repeat function is called with these inputs,
3246
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
47+
48+
test("throws an error when count is negative", () => {
49+
const str = "hello";
50+
const count = -3;
51+
expect(() => repeatStr(str, count)).toThrow("count cannot be negative");
52+
});

0 commit comments

Comments
 (0)