Skip to content

Commit e77e54a

Browse files
committed
2-practice-tdd get-ordinal-number.test.js written test
1 parent 3dce6cd commit e77e54a

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ function countChar(stringOfCharacters, findCharacter) {
99
}
1010
//console.log(countChar("please work for me", "e" )) //output is: 3
1111

12-
// module.exports = countChar;
12+
module.exports = countChar;
1313

14-
// function assertEquals(actualOutput, targetOutput) {
15-
// console.assert(
16-
// actualOutput === targetOutput,
17-
// `Expected ${actualOutput} to equal ${targetOutput}`
18-
// );
19-
// }
14+
function assertEquals(actualOutput, targetOutput) {
15+
console.assert(
16+
actualOutput === targetOutput,
17+
`Expected ${actualOutput} to equal ${targetOutput}`
18+
);
19+
}
2020

21-
// assertEquals(countChar("aaaaa", "a" ), 5);
22-
// assertEquals(countChar("venue", "b" ), 0);
23-
// assertEquals(countChar("", "x" ), 0);
21+
assertEquals(countChar("aaaaa", "a" ), 5);
22+
assertEquals(countChar("venue", "b" ), 0);
23+
assertEquals(countChar("", "x" ), 0);
2424

2525
// try {
2626
// countChar(12);

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,45 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
1818
expect(getOrdinalNumber(21)).toEqual("21st");
1919
expect(getOrdinalNumber(131)).toEqual("131st");
2020
});
21+
22+
// Case 2: Numbers ending with 2 (but not 12)
23+
// When the number ends with 2, except those ending with 12,
24+
// Then the function should return a string by appending "nd" to the number.
25+
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
26+
expect(getOrdinalNumber(2)).toEqual("2nd");
27+
expect(getOrdinalNumber(22)).toEqual("22nd");
28+
expect(getOrdinalNumber(122)).toEqual("122nd");
29+
});
30+
31+
// Case 3: Numbers ending with 3 (but not 13)
32+
// When the number ends with 3, except those ending with 13,
33+
// Then the function should return a string by appending "rd" to the number.
34+
35+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
36+
expect(getOrdinalNumber(3)).toEqual("3rd");
37+
expect(getOrdinalNumber(33)).toEqual("33rd");
38+
expect(getOrdinalNumber(133)).toEqual("133rd");
39+
});
40+
41+
// Case 4: Numbers ending with 4-9 and 0
42+
// When the number ends with 4-9, and with 0,
43+
// Then the function should return a string by appending "th" to the number.
44+
test("should append 'th' for numbers ending with 4-9 or 0", () => {
45+
expect(getOrdinalNumber(4)).toEqual("4th");
46+
expect(getOrdinalNumber(8)).toEqual("8th");
47+
expect(getOrdinalNumber(10)).toEqual("10th");
48+
expect(getOrdinalNumber(39)).toEqual("39th");
49+
expect(getOrdinalNumber(100)).toEqual("100th");
50+
});
51+
52+
// Case 5: Special cases 11, 12, 13
53+
// When the number ends with 11, 12, 13
54+
// Then the function should return a string by appending "th" to the number.
55+
test("should append 'th' for numbers ending with 11, 12, or 13", () => {
56+
expect(getOrdinalNumber(11)).toEqual("11th");
57+
expect(getOrdinalNumber(12)).toEqual("12th");
58+
expect(getOrdinalNumber(13)).toEqual("13th");
59+
expect(getOrdinalNumber(111)).toEqual("111th");
60+
expect(getOrdinalNumber(112)).toEqual("112th");
61+
expect(getOrdinalNumber(113)).toEqual("113th");
62+
});

0 commit comments

Comments
 (0)