Skip to content

Commit d6bc191

Browse files
Add empty string edge cases to repeatStr tests
1 parent 8295046 commit d6bc191

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
// Implement a function repeatStr
21
import { repeatStr } from "./repeat-str.js";
3-
// Given a target string `str` and a positive integer `count`,
4-
// When the repeatStr function is called with these inputs,
5-
// Then it should:
6-
7-
// Case: handle multiple repetitions:
8-
// Given a target string `str` and a positive integer `count` greater than 1,
9-
// When the repeatStr function is called with these inputs,
10-
// Then it should return a string that contains the original `str` repeated `count` times.
112

123
test("should repeat the string count times", () => {
134
const str = "hello";
@@ -43,16 +34,29 @@ test("should return Backstreet Boys lyrics", () => {
4334
expect(repeatedStr).toEqual("byebyebyebyebye");
4435
});
4536

46-
// Case: handle count of 1:
47-
// Given a target string `str` and a `count` equal to 1,
48-
// When the repeatStr function is called with these inputs,
37+
test("should return an empty string when repeating an empty string 3 times", () => {
38+
const str = "";
39+
const count = 3;
40+
const repeatedStr = repeatStr(str, count);
41+
expect(repeatedStr).toEqual("");
42+
});
43+
44+
test("should return an empty string when repeating an empty string once", () => {
45+
const str = "";
46+
const count = 1;
47+
const repeatedStr = repeatStr(str, count);
48+
expect(repeatedStr).toEqual("");
49+
});
4950

50-
// Case: Handle count of 0:
51-
// Given a target string `str` and a `count` equal to 0,
52-
// When the repeatStr function is called with these inputs,
53-
// Then it should return an empty string.
51+
test("should return an empty string when count is zero", () => {
52+
const str = "";
53+
const count = 0;
54+
const repeatedStr = repeatStr(str, count);
55+
expect(repeatedStr).toEqual("");
56+
});
5457

55-
// Case: Handle negative count:
56-
// Given a target string `str` and a negative integer `count`,
57-
// When the repeatStr function is called with these inputs,
58-
// Then it should throw an error, as negative counts are not valid.
58+
test("should throw an error when repeating an empty string a negative number of times", () => {
59+
const str = "";
60+
const count = -2;
61+
expect(() => repeatStr(str, count)).toThrow("Count cannot be negative");
62+
});

0 commit comments

Comments
 (0)