|
| 1 | +// Implement a function repeatStr |
| 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 | + |
| 12 | +test("should repeat the string count times", () => { |
| 13 | + const str = "hello"; |
| 14 | + const count = 3; |
| 15 | + const repeatedStr = repeatStr(str, count); |
| 16 | + expect(repeatedStr).toEqual("hellohellohello"); |
| 17 | +}); |
| 18 | + |
| 19 | +// Case: handle count of 1: |
| 20 | +// Given a target string `str` and a `count` equal to 1, |
| 21 | +// When the repeatStr function is called with these inputs, |
| 22 | +// Then it should return the original `str` without repetition. |
| 23 | + |
| 24 | +// Case: Handle count of 0: |
| 25 | +// Given a target string `str` and a `count` equal to 0, |
| 26 | +// When the repeatStr function is called with these inputs, |
| 27 | +// Then it should return an empty string. |
| 28 | + |
| 29 | +// Case: Handle negative count: |
| 30 | +// Given a target string `str` and a negative integer `count`, |
| 31 | +// When the repeatStr function is called with these inputs, |
| 32 | +// Then it should throw an error, as negative counts are not valid. |
0 commit comments