Skip to content

Commit 1a5ddc6

Browse files
Add tests for ordinal number suffixes in getOrdinalNumber function
1 parent ac7e1c8 commit 1a5ddc6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,43 @@ 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(172)).toEqual("172nd");
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(23)).toEqual("23rd");
37+
expect(getOrdinalNumber(4393)).toEqual("4393rd");
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 ending with 11, 12, or 13", () => {
44+
expect(getOrdinalNumber(11)).toEqual("11th");
45+
expect(getOrdinalNumber(12)).toEqual("12th");
46+
expect(getOrdinalNumber(13)).toEqual("13th");
47+
});
48+
49+
// Case 5: Numbers ending with 0, 4, 5, 6, 7, 8, or 9
50+
// When the number ends with 0, 4, 5, 6, 7, 8, or 9,
51+
// Then the function should return a string by appending "th" to the number.
52+
test("should append 'th' for numbers ending with 0, 4, 5, 6, 7, 8, or 9", () => {
53+
expect(getOrdinalNumber(150)).toEqual("150th");
54+
expect(getOrdinalNumber(6584)).toEqual("6584th");
55+
expect(getOrdinalNumber(85)).toEqual("85th");
56+
expect(getOrdinalNumber(659326)).toEqual("659326th");
57+
expect(getOrdinalNumber(567)).toEqual("567th");
58+
expect(getOrdinalNumber(888)).toEqual("888th");
59+
expect(getOrdinalNumber(6589)).toEqual("6589th");
60+
});

0 commit comments

Comments
 (0)