@@ -16,28 +16,54 @@ 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
2426
27+ test ( "given an array with one number, returns that number" , ( ) => {
28+ expect ( findMax ( [ 7 ] ) ) . toBe ( 7 ) ;
29+ } ) ;
30+
2531// Given an array with both positive and negative numbers
2632// When passed to the max function
2733// Then it should return the largest number overall
2834
35+ test ( "given positive and negative numbers, returns the largest number" , ( ) => {
36+ expect ( findMax ( [ - 3 , 7 , - 2 , 5 ] ) ) . toBe ( 7 ) ;
37+ } ) ;
38+
2939// Given an array with just negative numbers
3040// When passed to the max function
3141// Then it should return the closest one to zero
3242
43+ test ( "given an array with only negative numbers, returns the closest to zero" , ( ) => {
44+ expect ( findMax ( [ - 10 , - 3 , - 7 ] ) ) . toBe ( - 3 ) ;
45+ } ) ;
46+
3347// Given an array with decimal numbers
3448// When passed to the max function
3549// Then it should return the largest decimal number
3650
51+ test ( "given an array with decimal numbers, returns the clargest decimal number" , ( ) => {
52+ expect ( findMax ( [ 2.7 , 6.9 , 10.1 ] ) ) . toBe ( 10.1 ) ;
53+ } ) ;
54+
3755// Given an array with non-number values
3856// When passed to the max function
3957// Then it should return the max and ignore non-numeric values
4058
59+ test ( "given an array with non-number values, returns the max and ignore non-numeric values" , ( ) => {
60+ expect ( findMax ( [ 3 , "dogs" , 1 , "cat" , null ] ) ) . toBe ( 3 ) ;
61+ } ) ;
62+
4163// Given an array with only non-number values
4264// When passed to the max function
4365// Then it should return the least surprising value given how it behaves for all other inputs
66+
67+ test ( "given an array with only non-number values, returns -Infinity" , ( ) => {
68+ expect ( findMax ( [ "a" , null , true , undefined ] ) ) . toBe ( - Infinity ) ;
69+ } ) ;
0 commit comments