@@ -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 ( [ 5 ] ) ) . toBe ( 5 ) ;
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 ( "returns the largest number from positive and negative numbers" , ( ) => {
33+ expect ( findMax ( [ - 10 , 20 , - 5 , 15 ] ) ) . toBe ( 20 ) ;
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 ( "returns the largest negative number" , ( ) => {
40+ expect ( findMax ( [ - 10 , - 5 , - 20 ] ) ) . toBe ( - 5 ) ;
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 ( "returns the largest decimal number" , ( ) => {
47+ expect ( findMax ( [ 1.5 , 2.7 , 2.3 ] ) ) . toBe ( 2.7 ) ;
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 ( "ignores non-number values" , ( ) => {
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 ( "returns -Infinity when the array contains only non-number values" , ( ) => {
61+ expect ( findMax ( [ "hey" , null , undefined , "hi" ] ) ) . toBe ( - Infinity ) ;
62+ } ) ;
0 commit comments