@@ -16,28 +16,48 @@ 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
26+ test ( "given an array with one number, returns that number" , ( ) => {
27+ expect ( findMax ( [ 60 ] ) ) . toBe ( 60 ) ;
28+ } ) ;
2429
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 positive and negative numbers, returns the largest" , ( ) => {
34+ expect ( findMax ( [ - 10 , 0 , 15 , - 4 , 7 ] ) ) . toBe ( 15 ) ;
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
40+ test ( "given only negative numbers, returns the least negative" , ( ) => {
41+ expect ( findMax ( [ - 50 , - 10 , - 30 ] ) ) . toBe ( - 10 ) ;
42+ } ) ;
3243
3344// Given an array with decimal numbers
3445// When passed to the max function
3546// Then it should return the largest decimal number
47+ test ( "given decimal numbers, returns the largest one" , ( ) => {
48+ expect ( findMax ( [ 6.2 , 7.5 , 2.7 ] ) ) . toBe ( 7.5 ) ;
49+ } ) ;
3650
3751// Given an array with non-number values
3852// When passed to the max function
3953// Then it should return the max and ignore non-numeric values
54+ test ( "given an array with non-number values, ignores non-number values and returns the max number" , ( ) => {
55+ expect ( findMax ( [ 'hey' , 10 , 'hi' , 60 , 10 ] ) ) . toBe ( 60 ) ;
56+ } ) ;
4057
41- // Given an array with only non-number values
58+ // Given an array with only non-number values
4259// When passed to the max function
4360// Then it should return the least surprising value given how it behaves for all other inputs
61+ test ( "given an array with only non-number values, returns -Infinity" , ( ) => {
62+ expect ( findMax ( [ 'hey' , 'hi' , 'hello' ] ) ) . toBe ( - Infinity ) ;
63+ } ) ;
0 commit comments