|
1 | 1 | // Implement a function repeatStr |
2 | 2 | const repeatStr = require("./repeat-str"); |
| 3 | + |
| 4 | +// Given a target string `str` and a positive integer `count`, |
| 5 | +// When the repeatStr function is called with these inputs, |
| 6 | +// Then it should: |
| 7 | + |
| 8 | +// Case: handle multiple repetitions: |
| 9 | +// Given a target string `str` and a positive integer `count` greater than 1, |
| 10 | +// When the repeatStr function is called with these inputs, |
| 11 | +// Then it should return a string that contains the original `str` repeated `count` times. |
| 12 | +test("should repeat the string count times", () => { |
| 13 | + const str = "hello"; |
| 14 | + const count = 3; |
| 15 | + const repeatedStr = repeatStr(str, count); |
| 16 | + |
| 17 | + expect(repeatedStr).toEqual("hellohellohello"); |
| 18 | +}); |
| 19 | + |
| 20 | +// Case: handle count of 1: |
| 21 | +// Given a target string `str` and a `count` equal to 1, |
| 22 | +// When the repeatStr function is called with these inputs, |
| 23 | +// Then it should return the original `str` without repetition. |
| 24 | +test("should return the original string when count is 1", () => { |
| 25 | + const str = "hello"; |
| 26 | + const count = 1; |
| 27 | + const repeatedStr = repeatStr(str, count); |
| 28 | + |
| 29 | + expect(repeatedStr).toEqual("hello"); |
| 30 | +}); |
| 31 | + |
| 32 | +// Case: handle count of 0: |
| 33 | +// Given a target string `str` and a `count` equal to 0, |
| 34 | +// When the repeatStr function is called with these inputs, |
| 35 | +// Then it should return an empty string. |
| 36 | +test("should return an empty string when count is 0", () => { |
| 37 | + const str = "hello"; |
| 38 | + const count = 0; |
| 39 | + const repeatedStr = repeatStr(str, count); |
| 40 | + |
| 41 | + expect(repeatedStr).toEqual(""); |
| 42 | +}); // Implement a function repeatStr |
| 43 | + |
3 | 44 | // Given a target string `str` and a positive integer `count`, |
4 | 45 | // When the repeatStr function is called with these inputs, |
5 | 46 | // Then it should: |
@@ -30,5 +71,3 @@ test("should repeat the string count times", () => { |
30 | 71 | // Given a target string `str` and a negative integer `count`, |
31 | 72 | // When the repeatStr function is called with these inputs, |
32 | 73 | // Then it should throw an error, as negative counts are not valid. |
33 | | - |
34 | | - |
|
0 commit comments