-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathrepeat-str.test.js
More file actions
44 lines (39 loc) · 1.17 KB
/
repeat-str.test.js
File metadata and controls
44 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Implement a function repeatStr
const repeatStr = require("./repeat-str");
// Case: repeat string multiple times
test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const repeatedStr = repeatStr(count, str);
expect(repeatedStr).toEqual("hellohellohello");
});
// Case: count = 1
test("should return the original string when count is 1", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeatStr(count, str);
expect(repeatedStr).toEqual("hello");
});
// Case: count = 0
test("should return an empty string when count is 0", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeatStr(count, str);
expect(repeatedStr).toEqual("");
});
// Case: negative count
test("should throw an error when count is negative", () => {
const str = "hello";
const count = -1;
expect(() => repeatStr(count, str)).toThrow(
"Count must be a non-negative integer"
);
});
// Case: non-integer count
test("should throw an error when count is not an integer", () => {
const str = "hello";
const count = 2.5;
expect(() => repeatStr(count, str)).toThrow(
"Count must be a non-negative integer"
);
});