Skip to content

Commit a1e9f60

Browse files
add tests for repeat function to handle empty strings, strings with spaces, and long strings
1 parent ade9346 commit a1e9f60

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ expect(repeatedStr).toEqual("hello")
3333
// When the repeat function is called with these inputs,
3434
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
3535

36-
test("should return an empty string", ()=>{
37-
const str = "hello";
38-
const count = 0;
39-
const repeatedStr = repeat(str, count);
40-
expect(repeatedStr).toEqual("");
41-
})
36+
// test("should return an empty string", ()=>{
37+
// const str = "hello";
38+
// const count = 0;
39+
// const repeatedStr = repeat(str, count);
40+
// expect(repeatedStr).toEqual("");
41+
// })
4242

4343
// case: Negative Count:
4444
// Given a target string str and a negative integer count,
@@ -51,3 +51,51 @@ test("should return error", ()=>{
5151
const repeatedStr = repeat(str, count);
5252
expect(repeatedStr).toEqual("Error: negative numbers are not valid");
5353
})
54+
55+
// case: Handle empty string:
56+
// Given a target string str and a count equal to 2,
57+
// When the repeat function is called with these inputs,
58+
// Then it should return an empty string, ensuring that a count of 2 results in an empty output.
59+
60+
test("should return an empty string", () => {
61+
const str = "";
62+
const count = 2;
63+
const repeatedStr = repeat(str, count);
64+
expect(repeatedStr).toEqual("");
65+
});
66+
67+
// case: Handle string with space:
68+
// Given a target string str and a count equal to 2,
69+
// When the repeat function is called with these inputs,
70+
// Then it should repeat the str count times and return a new string containing the repeated str values.
71+
72+
test("should return an empty string", () => {
73+
const str = "a b";
74+
const count = 2;
75+
const repeatedStr = repeat(str, count);
76+
expect(repeatedStr).toEqual("a ba b");
77+
});
78+
79+
// case: Handle long string :
80+
// Given a target string str and a count equal to1,
81+
// When the repeat function is called with these inputs,
82+
// Then it should repeat the str count times and return a new string containing the repeated str values.
83+
84+
test("should return an empty string", () => {
85+
const str = "xvg56756yrhfghe5ujdfh45657tjrtg6yrthrty";
86+
const count = 1;
87+
const repeatedStr = repeat(str, count);
88+
expect(repeatedStr).toEqual("xvg56756yrhfghe5ujdfh45657tjrtg6yrthrty");
89+
});
90+
91+
// case: Handle single character string and high count :
92+
// Given a target string str and a count equal to 18,
93+
// When the repeat function is called with these inputs,
94+
// Then it should repeat the str count times and return a new string containing the repeated str values.
95+
96+
test("should return an empty string", () => {
97+
const str = "x";
98+
const count = 18;
99+
const repeatedStr = repeat(str, count);
100+
expect(repeatedStr).toEqual("xxxxxxxxxxxxxxxxxx");
101+
});

0 commit comments

Comments
 (0)