@@ -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+ describe ( "findMax" , ( ) => {
20+ test ( "given an empty array, returns -Infinity" , ( ) => {
21+ expect ( findMax ( [ ] ) ) . toBe ( - Infinity ) ;
22+ } ) ;
2023
2124// Given an array with one number
2225// When passed to the max function
2326// Then it should return that number
24-
27+ test ( "given an array with one number, returns that number" , ( ) => {
28+ expect ( findMax ( [ 42 ] ) ) . toBe ( 42 ) ;
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
33+ test ( "given an array with positive and negative numbers, returns the largest number" , ( ) => {
34+ expect ( findMax ( [ 10 , - 5 , 20 , 0 , - 2 ] ) ) . toBe ( 20 ) ;
35+ } ) ;
2836
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 just negative numbers, returns the closest one to zero" , ( ) => {
41+ expect ( findMax ( [ - 10 , - 50 , - 3 , - 7 ] ) ) . toBe ( - 3 ) ;
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, returns the largest decimal number" , ( ) => {
47+ expect ( findMax ( [ 1.5 , 2.7 , 0.3 , 2.6 ] ) ) . toBe ( 2.7 ) ;
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 with non-number values, ignores them and returns the largest number" , ( ) => {
53+ expect ( findMax ( [ 10 , "hi" , 20 , null , 5 ] ) ) . toBe ( 20 ) ;
54+ } ) ;
4155// Given an array with only non-number values
4256// When passed to the max function
4357// Then it should return the least surprising value given how it behaves for all other inputs
58+ test ( "given an array with only non-number values, returns -Infinity" , ( ) => {
59+ expect ( findMax ( [ "a" , "b" , null , undefined ] ) ) . toBe ( - Infinity ) ;
60+ } ) ;
61+ } ) ;
0 commit comments