@@ -58,4 +58,50 @@ test("should return '111th' for 111", () => {
5858
5959test ( "should return '0th' for 0" , ( ) => {
6060 expect ( getOrdinalNumber ( 0 ) ) . toEqual ( "0th" ) ;
61- } ) ;
61+ } ) ;
62+
63+ // Extra test to check for correct number of arguments
64+ test ( "should throw an error if no arguments are provided" , ( ) => {
65+ expect ( ( ) => getOrdinalNumber ( ) ) . toThrow ( "Function requires exactly one argument" ) ;
66+ } ) ;
67+
68+ test ( "should throw an error if more than one argument is provided" , ( ) => {
69+ expect ( ( ) => getOrdinalNumber ( 1 , 2 ) ) . toThrow ( "Function requires exactly one argument" ) ;
70+ } ) ;
71+
72+ //Invalid input tests
73+ test ( "should throw an error if the argument is not a number" , ( ) => {
74+ expect ( ( ) => getOrdinalNumber ( "a" ) ) . toThrow ( "Input must be a number" ) ;
75+ } ) ;
76+
77+ test ( "should throw an error if the argument is a negative number" , ( ) => {
78+ expect ( ( ) => getOrdinalNumber ( - 1 ) ) . toThrow ( "Input must be a non-negative integer" ) ;
79+ } ) ;
80+
81+ test ( "should throw an error if the argument is a decimal" , ( ) => {
82+ expect ( ( ) => getOrdinalNumber ( 1.5 ) ) . toThrow ( "Input must be a non-negative integer" ) ;
83+ } ) ;
84+
85+ test ( "should throw an error if the argument is NaN" , ( ) => {
86+ expect ( ( ) => getOrdinalNumber ( NaN ) ) . toThrow ( "Input must be a number" ) ;
87+ } ) ;
88+
89+ test ( "should throw an error if the argument is Infinity" , ( ) => {
90+ expect ( ( ) => getOrdinalNumber ( Infinity ) ) . toThrow ( "Input must be a finite number" ) ;
91+ } ) ;
92+
93+ test ( "should throw an error if the argument is -Infinity" , ( ) => {
94+ expect ( ( ) => getOrdinalNumber ( - Infinity ) ) . toThrow ( "Input must be a finite number" ) ;
95+ } ) ;
96+ test ( "should throw an error if the argument is an object" , ( ) => {
97+ expect ( ( ) => getOrdinalNumber ( { } ) ) . toThrow ( "Input must be a number" ) ;
98+ } ) ;
99+ test ( "should throw an error if the argument is an array" , ( ) => {
100+ expect ( ( ) => getOrdinalNumber ( [ ] ) ) . toThrow ( "Input must be a number" ) ;
101+ } ) ;
102+ test ( "should throw an error if the argument is null" , ( ) => {
103+ expect ( ( ) => getOrdinalNumber ( null ) ) . toThrow ( "Input must be a number" ) ;
104+ } ) ;
105+ test ( "should throw an error if the argument is undefined" , ( ) => {
106+ expect ( ( ) => getOrdinalNumber ( undefined ) ) . toThrow ( "Input must be a number" ) ;
107+ } ) ;
0 commit comments