@@ -16,28 +16,49 @@ 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+ } ) ;
22+
2023
2124// Given an array with one number
2225// When passed to the max function
2326// Then it should return that number
27+ test ( "given an array with one number, returns that number" , ( ) => {
28+ expect ( findMax ( [ 5 ] ) ) . toBe ( 5 ) ;
29+ } ) ;
2430
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
34+ test ( "given an array with both positive and negative numbers, returns the largest" , ( ) => {
35+ expect ( findMax ( [ 30 , 50 , 10 , 40 ] ) ) . toBe ( 50 ) ;
36+ } ) ;
2837
2938// Given an array with just negative numbers
3039// When passed to the max function
3140// Then it should return the closest one to zero
41+ test ( "given an array with just negative numbers, returns the closest to zero" , ( ) => {
42+ expect ( findMax ( [ - 10 , - 5 , - 20 ] ) ) . toBe ( - 5 ) ;
43+ } ) ;
3244
3345// Given an array with decimal numbers
3446// When passed to the max function
3547// Then it should return the largest decimal number
48+ test ( "given an array with decimal numbers, returns the largest" , ( ) => {
49+ expect ( findMax ( [ 3.14 , 2.71 , 1.41 ] ) ) . toBe ( 3.14 ) ;
50+ } ) ;
3651
3752// Given an array with non-number values
3853// When passed to the max function
3954// Then it should return the max and ignore non-numeric values
55+ test ( "given an array with non-number values, returns the largest number" , ( ) => {
56+ expect ( findMax ( [ 'hey' , 10 , 'hi' , 60 , 10 ] ) ) . toBe ( 60 ) ;
57+ } ) ;
4058
4159// Given an array with only non-number values
4260// When passed to the max function
4361// Then it should return the least surprising value given how it behaves for all other inputs
62+ test ( "given an array with only non-number values, returns the least surprising value" , ( ) => {
63+ expect ( findMax ( [ 'hey' , 'hi' , 'hello' ] ) ) . toBe ( null ) ;
64+ } ) ;
0 commit comments