@@ -18,3 +18,29 @@ 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 in 2 → add nd → (2nd, 22nd, 42nd)
23+ test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
24+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
25+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
26+ expect ( getOrdinalNumber ( 142 ) ) . toEqual ( "142nd" ) ;
27+ } ) ;
28+ // Case 3: Numbers ending in 3 → add rd → (3rd, 23rd, 53rd)
29+ test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
30+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
31+ expect ( getOrdinalNumber ( 33 ) ) . toEqual ( "33rd" ) ;
32+ expect ( getOrdinalNumber ( 153 ) ) . toEqual ( "153rd" ) ;
33+ } ) ;
34+ // Case 4: All other numbers → add th → (4th, 6th, 20th, 100th)
35+ test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
36+ expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
37+ expect ( getOrdinalNumber ( 20 ) ) . toEqual ( "20th" ) ;
38+ expect ( getOrdinalNumber ( 100 ) ) . toEqual ( "100th" ) ;
39+ } ) ;
40+ // Exceptions: Numbers ending in 11, 12, and 13 use -th (e.g., 11th, 12th, 13th).
41+ test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
42+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
43+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
44+ expect ( getOrdinalNumber ( 113 ) ) . toEqual ( "113th" ) ;
45+ } ) ;
46+
0 commit comments