Skip to content

Commit ac6e7d8

Browse files
add the general edge cases for the repeatStr function tests
1 parent 18fe3d9 commit ac6e7d8

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ test("should repeat the string count times", () => {
1515
const repeatedStr = repeatStr(str, count);
1616
expect(repeatedStr).toEqual("hellohellohello");
1717
});
18+
test("should repeat the string count times", () => {
19+
const str = "world";
20+
const count = 4;
21+
const repeatedStr = repeatStr(str, count);
22+
expect(repeatedStr).toEqual("worldworldworldworld");
23+
});
24+
test("should repeat the string count times", () => {
25+
const str = "bye";
26+
const count = 5;
27+
const repeatedStr = repeatStr(str, count);
28+
expect(repeatedStr).toEqual("byebyebyebyebye");
29+
});
1830

1931
// Case: handle count of 1:
2032
// Given a target string `str` and a `count` equal to 1,
@@ -23,6 +35,12 @@ test("should repeat the string count times", () => {
2335
test("should return the original string when count is 1", () => {
2436
expect(repeatStr("hello", 1)).toEqual("hello");
2537
});
38+
test("should return the original string when count is 1", () => {
39+
expect(repeatStr("world", 1)).toEqual("world");
40+
});
41+
test("should return the original string when count is 1", () => {
42+
expect(repeatStr("goodday", 1)).toEqual("goodday");
43+
});
2644

2745
// Case: Handle count of 0:
2846
// Given a target string `str` and a `count` equal to 0,
@@ -32,6 +50,12 @@ test("should return the original string when count is 1", () => {
3250
test("should return an empty string when count is 0", () => {
3351
expect(repeatStr("hello", 0)).toEqual("");
3452
});
53+
test("should return an empty string when count is 0", () => {
54+
expect(repeatStr("prakash", 0)).toEqual("");
55+
});
56+
test("should return an empty string when count is 0", () => {
57+
expect(repeatStr("snake", 0)).toEqual("");
58+
});
3559

3660
// Case: Handle negative count:
3761
// Given a target string `str` and a negative integer `count`,
@@ -40,3 +64,6 @@ test("should return an empty string when count is 0", () => {
4064
test("should throw an error when count is negative", () => {
4165
expect(() => repeatStr("hello", -1)).toThrow();
4266
});
67+
test("should throw an error when count is negative", () => {
68+
expect(() => repeatStr("apple", -1)).toThrow();
69+
});

0 commit comments

Comments
 (0)