@@ -21,8 +21,6 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
2121
2222// here are more test cases for different scenarios
2323
24- const getOrdinalNumber = require ( "./get-ordinal-number" ) ;
25-
2624describe ( "getOrdinalNumber" , ( ) => {
2725 // Case 1: Already defined in your prompt
2826 test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
@@ -55,12 +53,26 @@ describe("getOrdinalNumber", () => {
5553 expect ( getOrdinalNumber ( 113 ) ) . toEqual ( "113th" ) ;
5654 } ) ;
5755
58- // Case 5: All other numbers
59- test ( "should append 'th' for all other numbers" , ( ) => {
60- expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
61- expect ( getOrdinalNumber ( 10 ) ) . toEqual ( "10th" ) ;
62- expect ( getOrdinalNumber ( 20 ) ) . toEqual ( "20th" ) ;
63- expect ( getOrdinalNumber ( 34 ) ) . toEqual ( "34th" ) ;
64- expect ( getOrdinalNumber ( 100 ) ) . toEqual ( "100th" ) ;
56+ // Case 5: Numbers ending in 0, 4, 5, 6, 7, 8, or 9
57+ describe ( "numbers ending with 0, 4, 5, 6, 7, 8, or 9" , ( ) => {
58+ const defaultThCases = [
59+ { endingDigit : 0 , testValues : [ 0 , 10 , 20 , 100 , - 10 ] } ,
60+ { endingDigit : 4 , testValues : [ 4 , 24 , 104 , - 4 ] } ,
61+ { endingDigit : 5 , testValues : [ 5 , 25 , 105 , - 5 ] } ,
62+ { endingDigit : 6 , testValues : [ 6 , 26 , 106 , - 6 ] } ,
63+ { endingDigit : 7 , testValues : [ 7 , 27 , 107 , - 7 ] } ,
64+ { endingDigit : 8 , testValues : [ 8 , 28 , 108 , - 8 ] } ,
65+ { endingDigit : 9 , testValues : [ 9 , 29 , 109 , - 9 ] } ,
66+ ] ;
67+
68+
69+ defaultThCases . forEach ( ( { endingDigit, testValues } ) => {
70+ test . each ( testValues ) (
71+ `appends "th" to %i (representative for digit ${ endingDigit } )` ,
72+ ( num ) => {
73+ expect ( getOrdinalNumber ( num ) ) . toBe ( `${ num } th` ) ;
74+ }
75+ ) ;
76+ } ) ;
6577 } ) ;
66- } ) ;
78+ } ) ;
0 commit comments