11import { getOrdinalNumber } from "./get-ordinal-number.js" ;
2- import { test , expect } from "@jest/globals" ;
32// In this week's prep, we started implementing getOrdinalNumber.
43
54// Continue testing and implementing getOrdinalNumber for additional cases.
@@ -12,13 +11,6 @@ import { test, expect } from "@jest/globals";
1211// This approach improves coverage and makes our tests easier to maintain.
1312
1413// Case 1: Numbers ending with 1 (but not 11)
15- test ( "should not append 'st' for number ending with 11 " , ( ) => {
16- expect ( ( ) => getOrdinalNumber ( 11 ) ) . toThrow ( "Input must not ending with 11" ) ;
17- expect ( ( ) => getOrdinalNumber ( 111 ) ) . toThrow ( "Input must not ending with 11" ) ;
18- expect ( ( ) => getOrdinalNumber ( 45711 ) ) . toThrow (
19- "Input must not ending with 11"
20- ) ;
21- } ) ;
2214
2315// When the number ends with 1, except those ending with 11,
2416// Then the function should return a string by appending "st" to the number.
@@ -29,42 +21,32 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
2921 expect ( getOrdinalNumber ( 241 ) ) . toEqual ( "241st" ) ;
3022} ) ;
3123
32- // Case 2: Numbers ending with 2 (but not 22 )
33- // When the number ends with 2, except those ending with 22 ,
24+ // Case 2: Numbers ending with 2 (but not 12 )
25+ // When the number ends with 2, except those ending with 12 ,
3426// Then the function should return a string by appending "nd" to the number.
35- test ( "should append 'nd' for numbers ending with 2, except those ending with 22 " , ( ) => {
27+ test ( "should append 'nd' for numbers ending with 2, except those ending with 12 " , ( ) => {
3628 expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
29+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
3730 expect ( getOrdinalNumber ( 32 ) ) . toEqual ( "32nd" ) ;
3831 expect ( getOrdinalNumber ( 132 ) ) . toEqual ( "132nd" ) ;
3932} ) ;
4033
41- test ( "should not append 'nd' for number ending with 22 " , ( ) => {
42- expect ( ( ) => getOrdinalNumber ( 22 ) ) . toThrow ( "Input must not ending with 22" ) ;
43- expect ( ( ) => getOrdinalNumber ( 122 ) ) . toThrow ( "Input must not ending with 22" ) ;
44- expect ( ( ) => getOrdinalNumber ( 45722 ) ) . toThrow (
45- "Input must not ending with 22"
46- ) ;
47- } ) ;
48-
49- // Case 3: Numbers ending with 3 (but not 33)
50- test ( "should append 'rd' for numbers ending with 3, except those ending with 33" , ( ) => {
34+ // Case 3: Numbers ending with 3 (but not 13)
35+ test ( "should append 'rd' for numbers ending with 3, except those ending with 13" , ( ) => {
5136 expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
52- expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13rd " ) ;
37+ expect ( getOrdinalNumber ( 33 ) ) . toEqual ( "33rd " ) ;
5338 expect ( getOrdinalNumber ( 123 ) ) . toEqual ( "123rd" ) ;
5439} ) ;
5540
56- test ( "should not append 'rd' for number ending with 33 " , ( ) => {
57- expect ( ( ) => getOrdinalNumber ( 33 ) ) . toThrow ( "Input must not ending with 33" ) ;
58- expect ( ( ) => getOrdinalNumber ( 133 ) ) . toThrow ( "Input must not ending with 33" ) ;
59- expect ( ( ) => getOrdinalNumber ( 45733 ) ) . toThrow (
60- "Input must not ending with 33"
61- ) ;
62- } ) ;
63-
6441// Case 3: Numbers ending in other digits
6542test ( "should append 'th' for numbers ending in other digits" , ( ) => {
66- expect ( getOrdinalNumber ( 4 ) ) . toBe ( "4th" ) ;
43+ expect ( getOrdinalNumber ( 11 ) ) . toBe ( "11th" ) ;
44+ expect ( getOrdinalNumber ( 12 ) ) . toBe ( "12th" ) ;
45+ expect ( getOrdinalNumber ( 13 ) ) . toBe ( "13th" ) ;
6746 expect ( getOrdinalNumber ( 5 ) ) . toBe ( "5th" ) ;
6847 expect ( getOrdinalNumber ( 10 ) ) . toBe ( "10th" ) ;
6948 expect ( getOrdinalNumber ( 20 ) ) . toBe ( "20th" ) ;
49+ expect ( getOrdinalNumber ( 111 ) ) . toBe ( "111th" ) ;
50+ expect ( getOrdinalNumber ( 113 ) ) . toBe ( "113th" ) ;
51+ expect ( getOrdinalNumber ( 112 ) ) . toBe ( "112th" ) ;
7052} ) ;
0 commit comments