@@ -16,28 +16,30 @@ 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 ( [ ] ) ) . toEqual ( - Infinity ) ;
21+ } ) ;
2022
21- // Given an array with one number
22- // When passed to the max function
23- // Then it should return that number
23+ test ( "given an array with one number, returns that number" , ( ) => {
24+ expect ( findMax ( [ 7 ] ) ) . toEqual ( 7 ) ;
25+ } ) ;
2426
25- // Given an array with both positive and negative numbers
26- // When passed to the max function
27- // Then it should return the largest number overall
27+ test ( "given an array with positive and negative numbers, returns the largest" , ( ) => {
28+ expect ( findMax ( [ - 3 , 0 , 5 , - 1 ] ) ) . toEqual ( 5 ) ;
29+ } ) ;
2830
29- // Given an array with just negative numbers
30- // When passed to the max function
31- // Then it should return the closest one to zero
31+ test ( "given an array with just negative numbers, returns the closest to zero" , ( ) => {
32+ expect ( findMax ( [ - 10 , - 3 , - 7 ] ) ) . toEqual ( - 3 ) ;
33+ } ) ;
3234
33- // Given an array with decimal numbers
34- // When passed to the max function
35- // Then it should return the largest decimal number
35+ test ( "given an array with decimal numbers, returns the largest decimal" , ( ) => {
36+ expect ( findMax ( [ 1.1 , 2.9 , 2.1 ] ) ) . toEqual ( 2.9 ) ;
37+ } ) ;
3638
37- // Given an array with non-number values
38- // When passed to the max function
39- // Then it should return the max and ignore non-numeric values
39+ test ( "given an array with non-number values, ignores them and returns the max" , ( ) => {
40+ expect ( findMax ( [ "hey" , 10 , "hi" , 60 , 10 ] ) ) . toEqual ( 60 ) ;
41+ } ) ;
4042
41- // Given an array with only non-number values
42- // When passed to the max function
43- // Then it should return the least surprising value given how it behaves for all other inputs
43+ test ( "given an array with only non-number values, returns -Infinity" , ( ) => {
44+ expect ( findMax ( [ "a" , "b" ] ) ) . toEqual ( - Infinity ) ;
45+ } ) ;
0 commit comments