@@ -15,29 +15,51 @@ 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+ // Delete this test.todo and replace it with a test
19+ test ( "given an empty array, returns -Infinity" , ( ) => {
20+ expect ( findMax ( [ ] ) ) . toEqual ( - Infinity ) ;
21+ } ) ;
2022
2123// Given an array with one number
2224// When passed to the max function
2325// Then it should return that number
24-
26+ test ( "given one number, when passed by max function, return that number" , ( ) => {
27+ expect ( findMax ( [ 1 ] ) ) . toEqual ( 1 ) ;
28+ } ) ;
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 ( "array with positive and negative numbers returns largest number" , ( ) => {
33+ expect ( findMax ( [ - 2 , 4 , - 3 , 5 , - 6 , 7 ] ) ) . toEqual ( 7 ) ;
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 ( "array with negative numbers , returns one closest to zero" , ( ) => {
40+ expect ( findMax ( [ - 2 , - 3 , - 5 ] ) ) . toEqual ( - 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 ( "array with decimal number,return largest decimal number" , ( ) => {
47+ expect ( findMax ( [ 1.2 , 2.2 , 3.1 , 5.5 ] ) ) . toEqual ( 5.5 )
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
40-
53+ test ( "array with non-number values ,return max number and ignore non-numeric values" , ( ) => {
54+ const input = [ "hi" , 6 , 2 , 1 , 7 , "we" , "put" ] ;
55+ const result = findMax ( input ) ;
56+ expect ( result ) . toEqual ( 7 ) ;
57+ } ) ;
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 ( "array with only non-number values, return the least surprising value" , ( ) => {
62+ const input = [ "no" , "hat" , "dot" , "cape" ] ;
63+ const result = findMax ( input ) ;
64+ expect ( result ) . toEqual ( - Infinity ) ;
65+ } ) ;
0 commit comments