@@ -16,28 +16,49 @@ 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
26+ test ( "given an array with one number, it 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, it returns the largest number" , ( ) => {
34+ expect ( findMax ( [ - 5 , 10 , - 2 , 7 ] ) ) . toBe ( 10 ) ;
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 an array with just negative numbers, it returns the closest to zero" , ( ) => {
41+ expect ( findMax ( [ - 10 , - 3 , - 20 ] ) ) . toBe ( - 3 ) ;
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 an array with decimal numbers, it returns the largest decimal number" , ( ) => {
48+ expect ( findMax ( [ 1.2 , 3.5 , 2.8 ] ) ) . toBe ( 3.5 ) ;
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 ( "given an array with non-number values, it returns the max and ignores non-numeric values" , ( ) => {
55+ expect ( findMax ( [ "hi" , 10 , "hello" , 60 , false , 20 ] ) ) . 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
61+ test ( "given an array with only non-number values, it returns -Infinity" , ( ) => {
62+ expect ( findMax ( [ "a" , "hello" , false , null , undefined ] ) ) . toBe ( - Infinity ) ;
63+ } ) ;
64+
0 commit comments