Skip to content

Commit f4337c9

Browse files
author
Ogbemi mene
committed
code- get-ordinal number
1 parent 319f61b commit f4337c9

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,46 @@ 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(32)).toEqual("32nd");
28+
expect(getOrdinalNumber(242)).toEqual("242nd");
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(43)).toEqual("43rd"); // Note: should be "43rd" based on standard logic, fixing a potential typo
37+
expect(getOrdinalNumber(103)).toEqual("103rd");
38+
});
39+
40+
// Case 4: General numbers ending with 4 through 9, and 0
41+
// When the number ends with 4, 5, 6, 7, 8, 9, or 0,
42+
// Then the function should return a string by appending "th" to the number.
43+
test("should append 'th' for general numbers ending in 4-9 or 0", () => {
44+
expect(getOrdinalNumber(4)).toEqual("4th");
45+
expect(getOrdinalNumber(7)).toEqual("7th");
46+
expect(getOrdinalNumber(20)).toEqual("20th");
47+
expect(getOrdinalNumber(56)).toEqual("56th");
48+
});
49+
50+
// Case 5: The Exception Rule (Numbers ending with 11, 12, or 13)
51+
// When the number ends specifically with 11, 12, or 13 (the teen boundary),
52+
// Then the function should always override standard rules and append "th".
53+
test("should correctly append 'th' for exceptions ending in 11, 12, or 13", () => {
54+
// Primary boundaries
55+
expect(getOrdinalNumber(11)).toEqual("11th");
56+
expect(getOrdinalNumber(12)).toEqual("12th");
57+
expect(getOrdinalNumber(13)).toEqual("13th");
58+
59+
// Larger representative samples matching the group
60+
expect(getOrdinalNumber(111)).toEqual("111th");
61+
expect(getOrdinalNumber(212)).toEqual("212th");
62+
expect(getOrdinalNumber(1013)).toEqual("1013th");
63+
});

0 commit comments

Comments
 (0)