Skip to content

Commit 1973ce9

Browse files
committed
Add empty string tests for repeatStr.
1 parent 0941a03 commit 1973ce9

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎practice-tdd/repeat-str.test.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ test("should repeat the string count times", () => {
1515
const repeatedStr = repeatStr(str, count);
1616
expect(repeatedStr).toEqual("hellohellohello");
1717
});
18-
18+
test("should return an empty string when repeating an empty string multiple times", () => {
19+
const str = "";
20+
const count = 3;
21+
const repeatedStr = repeatStr(str, count);
22+
expect(repeatedStr).toEqual("");
23+
});
1924
// Case: handle count of 1:
2025
// Given a target string `str` and a `count` equal to 1,
2126
// When the repeatStr function is called with these inputs,
@@ -26,6 +31,12 @@ test("should return the original `str` without repetition", () => {
2631
const repeatedStr = repeatStr(str, count);
2732
expect(repeatedStr).toEqual("hello");
2833
});
34+
test("should return an empty string when the string is empty and count is 1", () => {
35+
const str = "";
36+
const count = 1;
37+
const repeatedStr = repeatStr(str, count);
38+
expect(repeatedStr).toEqual("");
39+
});
2940
// Case: Handle count of 0:
3041
// Given a target string `str` and a `count` equal to 0,
3142
// When the repeatStr function is called with these inputs,
@@ -36,6 +47,12 @@ test("should return an empty string", () => {
3647
const repeatedStr = repeatStr(str, count);
3748
expect(repeatedStr).toEqual("");
3849
});
50+
test("should return an empty string when the string is empty and count is 0", () => {
51+
const str = "";
52+
const count = 0;
53+
const repeatedStr = repeatStr(str, count);
54+
expect(repeatedStr).toEqual("");
55+
});
3956
// Case: Handle negative count:
4057
// Given a target string `str` and a negative integer `count`,
4158
// When the repeatStr function is called with these inputs,

0 commit comments

Comments
 (0)