@@ -16,28 +16,58 @@ 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+
20+ test ( "returns -Infinity for an empty array" , ( ) => {
21+ expect ( findMax ( [ ] ) ) . toEqual ( - Infinity ) ;
22+ } )
2023
2124// Given an array with one number
2225// When passed to the max function
2326// Then it should return that number
2427
28+ test ( "given an array with one number, should return that number" , ( ) => {
29+ expect ( findMax ( [ 8 ] ) ) . toEqual ( 8 ) ;
30+ expect ( findMax ( [ - 5 ] ) ) . toEqual ( - 5 ) ;
31+ expect ( findMax ( [ 0 ] ) ) . toEqual ( 0 ) ;
32+ } )
33+
2534// Given an array with both positive and negative numbers
2635// When passed to the max function
2736// Then it should return the largest number overall
2837
38+ test ( "return the largest number overall" , ( ) => {
39+ expect ( findMax ( [ - 8 , - 4 , 0 , 4 , 8 ] ) ) . toEqual ( 8 ) ;
40+ expect ( findMax ( [ - 3 , - 2 , - 1 , 4 , 2 , 3 ] ) ) . toEqual ( 4 ) ;
41+ } )
42+
2943// Given an array with just negative numbers
3044// When passed to the max function
3145// Then it should return the closest one to zero
3246
47+ test ( "given an array with only negative numbers, should return closest to 0" , ( ) => {
48+ expect ( findMax ( [ - 2 , - 4 , - 1 , - 3 , - 100 ] ) ) . toEqual ( - 1 ) ;
49+ } )
50+
3351// Given an array with decimal numbers
3452// When passed to the max function
3553// Then it should return the largest decimal number
3654
55+ test ( "an array with decimal numbers, should return the largest decimal number" , ( ) => {
56+ expect ( findMax ( [ 0.1 , 0.2 , 0.9 , 0.8 , 0.3 , 0.7 , 0.4 , 0.6 ] ) ) . toEqual ( 0.9 ) ;
57+ } )
58+
3759// Given an array with non-number values
3860// When passed to the max function
3961// Then it should return the max and ignore non-numeric values
4062
63+ test ( "ignore the non-numeric values" , ( ) => {
64+ expect ( findMax ( [ "Blue" , 3 , "White" , "Orange" , "Pink" ] ) ) . toEqual ( 3 ) ;
65+ } )
66+
4167// Given an array with only non-number values
4268// When passed to the max function
4369// Then it should return the least surprising value given how it behaves for all other inputs
70+
71+ test ( "an array with only non-number values" , ( ) => {
72+ expect ( findMax ( [ "Blue" , "White" , "Orange" , "Pink" ] ) ) . toEqual ( - Infinity ) ;
73+ } )
0 commit comments