Skip to content

Commit 280fe5c

Browse files
committed
Add tests for empty strings. Update test names
1 parent 19b6fd7 commit 280fe5c

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ test("should repeat the string count times", () => {
1616
expect(repeatedStr).toEqual("hellohellohello");
1717
});
1818

19+
test("should return empty string when str is empty and count = 3", () => {
20+
const str = "";
21+
const count = 3;
22+
const repeatedStr = repeatStr(str, count);
23+
expect(repeatedStr).toEqual("");
24+
});
25+
1926
// Case: handle count of 1:
2027
// Given a target string `str` and a `count` equal to 1,
2128
// When the repeatStr function is called with these inputs,
@@ -28,23 +35,43 @@ test("should repeat the string count times, count = 1", () => {
2835
expect(repeatedStr).toEqual("hello");
2936
});
3037

38+
test("should return empty string when str is empty and count = 1", () => {
39+
const str = "";
40+
const count = 1;
41+
const repeatedStr = repeatStr(str, count);
42+
expect(repeatedStr).toEqual("");
43+
});
44+
3145
// Case: Handle count of 0:
3246
// Given a target string `str` and a `count` equal to 0,
3347
// When the repeatStr function is called with these inputs,
3448
// Then it should return an empty string.
35-
test("should return empty string, count = 0", () => {
49+
test("should return empty string when count = 0", () => {
3650
const str = "hello";
3751
const count = 0;
3852
const repeatedStr = repeatStr(str, count);
3953
expect(repeatedStr).toEqual("");
4054
});
4155

56+
test("should return empty string when string is empty and count = 0", () => {
57+
const str = "";
58+
const count = 0;
59+
const repeatedStr = repeatStr(str, count);
60+
expect(repeatedStr).toEqual("");
61+
});
62+
4263
// Case: Handle negative count:
4364
// Given a target string `str` and a negative integer `count`,
4465
// When the repeatStr function is called with these inputs,
4566
// Then it should throw an error, as negative counts are not valid.
46-
test("should return error, count < 0", () => {
67+
test("should return error when count < 0", () => {
4768
const str = "hello";
4869
const count = -5;
4970
expect(() => repeatStr(str, count)).toThrow(/Error/);
5071
});
72+
73+
test("should return error when count < 0 and string is empty", () => {
74+
const str = "";
75+
const count = -5;
76+
expect(() => repeatStr(str, count)).toThrow(/Error/);
77+
});

0 commit comments

Comments
 (0)