Skip to content

Commit 0e7fe70

Browse files
author
Ogbemi mene
committed
test.js for ordinal num
1 parent 7991a9b commit 0e7fe70

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,49 @@ 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+
// here are more test cases for different scenarios
23+
24+
const getOrdinalNumber = require("./get-ordinal-number");
25+
26+
describe("getOrdinalNumber", () => {
27+
// Case 1: Already defined in your prompt
28+
test("should append 'st' for numbers ending with 1, except those ending with 11", () => {
29+
expect(getOrdinalNumber(1)).toEqual("1st");
30+
expect(getOrdinalNumber(21)).toEqual("21st");
31+
expect(getOrdinalNumber(131)).toEqual("131st");
32+
});
33+
34+
// Case 2: Numbers ending with 2 (but not 12)
35+
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
36+
expect(getOrdinalNumber(2)).toEqual("2nd");
37+
expect(getOrdinalNumber(22)).toEqual("22nd");
38+
expect(getOrdinalNumber(142)).toEqual("142nd");
39+
});
40+
41+
// Case 3: Numbers ending with 3 (but not 13)
42+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
43+
expect(getOrdinalNumber(3)).toEqual("3rd");
44+
expect(getOrdinalNumber(23)).toEqual("23rd");
45+
expect(getOrdinalNumber(153)).toEqual("153rd");
46+
});
47+
48+
// Case 4: Numbers ending with 11, 12, 13 (The exceptions)
49+
test("should append 'th' for numbers ending in 11, 12, or 13", () => {
50+
expect(getOrdinalNumber(11)).toEqual("11th");
51+
expect(getOrdinalNumber(12)).toEqual("12th");
52+
expect(getOrdinalNumber(13)).toEqual("13th");
53+
expect(getOrdinalNumber(111)).toEqual("111th");
54+
expect(getOrdinalNumber(112)).toEqual("112th");
55+
expect(getOrdinalNumber(113)).toEqual("113th");
56+
});
57+
58+
// Case 5: All other numbers
59+
test("should append 'th' for all other numbers", () => {
60+
expect(getOrdinalNumber(4)).toEqual("4th");
61+
expect(getOrdinalNumber(10)).toEqual("10th");
62+
expect(getOrdinalNumber(20)).toEqual("20th");
63+
expect(getOrdinalNumber(34)).toEqual("34th");
64+
expect(getOrdinalNumber(100)).toEqual("100th");
65+
});
66+
});

0 commit comments

Comments
 (0)