@@ -16,29 +16,48 @@ 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 null" , ( ) => {
20+ expect ( findMax ( [ ] ) ) . toBe ( null ) ;
21+ } ) ;
2022
2123// Given an array with one number
2224// When passed to the max function
2325// Then it should return that number
26+ test ( "given an array with one number , returns that number" , ( ) => {
27+ expect ( findMax ( [ 7 ] ) ) . toBe ( 7 ) ;
28+ } ) ;
2429
2530// Given an array with both positive and negative numbers
2631// When passed to the max function
2732// Then it should return the largest number overall
33+ test ( "given positive and negative numbers, returns the largest number" , ( ) => {
34+ expect ( findMax ( [ - 10 , 0 , 5 , - 3 , 8 ] ) ) . toBe ( 8 ) ;
35+ } ) ;
2836
2937// Given an array with just negative numbers
3038// When passed to the max function
3139// Then it should return the closest one to zero
40+ test ( "given only negative numbers, returns the largest negative number" , ( ) => {
41+ expect ( findMax ( [ - 10 , - 4 , - 2 , - 30 ] ) ) . toBe ( - 2 ) ;
42+ } ) ;
3243
3344// Given an array with decimal numbers
3445// When passed to the max function
3546// Then it should return the largest decimal number
47+ test ( "given decimal numbers, returns the largest decimal number" , ( ) => {
48+ expect ( findMax ( [ 1.2 , 3.7 , 2.5 ] ) ) . toBe ( 3.7 ) ;
49+ } ) ;
3650
3751// Given an array with non-number values
3852// When passed to the max function
3953// Then it should return the max and ignore non-numeric values
54+ test ( "ignores non-number values and returns the max" , ( ) => {
55+ expect ( findMax ( [ "hey" , 10 , "hi" , 60 , 10 ] ) ) . toBe ( 60 ) ;
56+ } ) ;
4057
4158// Given an array with only non-number values
4259// When passed to the max function
4360// Then it should return the least surprising value given how it behaves for all other inputs
44-
61+ test ( "given only non-number values, returns null" , ( ) => {
62+ expect ( findMax ( [ "hey" , "hi" , null , undefined , NaN ] ) ) . toBe ( null ) ;
63+ } ) ;
0 commit comments