@@ -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+ test ( "should append 'nd' for numbers ending with 2, except those ending with 12" , ( ) => {
24+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
25+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
26+ expect ( getOrdinalNumber ( 102 ) ) . toEqual ( "102nd" ) ;
27+ } ) ;
28+
29+ //Case 3: Number ending with 3 (but not 13)
30+ test ( "should append 'rd' for numbers ending with 3, except those ending with 13" , ( ) => {
31+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
32+ expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
33+ expect ( getOrdinalNumber ( 103 ) ) . toEqual ( "103rd" ) ;
34+ } ) ;
35+
36+ //Case 4: Special cases: 11, 12, 13
37+ test ( "should append 'th' for special cases 11, 12, and 13" , ( ) => {
38+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
39+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
40+ expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13th" ) ;
41+ expect ( getOrdinalNumber ( 111 ) ) . toEqual ( "111th" ) ;
42+ expect ( getOrdinalNumber ( 112 ) ) . toEqual ( "112th" ) ;
43+ } ) ;
44+
45+ //Case 5: All other numbers
46+ test ( "should append 'th' for all other numbers" , ( ) => {
47+ expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
48+ expect ( getOrdinalNumber ( 20 ) ) . toEqual ( "20th" ) ;
49+ expect ( getOrdinalNumber ( 100 ) ) . toEqual ( "100th" ) ;
50+ } ) ;
0 commit comments