Skip to content

Commit 17a2043

Browse files
committed
deleted repeat.js and adjusted repeat.str.test.js
1 parent e7cad87 commit 17a2043

File tree

3 files changed

+12
-71
lines changed

3 files changed

+12
-71
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
function repeatStr() {
2-
return "hellohellohello";
1+
function repeatStr(str, count) {
2+
3+
if (count < 0) {
4+
throw new Error("Count must be a non-negative integer");
5+
}
6+
return str.repeat(count);
37
}
48

59
module.exports = repeatStr;
Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,20 @@
1-
// Implement a function repeatStr
2-
const repeatStr = require("./repeat-str");
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-
function repeat(str, count) {
7-
if (count < 0) {
8-
throw new Error("Count must be a non-negative integer");
9-
}
10-
return str.repeat(count);
11-
}
12-
13-
module.exports = repeat;
14-
15-
// case: repeat String:
16-
// Given a target string str and a positive integer count,
17-
// When the repeatStr function is called with these inputs,
18-
// Then it should repeat the str count times and return a new string containing the repeated str values.
191

20-
test("should repeat the string count times", () => {
21-
const str = "hello";
22-
const count = 3;
23-
const repeatedStr = repeatStr(str, count);
24-
expect(repeatedStr).toEqual("hellohellohello");
25-
});
262

27-
// case: handle Count of 1:
28-
// Given a target string str and a count equal to 1,
29-
// When the repeatStr function is called with these inputs,
30-
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
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, ensuring that a count of 0 results in an empty output.
36-
37-
// case: Negative Count:
38-
// Given a target string str and a negative integer count,
39-
// When the repeatStr function is called with these inputs,
40-
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
41-
const repeat = require("./repeat");
3+
const repeatStr = require("./repeat-str");
424

43-
// Case 1: Repeat string multiple times
445
test("should repeat the string count times", () => {
45-
const str = "hello";
46-
const count = 3;
47-
const repeatedStr = repeat(str, count);
48-
expect(repeatedStr).toEqual("hellohellohello");
6+
expect(repeatStr("hello", 3)).toBe("hellohellohello");
497
});
508

51-
// Case 2: Handle count of 1
529
test("should return the original string when count is 1", () => {
53-
const str = "world";
54-
const count = 1;
55-
const repeatedStr = repeat(str, count);
56-
expect(repeatedStr).toEqual("world");
10+
expect(repeatStr("world", 1)).toBe("world");
5711
});
5812

59-
// Case 3: Handle count of 0
6013
test("should return an empty string when count is 0", () => {
61-
const str = "test";
62-
const count = 0;
63-
const repeatedStr = repeat(str, count);
64-
expect(repeatedStr).toEqual("");
14+
expect(repeatStr("test", 0)).toBe("");
6515
});
6616

67-
// Case 4: Negative count
6817
test("should throw an error when count is negative", () => {
69-
const str = "oops";
70-
const count = -2;
71-
expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer");
18+
expect(() => repeatStr("oops", -2)).toThrow("Count must be a non-negative integer");
7219
});
20+

Sprint-3/2-practice-tdd/repeat.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)