Skip to content

Commit 4098eb1

Browse files
author
Pretty Taruvinga
committed
Co-authored-by: Isaac Abodunrin <bytesandroses@users.noreply.github.com>
1 parent 2af6c11 commit 4098eb1

File tree

4 files changed

+98
-34
lines changed

4 files changed

+98
-34
lines changed

CYF-Workshops

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5c89bd2b0949c13eb70950a776b1cfebf87de5a1

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ test("should return 0 when the character does not occur in the string", () => {
3232
const count = countChar(str, char);
3333
expect(count).toEqual(0);
3434
});
35-
3635
// Scenario: Case Sensitivity
3736
test("should be case sensitive", () => {
3837
const str = "Hello World";

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ function repeatStr(n, str) {
77
}
88

99
module.exports = repeatStr;
10-
const repeatStr = require("./repeat-str");
10+
// const repeatStr = require("./repeat-str");
1111

12-
test("repeats a string n times", () => {
13-
expect(repeatStr(3, "hello")).toBe("hellohellohello");
14-
});
12+
// test("repeats a string n times", () => {
13+
// expect(repeatStr(3, "hello")).toBe("hellohellohello");
14+
// });
1515

16-
test("repeats a different string", () => {
17-
expect(repeatStr(2, "abc")).toBe("abcabc");
18-
});
16+
// test("repeats a different string", () => {
17+
// expect(repeatStr(2, "abc")).toBe("abcabc");
18+
// });
1919

20-
test("returns empty string when n is 0", () => {
21-
expect(repeatStr(0, "hi")).toBe("");
22-
});
20+
// test("returns empty string when n is 0", () => {
21+
// expect(repeatStr(0, "hi")).toBe("");
22+
// });
Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,96 @@
11
// Implement a function repeatStr
22
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-
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-
123
test("should repeat the string count times", () => {
134
const str = "hello";
145
const count = 3;
15-
const repeatedStr = repeatStr(str, count);
6+
const repeatedStr = repeatStr(count, str);
167
expect(repeatedStr).toEqual("hellohellohello");
178
});
9+
// test("should return the original string when count is 1", () => {
10+
// const str = "hello";
11+
// const count = 1;
12+
// const repeatedStr = repeatStr(str, count);
13+
// expect(repeatedStr).toEqual("hello");
14+
// });
15+
// test("should return an empty string when count is 0", () => {
16+
// const str = "hello";
17+
// const count = 0;
18+
// const repeatedStr = repeatStr(str, count);
19+
// expect(repeatedStr).toEqual("");
20+
// });
21+
// // Given a target string `str` and a positive integer `count`,
22+
// // When the repeatStr function is called with these inputs,
23+
// // Then it should:
24+
// // - Validate that `count` is a non-negative integer.
25+
// // - If `count` is 0, return an empty string.
26+
// // - If `count` is 1, return the original `str`.
27+
// // - If `count` is greater than 1, concatenate `str` to itself `count` times and return the resulting string.
1828

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.
29+
// // Case: handle multiple repetitions:
30+
// // Given a target string `str` and a positive integer `count` greater than 1,
31+
// // When the repeatStr function is called with these inputs,
32+
// // Then it should return a string that contains the original `str` repeated `count` times.
33+
// test("should repeat the string count times", () => {
34+
// const str = "hello";
35+
// const count = 3;
36+
// const repeatedStr = repeatStr(str, count);
37+
// expect(repeatedStr).toEqual("hellohellohello");
38+
// });
39+
// // Case: handle count of 1:
40+
// // Given a target string `str` and a `count` equal to 1,
41+
// // When the repeatStr function is called with these inputs,
42+
// test("should repeat the string count times", () => {
43+
// const str = "hello";
44+
// const count = 3;
45+
// const repeatedStr = repeatStr(str, count);
46+
// expect(repeatedStr).toEqual("hellohellohello");
47+
// });
2848

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.
49+
// // Case: handle count of 1:
50+
// // Given a target string `str` and a `count` equal to 1,
51+
// // When the repeatStr function is called with these inputs,
52+
// // Then it should return the original `str` without repetition.
53+
// test("should return the original string when count is 1", () => {
54+
// const str = "hello";
55+
// const count = 1;
56+
// const repeatedStr = repeatStr(str, count);
57+
// expect(repeatedStr).toEqual("hello");
58+
// });
59+
// // Case: handle count of 0:
60+
// // Given a target string `str` and a `count` equal to 0,
61+
// // When the repeatStr function is called with these inputs,
62+
// // Then it should return an empty string.
63+
// test("should return the original string when count is 1", () => {
64+
// const str = "hello";
65+
// const count = 1;
66+
// const repeatedStr = repeatStr(str, count);
67+
// expect(repeatedStr).toEqual("hello");
68+
// });
69+
// // Case: Handle count of 0:
70+
// // Given a target string `str` and a `count` equal to 0,
71+
// // When the repeatStr function is called with these inputs,
72+
// // Then it should return an empty string.
73+
// test("should return an empty string when count is 0", () => {
74+
// const str = "hello";
75+
// const count = 0;
76+
// const repeatedStr = repeatStr(str, count);
77+
// expect(repeatedStr).toEqual("");
78+
// });
79+
// // Case: Handle negative count:
80+
// // Given a target string `str` and a negative integer `count`,
81+
// // When the repeatStr function is called with these inputs,
82+
// // Then it should throw an error, as negative counts are not valid.
83+
// test("should throw an error when count is negative", () => {
84+
// const str = "hello";
85+
// const count = -1;
86+
// expect(() => repeatStr(str, count)).toThrow("Count must be a non-negative integer");
87+
// });
88+
// // Case: Handle non-integer count:
89+
// // Given a target string `str` and a non-integer value for `count`,
90+
// // When the repeatStr function is called with these inputs,
91+
// // Then it should throw an error, as non-integer counts are not valid.
92+
// test("should throw an error when count is not an integer", () => {
93+
// const str = "hello";
94+
// const count = 2.5;
95+
// expect(() => repeatStr(str, count)).toThrow("Count must be a non-negative integer");
96+
// });

0 commit comments

Comments
 (0)