|
1 | 1 | // Implement a function repeatStr |
2 | 2 | import { repeatStr } from "./repeat-str.js"; |
| 3 | +// Given a target string `str` and a positive integer `count`, |
| 4 | +// When the repeatStr function is called with these inputs, |
| 5 | +// Then it should: |
| 6 | + |
| 7 | +// Case: handle multiple repetitions: |
| 8 | +// Given a target string `str` and a positive integer `count` greater than 1, |
| 9 | +// When the repeatStr function is called with these inputs, |
| 10 | +// Then it should return a string that contains the original `str` repeated `count` times. |
| 11 | + |
3 | 12 | // Case: handle count of 1, 2, 3, 4: |
4 | 13 | test("should repeat the string 1 times", () => { |
5 | 14 | const str = "hello"; |
@@ -32,14 +41,17 @@ test("should repeat the string 0 times", () => { |
32 | 41 | const repeatedStr = repeatStr(str, count); |
33 | 42 | expect(repeatedStr).toEqual(""); |
34 | 43 | }); |
35 | | -//case: Handle decimal count |
| 44 | +//case: Handle decimal count: |
36 | 45 | test("should repeat the stringthe whole number in the count times", () => { |
37 | 46 | const str = "hello"; |
38 | 47 | const count = 2.5; |
39 | 48 | const repeatedStr = repeatStr(str, count); |
40 | 49 | expect(repeatedStr).toEqual("hellohello"); |
41 | 50 | }); |
42 | 51 | // Case: Handle negative count: |
| 52 | +// Given a target string `str` and a negative integer `count`, |
| 53 | +// When the repeatStr function is called with these inputs, |
| 54 | +// Then it should throw an error, as negative counts are not valid |
43 | 55 | test("should throw an error when -1 count is given", () => { |
44 | 56 | expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); |
45 | 57 | }); |
|
0 commit comments