@@ -16,28 +16,43 @@ const findMax = require("./max.js");
1616// When passed to the max function
1717// Then it should return -Infinity
1818// Delete this test.todo and replace it with a test.
19- test . todo ( "given an empty array, returns -Infinity" ) ;
19+ test ( "given an empty array, returns -Infinity" , ( ) => {
20+ expect ( findMax ( [ ] ) ) . toBe ( - Infinity ) ;
21+ } ) ;
2022
2123// Given an array with one number
2224// When passed to the max function
2325// Then it should return that number
24-
26+ test ( "given an empty array, returns 0" , ( ) => {
27+ expect ( findMax ( [ 78 ] ) ) . toBe ( 78 ) ;
28+ } ) ;
2529// Given an array with both positive and negative numbers
2630// When passed to the max function
2731// Then it should return the largest number overall
28-
32+ test ( "given an array with positive and negative numbers, returns largest number" , ( ) => {
33+ expect ( findMax ( [ - 8 , 10 , 45 , - 60 ] ) ) . toBe ( 45 ) ;
34+ } ) ;
2935// Given an array with just negative numbers
3036// When passed to the max function
3137// Then it should return the closest one to zero
32-
38+ test ( "given an array with negative numbers, returns closest to 0" , ( ) => {
39+ expect ( findMax ( [ - 8 , - 7 , - 5 , - 60 ] ) ) . toBe ( - 5 ) ;
40+ } ) ;
3341// Given an array with decimal numbers
3442// When passed to the max function
3543// Then it should return the largest decimal number
36-
44+ test ( "given an array with decimal numbers, returns largest number" , ( ) => {
45+ expect ( findMax ( [ 3.7 , 5.8 , 4.5 , 60.8 ] ) ) . toBe ( 60.8 ) ;
46+ } ) ;
3747// Given an array with non-number values
3848// When passed to the max function
3949// Then it should return the max and ignore non-numeric values
40-
50+ test ( "given an array with non-number values, returns number" , ( ) => {
51+ expect ( findMax ( [ 100 , "hello" , 94 ] ) ) . toBe ( 100 ) ;
52+ } ) ;
4153// Given an array with only non-number values
4254// When passed to the max function
4355// Then it should return the least surprising value given how it behaves for all other inputs
56+ test ( "given an array with non-numbers, returns -Infinity" , ( ) => {
57+ expect ( findMax ( [ "hi" , "maryam" , "here" ] ) ) . toBe ( - Infinity ) ;
58+ } ) ;
0 commit comments