@@ -18,3 +18,41 @@ 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
23+ // When the number ends with 2
24+ // Then the function should return a string by appending "nd" to the number.
25+ test ( "should append 'nd' for numbers ending with 2" , ( ) => {
26+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
27+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
28+ expect ( getOrdinalNumber ( 132 ) ) . toEqual ( "132nd" ) ;
29+ } ) ;
30+
31+ // Case 3: Numbers ending with 3
32+ // When the number ends with 3
33+ // Then the function should return a string by appending "rd" to the number.
34+ test ( "should append 'rd' for numbers ending with 3" , ( ) => {
35+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
36+ expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
37+ expect ( getOrdinalNumber ( 223 ) ) . toEqual ( "223rd" ) ;
38+ } ) ;
39+
40+ // Case 4: the general(ish) case
41+ // When numbers end with 0, 4, 5, 6, 7, 8, 9
42+ // The function should return a string by appending "th" to the number
43+ test ( "should append 'th' for numbers ending with 0, 4, 5, 6, 7, 8, 9" , ( ) => {
44+ expect ( getOrdinalNumber ( 10 ) ) . toEqual ( "10th" ) ;
45+ expect ( getOrdinalNumber ( 24 ) ) . toEqual ( "24th" ) ;
46+ expect ( getOrdinalNumber ( 25 ) ) . toEqual ( "25th" ) ;
47+ expect ( getOrdinalNumber ( 46 ) ) . toEqual ( "46th" ) ;
48+ expect ( getOrdinalNumber ( 57 ) ) . toEqual ( "57th" ) ;
49+ expect ( getOrdinalNumber ( 78 ) ) . toEqual ( "78th" ) ;
50+ expect ( getOrdinalNumber ( 89 ) ) . toEqual ( "89th" ) ;
51+ } ) ;
52+
53+ // Case 5: The special case of 11
54+ // When the number is 11
55+ // Then the function should return a string by appending "th" to the number.
56+ test ( "should append 'th' for 11" , ( ) => {
57+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
58+ } ) ;
0 commit comments