-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathrepeat-str.test.js
More file actions
96 lines (94 loc) · 4.04 KB
/
repeat-str.test.js
File metadata and controls
96 lines (94 loc) · 4.04 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Implement a function repeatStr
const repeatStr = require("./repeat-str");
test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const repeatedStr = repeatStr(count, str);
expect(repeatedStr).toEqual("hellohellohello");
});
// test("should return the original string when count is 1", () => {
// const str = "hello";
// const count = 1;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("hello");
// });
// test("should return an empty string when count is 0", () => {
// const str = "hello";
// const count = 0;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("");
// });
// // Given a target string `str` and a positive integer `count`,
// // When the repeatStr function is called with these inputs,
// // Then it should:
// // - Validate that `count` is a non-negative integer.
// // - If `count` is 0, return an empty string.
// // - If `count` is 1, return the original `str`.
// // - If `count` is greater than 1, concatenate `str` to itself `count` times and return the resulting string.
// // Case: handle multiple repetitions:
// // Given a target string `str` and a positive integer `count` greater than 1,
// // When the repeatStr function is called with these inputs,
// // Then it should return a string that contains the original `str` repeated `count` times.
// test("should repeat the string count times", () => {
// const str = "hello";
// const count = 3;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("hellohellohello");
// });
// // Case: handle count of 1:
// // Given a target string `str` and a `count` equal to 1,
// // When the repeatStr function is called with these inputs,
// test("should repeat the string count times", () => {
// const str = "hello";
// const count = 3;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("hellohellohello");
// });
// // Case: handle count of 1:
// // Given a target string `str` and a `count` equal to 1,
// // When the repeatStr function is called with these inputs,
// // Then it should return the original `str` without repetition.
// test("should return the original string when count is 1", () => {
// const str = "hello";
// const count = 1;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("hello");
// });
// // Case: handle count of 0:
// // Given a target string `str` and a `count` equal to 0,
// // When the repeatStr function is called with these inputs,
// // Then it should return an empty string.
// test("should return the original string when count is 1", () => {
// const str = "hello";
// const count = 1;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("hello");
// });
// // Case: Handle count of 0:
// // Given a target string `str` and a `count` equal to 0,
// // When the repeatStr function is called with these inputs,
// // Then it should return an empty string.
// test("should return an empty string when count is 0", () => {
// const str = "hello";
// const count = 0;
// const repeatedStr = repeatStr(str, count);
// expect(repeatedStr).toEqual("");
// });
// // Case: Handle negative count:
// // Given a target string `str` and a negative integer `count`,
// // When the repeatStr function is called with these inputs,
// // Then it should throw an error, as negative counts are not valid.
// test("should throw an error when count is negative", () => {
// const str = "hello";
// const count = -1;
// expect(() => repeatStr(str, count)).toThrow("Count must be a non-negative integer");
// });
// // Case: Handle non-integer count:
// // Given a target string `str` and a non-integer value for `count`,
// // When the repeatStr function is called with these inputs,
// // Then it should throw an error, as non-integer counts are not valid.
// test("should throw an error when count is not an integer", () => {
// const str = "hello";
// const count = 2.5;
// expect(() => repeatStr(str, count)).toThrow("Count must be a non-negative integer");
// });