Skip to content

Commit eb8edda

Browse files
committed
test getOrdinalNumber function
1 parent fc349ab commit eb8edda

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,35 @@ 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(202)).toEqual("202nd");
28+
expect(getOrdinalNumber(1032)).toEqual("1032nd");
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(2333)).toEqual("2333rd");
37+
expect(getOrdinalNumber(13453)).toEqual("13453rd");
38+
});
39+
40+
// Case 4: All other numbers
41+
// When the number does not end with 1, 2, or 3 (except for the exceptions),
42+
// Then the function should return a string by appending "th" to the number.
43+
test("should append 'th' for all other numbers", () => {
44+
expect(getOrdinalNumber(4)).toEqual("4th");
45+
expect(getOrdinalNumber(10)).toEqual("10th");
46+
expect(getOrdinalNumber(11)).toEqual("11th");
47+
expect(getOrdinalNumber(12)).toEqual("12th");
48+
expect(getOrdinalNumber(13)).toEqual("13th");
49+
expect(getOrdinalNumber(100)).toEqual("100th");
50+
expect(getOrdinalNumber(1012)).toEqual("1012th");
51+
expect(getOrdinalNumber(1038)).toEqual("1038th");
52+
});

0 commit comments

Comments
 (0)