Skip to content

Commit 761fb1d

Browse files
committed
refactor tests for countChar and getOrdinalNumber
1 parent 97a5210 commit 761fb1d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,42 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
1717
expect(getOrdinalNumber(1)).toEqual("1st");
1818
expect(getOrdinalNumber(21)).toEqual("21st");
1919
expect(getOrdinalNumber(131)).toEqual("131st");
20+
21+
});
22+
23+
// Case 2: Numbers ending with 2 (but not 12)
24+
// When the number ends with 2, except those ending with 12,
25+
// Then the function should return a string by appending "nd" to the number.
26+
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
27+
expect(getOrdinalNumber(2)).toEqual("2nd");
28+
expect(getOrdinalNumber(22)).toEqual("22nd");
29+
expect(getOrdinalNumber(132)).toEqual("132nd");
30+
});
31+
32+
// Case 3: Numbers ending with 3 (but not 13)
33+
// When the case ends with 3, expect those ending with 13
34+
// Then the function should return a string by appending "rd" to the number.
35+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
36+
expect(getOrdinalNumber(3)).toEqual("3rd");
37+
expect(getOrdinalNumber(23)).toEqual("23rd");
38+
expect(getOrdinalNumber(133)).toEqual("133rd");
39+
});
40+
41+
// Case 4: Numbers ending with 11, 12, or 13
42+
// When the number ends with 11, 12, or 13,
43+
// Then the function should return a string by appending "th" to the number.
44+
test("should append 'th' for numbers ending with 11, 12, or 13", () => {
45+
expect(getOrdinalNumber(11)).toEqual("11th");
46+
expect(getOrdinalNumber(12)).toEqual("12th");
47+
expect(getOrdinalNumber(13)).toEqual("13th");
48+
});
49+
50+
// Case 5: ALL other numbers
51+
// When the number does not end with 1, 2, 3, 11, 12, or 13,
52+
// Then the function should return a string by appending "th" to the number.
53+
test("should append 'th' for all other numbers", () => {
54+
expect(getOrdinalNumber(4)).toEqual("4th");
55+
expect(getOrdinalNumber(10)).toEqual("10th");
56+
expect(getOrdinalNumber(14)).toEqual("14th");
57+
expect(getOrdinalNumber(100)).toEqual("100th");
2058
});

0 commit comments

Comments
 (0)