Skip to content

Commit ddd628d

Browse files
committed
Add tests for getOrdinalNumber function: cover cases for 2, 3, and other numbers
1 parent 8171039 commit ddd628d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,32 @@ 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+
// Case 2: Numbers ending with 2 (but not 12)
22+
// When the number ends with 2, except those ending with 12,
23+
// Then the function should return a string by appending "nd" to the number.
24+
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
25+
expect(getOrdinalNumber(2)).toEqual("2nd");
26+
expect(getOrdinalNumber(22)).toEqual("22nd");
27+
expect(getOrdinalNumber(102)).toEqual("102nd");
28+
});
29+
30+
// Case 3: Numbers ending with 3 (but not 13)
31+
// When the number ends with 3, except those ending with 13,
32+
// Then the function should return a string by appending "rd" to the number.
33+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
34+
expect(getOrdinalNumber(3)).toEqual("3rd");
35+
expect(getOrdinalNumber(23)).toEqual("23rd");
36+
expect(getOrdinalNumber(103)).toEqual("103rd");
37+
});
38+
39+
// Case 4: All other numbers, including 11, 12, and 13
40+
// When the number doesn't fall into the above categories,
41+
// Then the function should return a string by appending "th" to the number.
42+
test("should append 'th' for all other numbers, including 11, 12, and 13", () => {
43+
expect(getOrdinalNumber(4)).toEqual("4th");
44+
expect(getOrdinalNumber(11)).toEqual("11th");
45+
expect(getOrdinalNumber(12)).toEqual("12th");
46+
expect(getOrdinalNumber(13)).toEqual("13th");
47+
expect(getOrdinalNumber(111)).toEqual("111th");
48+
expect(getOrdinalNumber(0)).toEqual("0th");
49+
});

0 commit comments

Comments
 (0)