@@ -16,28 +16,46 @@ 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, it 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 an array with one number, it should return that number` , ( ) => {
27+ expect ( findMax ( [ 80 ] ) ) . toEqual ( 80 ) ;
28+ expect ( findMax ( [ 1 ] ) ) . toEqual ( 1 ) ;
29+ } ) ;
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
28-
33+ test ( `given an array with both positive numbers and negative numbers, it should return the largest number overall` , ( ) => {
34+ expect ( findMax ( [ 80 , - 30 , 50 , - 10 , 20 , 100 , 40 ] ) ) . toEqual ( 100 ) ;
35+ expect ( findMax ( [ - 90 , 30 , 250 , 1 , 120 , - 100 , - 40 ] ) ) . toEqual ( 250 ) ;
36+ } ) ;
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
32-
40+ test ( `given an array with negative numbers, it should return the addition of them all` , ( ) => {
41+ expect ( findMax ( [ - 80 , - 30 , - 50 , - 10 , - 20 , - 100 , - 40 ] ) ) . toEqual ( - 10 ) ;
42+ } ) ;
3343// Given an array with decimal numbers
3444// When passed to the max function
3545// Then it should return the largest decimal number
36-
46+ test ( `given an array with decimal numbers, it should return the largest decimal number` , ( ) => {
47+ expect ( findMax ( [ - 80.5 , - 30.1 , 50.7 , - 10 , 20.4 , 10.3 , 60.1 ] ) ) . toEqual ( 60.1 ) ;
48+ } ) ;
3749// Given an array with non-number values
3850// When passed to the max function
3951// Then it should return the max and ignore non-numeric values
40-
52+ test ( `given an array of numeric and non-numeric values, it should return the largest numeric` , ( ) => {
53+ expect ( findMax ( [ 'hey' , 10 , 'hi' , 60 , 10 ] ) ) . toEqual ( 60 ) ;
54+ expect ( findMax ( [ 'i' , 'love' , 10 , 'code' , 'hi' , 80 , 60 , 'your' , 'future' , 10 ] ) ) . toEqual ( 80 ) ;
55+ } ) ;
4156// Given an array with only non-number values
4257// When passed to the max function
4358// Then it should return the least surprising value given how it behaves for all other inputs
59+ test ( `given an array of non-numeric values, it should return -Infinity` , ( ) => {
60+ expect ( findMax ( [ 'i' , 'love' , 'code' , 'your' , 'future' ] ) ) . toEqual ( - Infinity ) ;
61+ } ) ;
0 commit comments