@@ -18,3 +18,38 @@ 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 return 'nd' for numbers ending with 2` , ( ) => {
26+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
27+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
28+ expect ( getOrdinalNumber ( 122 ) ) . toEqual ( "122nd" ) ;
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 add 'rd' for numbers ending with 3` , ( ) => {
35+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
36+ expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
37+ expect ( getOrdinalNumber ( 123 ) ) . toEqual ( "123rd" ) ;
38+ } ) ;
39+
40+ //Case 4: Numbers ending with 11, 12, 13.
41+ // When the number ends with 11, 12 and 13,
42+ // Then the function should return a string by appending "th" to the number.
43+ test ( `should add 'th' to exceptions like 11, 12 and 13` , ( ) => {
44+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
45+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
46+ expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13th" ) ;
47+ } ) ;
48+
49+ //Case 5: All other numbers that are not ending with 1, 2, 3, and that are not 11, 12, and 13.
50+ // the function should return corresponding string with "th" at the end
51+ test ( `should add 'th' to every case that is not exceptional` , ( ) => {
52+ expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
53+ expect ( getOrdinalNumber ( 555 ) ) . toEqual ( "555th" ) ;
54+ expect ( getOrdinalNumber ( 6666 ) ) . toEqual ( "6666th" ) ;
55+ } ) ;
0 commit comments