11const getOrdinalNumber = require ( "./get-ordinal-number" ) ;
2+ test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
3+ expect ( getOrdinalNumber ( 1 ) ) . toEqual ( "1st" ) ;
4+ expect ( getOrdinalNumber ( 21 ) ) . toEqual ( "21st" ) ;
5+ expect ( getOrdinalNumber ( 131 ) ) . toEqual ( "131st" ) ;
6+ } ) ;
7+
8+ // Case 2: Numbers ending with 2 (but not 12)
9+ // When the number ends with 2, except those ending with 12,
10+ // Then the function should return a string by appending "nd" to the number.
11+ test ( "should append 'nd' for numbers ending with 2, except those ending with 12" , ( ) => {
12+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
13+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
14+ expect ( getOrdinalNumber ( 132 ) ) . toEqual ( "132nd" ) ;
15+ } ) ;
16+
217// In this week's prep, we started implementing getOrdinalNumber.
18+ // This function takes a number as input and returns a string with the appropriate ordinal suffix ("st", "nd", "rd", "th").
19+ // For example:
20+ // - getOrdinalNumber(1) should return "1st"
321
422// Continue testing and implementing getOrdinalNumber for additional cases.
523// Write your tests using Jest — remember to run your tests often for continual feedback.
6-
24+ test ( "should append 'rd' for numbers ending with 3, except those ending with 13" , ( ) => {
25+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
26+ expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
27+ expect ( getOrdinalNumber ( 133 ) ) . toEqual ( "133rd" ) ;
28+ } ) ;
729// To ensure thorough testing, we need broad scenarios that cover all possible cases.
830// Listing individual values, however, can quickly lead to an unmanageable number of test cases.
931// Instead of writing tests for individual numbers, consider grouping all possible input values
@@ -13,8 +35,18 @@ const getOrdinalNumber = require("./get-ordinal-number");
1335// Case 1: Numbers ending with 1 (but not 11)
1436// When the number ends with 1, except those ending with 11,
1537// 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 ( 21 ) ) . toEqual ( "21st" ) ;
19- expect ( getOrdinalNumber ( 131 ) ) . toEqual ( "131st" ) ;
38+ test ( "should append 'th' for numbers ending with 11, 12, or 13" , ( ) => {
39+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
40+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
41+ expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13th" ) ;
42+ } ) ;
43+
44+ // Case 4: All other numbers
45+ // When the number does not end with 1, 2, or 3 (or ends with 11, 12, or 13),
46+ // Then the function should return a string by appending "th" to the number.
47+ test ( "should append 'th' for all other numbers" , ( ) => {
48+ expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
49+ expect ( getOrdinalNumber ( 10 ) ) . toEqual ( "10th" ) ;
50+ expect ( getOrdinalNumber ( 14 ) ) . toEqual ( "14th" ) ;
51+ expect ( getOrdinalNumber ( 100 ) ) . toEqual ( "100th" ) ;
2052} ) ;
0 commit comments