Skip to content

Commit 288b3f1

Browse files
committed
Added tests for ordinal number suffixes in getOrdinalNumber function
1 parent 74a0212 commit 288b3f1

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
@@ -18,3 +18,41 @@ 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(3162)).toEqual("3162nd");
28+
expect(getOrdinalNumber(7322)).toEqual("7322nd");
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+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
35+
expect(getOrdinalNumber(3)).toEqual("3rd");
36+
expect(getOrdinalNumber(3243)).toEqual("3243rd");
37+
expect(getOrdinalNumber(133)).toEqual("133rd");
38+
});
39+
40+
// Case 4: Numbers ending with 11, 12 or 13
41+
// When the number ends with 11, 12 or 13
42+
// Then the function should return a string by appending "th" to the number.
43+
test("should append 'th' for numbers with 11, 12 or 13", () => {
44+
expect(getOrdinalNumber(11)).toEqual("11th");
45+
expect(getOrdinalNumber(211)).toEqual("211th");
46+
expect(getOrdinalNumber(2113)).toEqual("2113th");
47+
expect(getOrdinalNumber(824312)).toEqual("824312th");
48+
});
49+
50+
// Case 4: Numbers not ending in 1, 2 and 3
51+
// When the number ends with 0, 4, 5, 6, 7, 8, 9
52+
// Then the function should return a string by appending "th" to the number.
53+
test("should append 'th' for numbers not ending in 1, 2 and 3", () => {
54+
expect(getOrdinalNumber(19)).toEqual("19th");
55+
expect(getOrdinalNumber(2118)).toEqual("2118th");
56+
expect(getOrdinalNumber(3130)).toEqual("3130th");
57+
expect(getOrdinalNumber(924334)).toEqual("924334th");
58+
});

0 commit comments

Comments
 (0)