Skip to content

Commit fae571e

Browse files
committed
TDD: Completed get-ordinal-number.test.js with 5 grouped test cases
1 parent e827d26 commit fae571e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,47 @@ 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 (except 12)
23+
// Given the number ends with 2 but not 12,
24+
// When getOrdinalNumber is called,
25+
// Then it should append "nd".
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(102)).toEqual("102nd");
30+
});
31+
32+
// Case 3: Numbers ending with 3 (except 13)
33+
// Given the number ends with 3 but not 13,
34+
// When getOrdinalNumber is called,
35+
// Then it should append "rd".
36+
test("should append 'rd' for numbers ending with 3 except those ending with 13", () => {
37+
expect(getOrdinalNumber(3)).toEqual("3rd");
38+
expect(getOrdinalNumber(23)).toEqual("23rd");
39+
expect(getOrdinalNumber(103)).toEqual("103rd");
40+
});
41+
42+
// Case 4: Numbers ending with 4-9, 0, or 11-19
43+
// Given the number ends with 4-9, 0, ot 11-19,
44+
// When getOrdinalNumber is called,
45+
// Then it should append "th".
46+
test("should append 'th' for numbers ending with 4-9, 0, or 11-19", () => {
47+
expect(getOrdinalNumber(4)).toEqual("4th");
48+
expect(getOrdinalNumber(5)).toEqual("5th");
49+
expect(getOrdinalNumber(10)).toEqual("10th");
50+
expect(getOrdinalNumber(11)).toEqual("11th");
51+
expect(getOrdinalNumber(12)).toEqual("12th");
52+
expect(getOrdinalNumber(13)).toEqual("13th");
53+
expect(getOrdinalNumber(20)).toEqual("20th");
54+
});
55+
56+
// Case 5: Large numbers
57+
// Give a very large positive number,
58+
// When getOrdinalNumber is called,
59+
// Then it should still append the correct suffix based on the last digits.
60+
test("should handle large numbers correctly", () => {
61+
expect(getOrdinalNumber(101)).toEqual("101st");
62+
expect(getOrdinalNumber(112)).toEqual("112th");
63+
expect(getOrdinalNumber(1000)).toEqual("1000th");
64+
});

0 commit comments

Comments
 (0)