@@ -9,24 +9,29 @@ const getOrdinalNumber = require("./get-ordinal-number");
99// Instead of writing tests for individual numbers, consider grouping all possible input values
1010// into meaningful categories. Then, select representative samples from each category to test.
1111// This approach improves coverage and makes our tests easier to maintain.
12+ // Case 4: Numbers ending with 11, 12, or 13 (the exceptions)
13+ // These should always get "th", even though they end in 1, 2, or 3.
14+
1215
1316// Case 1: Numbers ending with 1 (but not 11)
1417// When the number ends with 1, except those ending with 11,
1518// Then the function should return a string by appending "st" to the number.
16- test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
17- expect ( getOrdinalNumber ( 1 ) ) . toEqual ( "1st" ) ;
18- expect ( getOrdinalNumber ( 31 ) ) . toEqual ( "31st" ) ;
19- expect ( getOrdinalNumber ( 131 ) ) . toEqual ( "131st " ) ;
20- } ) ;
21- test ( `should append 'nd' for numbers ending with 2 except those ending with 12 ` , ( ) => {
22- expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd " ) ;
23- expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd " ) ;
24- expect ( getOrdinalNumber ( 132 ) ) . toEqual ( "132nd " ) ;
19+ // Case 4: Numbers ending with 11, 12, or 13 (the exceptions)
20+ // These should always get "th", even though they end in 1, 2, or 3.
21+ test ( "should append 'th' for numbers ending with 11, 12, or 13" , ( ) => {
22+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th " ) ;
23+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
24+ expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13th" ) ;
25+ expect ( getOrdinalNumber ( 111 ) ) . toEqual ( "111th " ) ;
26+ expect ( getOrdinalNumber ( 112 ) ) . toEqual ( "112th " ) ;
27+ expect ( getOrdinalNumber ( 113 ) ) . toEqual ( "113th " ) ;
2528} ) ;
2629
27- test ( `should append 'rd' for numbers ending with 3 except those ending with 13 ` , ( ) => {
28- expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
29- expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
30- expect ( getOrdinalNumber ( 143 ) ) . toEqual ( "143rd" ) ;
31- } ) ;
32-
30+ // Case 5: Numbers ending with 4-9, and 0
31+ // These should always get "th".
32+ test ( "should append 'th' for numbers ending with 0 or 4-9" , ( ) => {
33+ expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
34+ expect ( getOrdinalNumber ( 15 ) ) . toEqual ( "15th" ) ;
35+ expect ( getOrdinalNumber ( 20 ) ) . toEqual ( "20th" ) ;
36+ expect ( getOrdinalNumber ( 100 ) ) . toEqual ( "100th" ) ;
37+ } ) ;
0 commit comments