Skip to content

Commit d48367c

Browse files
solve excersise get-ordinal-number.test.js
1 parent eafa02b commit d48367c

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎practice-tdd/get-ordinal-number.test.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,33 @@ 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(452)).toEqual("452nd");
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");
37+
expect(getOrdinalNumber(823)).toEqual("823rd");
38+
});
39+
40+
// Case 4: Numbers ending with any other number (but not 1,2 or 3)
41+
// When the number ends with 4,5,6 ,7 ,8 or 9 ,
42+
// Then the function should return a string by appending "th" to the number.
43+
test("should append 'th' for numbers ending with 4,5,6 ,7 ,8 or 9 ", () => {
44+
expect(getOrdinalNumber(4)).toEqual("4th");
45+
expect(getOrdinalNumber(25)).toEqual("25th");
46+
expect(getOrdinalNumber(656)).toEqual("656th");
47+
expect(getOrdinalNumber(1007)).toEqual("1007th");
48+
expect(getOrdinalNumber(638398)).toEqual("638398th");
49+
expect(getOrdinalNumber(34454559)).toEqual("34454559th");
50+
});

0 commit comments

Comments
 (0)