|
1 | | -// Implement a function repeat |
2 | | -const repeat = require("./repeat"); |
| 1 | +// Implement a function repeatStr |
| 2 | +const repeatStr = require("./repeat-str"); |
3 | 3 | // Given a target string str and a positive integer count, |
4 | | -// When the repeat function is called with these inputs, |
| 4 | +// When the repeatStr function is called with these inputs, |
5 | 5 | // Then it should: |
6 | 6 |
|
7 | 7 | // case: repeat String: |
8 | 8 | // Given a target string str and a positive integer count, |
9 | | -// When the repeat function is called with these inputs, |
| 9 | +// When the repeatStr function is called with these inputs, |
10 | 10 | // Then it should repeat the str count times and return a new string containing the repeated str values. |
11 | 11 |
|
12 | 12 | test("should repeat the string count times", () => { |
13 | 13 | const str = "hello"; |
14 | 14 | const count = 3; |
15 | | - const repeatedStr = repeat(str, count); |
| 15 | + const repeatedStr = repeatStr(str, count); |
16 | 16 | expect(repeatedStr).toEqual("hellohellohello"); |
17 | 17 | }); |
18 | 18 |
|
19 | 19 | // case: handle Count of 1: |
20 | 20 | // Given a target string str and a count equal to 1, |
21 | | -// When the repeat function is called with these inputs, |
| 21 | +// When the repeatStr function is called with these inputs, |
22 | 22 | // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. |
23 | 23 | test("should return the original string without repetition if count equal to 1", () => { |
24 | 24 | const str = "Alone"; |
25 | 25 | const count = 1; |
26 | | - const repeatedStr = repeat(str, count); |
| 26 | + const repeatedStr = repeatStr(str, count); |
27 | 27 | expect(repeatedStr).toEqual("Alone"); |
28 | 28 | }); |
29 | 29 |
|
30 | 30 | // case: Handle Count of 0: |
31 | 31 | // Given a target string str and a count equal to 0, |
32 | | -// When the repeat function is called with these inputs, |
| 32 | +// When the repeatStr function is called with these inputs, |
33 | 33 | // Then it should return an empty string, ensuring that a count of 0 results in an empty output. |
34 | 34 | test("should return an empty string if count equal to 0", () => { |
35 | 35 | const str = "nonsense"; |
36 | 36 | const count = 0; |
37 | | - const repeatedStr = repeat(str, count); |
| 37 | + const repeatedStr = repeatStr(str, count); |
38 | 38 | expect(repeatedStr).toEqual(""); |
39 | 39 | }); |
40 | 40 |
|
41 | 41 | // case: Negative Count: |
42 | 42 | // Given a target string str and a negative integer count, |
43 | | -// When the repeat function is called with these inputs, |
| 43 | +// When the repeatStr function is called with these inputs, |
44 | 44 | // Then it should throw an error or return an appropriate error message, as negative counts are not valid. |
45 | 45 | test("should return an appropriate error message if count equal to a negative integer", () => { |
46 | 46 | const str = "negative"; |
47 | 47 | const count = -5; |
48 | | - const repeatedStr = repeat(str, count); |
| 48 | + const repeatedStr = repeatStr(str, count); |
49 | 49 | expect(repeatedStr).toEqual("Error! Negative counts are not valid!"); |
50 | 50 | }); |
0 commit comments