@@ -16,28 +16,65 @@ 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+ // This one is good to go!
20+ test ( "given an empty array, returns -Infinity" , ( ) => {
21+ const input = [ ] ;
22+ const result = findMax ( input ) ;
23+ expect ( result ) . toEqual ( - Infinity ) ;
24+ } ) ;
2025
2126// Given an array with one number
2227// When passed to the max function
2328// Then it should return that number
29+ test ( "given an array with 1 number, it returns the number " , ( ) => { ;
30+ const inputMax1 = [ 3 ] ;
31+ const result = findMax ( inputMax1 ) ;
32+ expect ( result ) . toEqual ( 3 ) ;
33+ } ) ;
34+
2435
2536// Given an array with both positive and negative numbers
2637// When passed to the max function
2738// Then it should return the largest number overall
39+ test ( "give 2 positive numbers return the largest nunber" , ( ) => {
40+ const inputMax2 = [ 5 , 8 ] ;
41+ const result = findMax ( inputMax2 ) ;
42+ expect ( result ) . toEqual ( 8 ) ;
43+ } ) ;
2844
2945// Given an array with just negative numbers
3046// When passed to the max function
3147// Then it should return the closest one to zero
48+ test ( "Given an array with just negative numbers return colest to Zero" , ( ) => {
49+ const inputMax3 = [ - 5 , - 3 ] ;
50+ const result = findMax ( inputMax3 ) ;
51+ expect ( result ) . toEqual ( - 3 ) ;
52+ } ) ;
3253
3354// Given an array with decimal numbers
3455// When passed to the max function
3556// Then it should return the largest decimal number
57+ test ( "Given an array with decimal numbers, should return the largest decimal number" , ( ) => {
58+ const inputMax4 = [ 2.4 , 3.5 ] ;
59+ const result = findMax ( inputMax4 ) ;
60+ expect ( result ) . toEqual ( 3.5 ) ;
61+ } ) ;
3662
3763// Given an array with non-number values
3864// When passed to the max function
3965// Then it should return the max and ignore non-numeric values
66+ test ( "Given an array with non-number values,it should return the max and ignore non-numeric values " , ( ) => {
67+ const inputMax5 = [ 2 , "apple" , 5 , "banana" , 8 , "watermelon" ] ;
68+ const result = findMax ( inputMax5 ) ;
69+ expect ( result ) . toEqual ( 8 ) ;
70+ } ) ;
4071
4172// Given an array with only non-number values
4273// When passed to the max function
4374// Then it should return the least surprising value given how it behaves for all other inputs
75+ test ( " Given an array with only non-number values,it should return the least surprising value given how it behaves for all other inputs " , ( ) => {
76+ const inputMax6 = [ "computer" , "bike" , "car" , "ball" ] ;
77+ const result = findMax ( inputMax6 ) ;
78+ expect ( result ) . toEqual ( - Infinity ) ;
79+ } ) ;
80+
0 commit comments