Skip to content

Commit a5cdf92

Browse files
committed
Improved Practice tdd tasks following the feedback instructions
1 parent cb22d60 commit a5cdf92

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,37 @@ const getOrdinalNumber = require("./get-ordinal-number");
88
// Listing individual values, however, can quickly lead to an unmanageable number of test cases.
99
// Instead of writing tests for individual numbers, consider grouping all possible input values
1010
// into meaningful categories. Then, select representative samples from each category to test.
11-
// This approach improves coverage and makes our tests easier to maintain.
11+
// This approach improves coverage and makes our tests easier to maintain
1212

1313
// Case 1: Numbers ending with 1 (but not 11)
14-
// When the number ends with 1, except those ending with 11,
15-
// Then the function should return a string by appending "st" to the number.
1614
test("should append 'st' for numbers ending with 1, except those ending with 11", () => {
1715
expect(getOrdinalNumber(1)).toEqual("1st");
1816
expect(getOrdinalNumber(21)).toEqual("21st");
1917
expect(getOrdinalNumber(131)).toEqual("131st");
2018
});
2119

20+
// Case 2: numbers ending with 2 (except 12)
21+
test(" should append 'rd' for numberss ending witth 3 except those ending with 13", () => {
22+
expect(getOrdinalNumber(3)).toEqual("3rd");
23+
expect(getOrdinalNumber(23)).toEqual("23rd");
24+
});
25+
26+
// Case 3: numbers ending with 3 (except 13)
27+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
28+
expect(getOrdinalNumber(3)).toEqual("3rd");
29+
expect(getOrdinalNumber(23)).toEqual("23rd");
30+
});
31+
32+
// Case 4: numbers ending with th
33+
test("should append 'th' for numbers ending with 4-9 or 0", () => {
34+
expect(getOrdinalNumber(4)).toEqual("4th");
35+
expect(getOrdinalNumber(10)).toEqual("10th");
36+
});
37+
38+
// Case 5: special cases 11,12,13
39+
test("should append 'th' for numbers ending with 11, 12, 13", () => {
40+
expect(getOrdinalNumber(11)).toEqual("11th");
41+
expect(getOrdinalNumber(12)).toEqual("12th");
42+
expect(getOrdinalNumber(13)).toEqual("13th");
43+
});
44+
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
function repeatStr() {
2-
return "hellohellohello";
1+
function repeatStr(str, count) {
2+
return str.repeat(count);
33
}
44

55
module.exports = repeatStr;
6-
7-

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
// Implement a function repeatStr
22
const repeatStr = require("./repeat-str");
3+
4+
// Given a target string `str` and a positive integer `count`,
5+
// When the repeatStr function is called with these inputs,
6+
// Then it should:
7+
8+
// Case: handle multiple repetitions:
9+
// Given a target string `str` and a positive integer `count` greater than 1,
10+
// When the repeatStr function is called with these inputs,
11+
// Then it should return a string that contains the original `str` repeated `count` times.
12+
test("should repeat the string count times", () => {
13+
const str = "hello";
14+
const count = 3;
15+
const repeatedStr = repeatStr(str, count);
16+
17+
expect(repeatedStr).toEqual("hellohellohello");
18+
});
19+
20+
// Case: handle count of 1:
21+
// Given a target string `str` and a `count` equal to 1,
22+
// When the repeatStr function is called with these inputs,
23+
// Then it should return the original `str` without repetition.
24+
test("should return the original string when count is 1", () => {
25+
const str = "hello";
26+
const count = 1;
27+
const repeatedStr = repeatStr(str, count);
28+
29+
expect(repeatedStr).toEqual("hello");
30+
});
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.
36+
test("should return an empty string when count is 0", () => {
37+
const str = "hello";
38+
const count = 0;
39+
const repeatedStr = repeatStr(str, count);
40+
41+
expect(repeatedStr).toEqual("");
42+
}); // Implement a function repeatStr
43+
344
// Given a target string `str` and a positive integer `count`,
445
// When the repeatStr function is called with these inputs,
546
// Then it should:
@@ -30,5 +71,3 @@ test("should repeat the string count times", () => {
3071
// Given a target string `str` and a negative integer `count`,
3172
// When the repeatStr function is called with these inputs,
3273
// Then it should throw an error, as negative counts are not valid.
33-
34-

0 commit comments

Comments
 (0)