@@ -15,29 +15,48 @@ const findMax = require("./max.js");
1515// Given an empty array
1616// When passed to the max function
1717// Then it should return -Infinity
18- // Delete this test.todo and replace it with a test.
19- test . todo ( "given an empty array, returns -Infinity" ) ;
18+ test ( "given an empty array, returns -Infinity" , ( ) => {
19+ expect ( findMax ( [ ] ) ) . toBe ( - Infinity ) ;
20+ } ) ;
2021
2122// Given an array with one number
2223// When passed to the max function
2324// Then it should return that number
25+ test ( "given an array with one number, returns that number" , ( ) => {
26+ expect ( findMax ( [ 42 ] ) ) . toBe ( 42 ) ;
27+ } ) ;
2428
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
32+ test ( "given an array with positive and negative numbers, returns the largest number" , ( ) => {
33+ expect ( findMax ( [ - 10 , 3 , 25 , - 1 ] ) ) . toBe ( 25 ) ;
34+ } ) ;
2835
2936// Given an array with just negative numbers
3037// When passed to the max function
3138// Then it should return the closest one to zero
39+ test ( "given an array with only negative numbers, returns the largest one" , ( ) => {
40+ expect ( findMax ( [ - 9 , - 2 , - 15 , - 4 ] ) ) . toBe ( - 2 ) ;
41+ } ) ;
3242
3343// Given an array with decimal numbers
3444// When passed to the max function
3545// Then it should return the largest decimal number
46+ test ( "given an array with decimal numbers, returns the largest decimal" , ( ) => {
47+ expect ( findMax ( [ 1.2 , 3.8 , 2.4 ] ) ) . toBe ( 3.8 ) ;
48+ } ) ;
3649
3750// Given an array with non-number values
3851// When passed to the max function
3952// Then it should return the max and ignore non-numeric values
53+ test ( "given an array with non-number values, ignores them and returns the max" , ( ) => {
54+ expect ( findMax ( [ "hey" , 10 , "hi" , 60 , 10 ] ) ) . toBe ( 60 ) ;
55+ } ) ;
4056
4157// Given an array with only non-number values
4258// When passed to the max function
4359// Then it should return the least surprising value given how it behaves for all other inputs
60+ test ( "given an array with only non-number values, returns -Infinity" , ( ) => {
61+ expect ( findMax ( [ "apple" , null , undefined , "banana" ] ) ) . toBe ( - Infinity ) ;
62+ } ) ;
0 commit comments