@@ -15,29 +15,53 @@ const findMax = require("./max.js");
1515// Given an empty array
1616// When passed to the max function
1717// Then it should return -Infinity
18- // Delete this test.todo and replace it with a test.
19- test . todo ( "given an empty array, returns -Infinity" ) ;
18+ test ( "given an empty array, returns -Infinity" , ( ) => {
19+ expect ( findMax ( [ ] ) ) . toBe ( - Infinity ) ;
20+ } ) ;
2021
2122// Given an array with one number
2223// When passed to the max function
2324// Then it should return that number
25+ test ( "given an array with one number, returns that number" , ( ) => {
26+ expect ( findMax ( [ 42 ] ) ) . toBe ( 42 ) ;
27+ expect ( findMax ( [ - 5 ] ) ) . toBe ( - 5 ) ;
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 an array with positive and negative numbers, returns the largest" , ( ) => {
34+ expect ( findMax ( [ 30 , 50 , 10 , 40 ] ) ) . toBe ( 50 ) ;
35+ expect ( findMax ( [ - 10 , 5 , - 20 , 15 ] ) ) . toBe ( 15 ) ;
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 only negative numbers, returns closest to zero" , ( ) => {
42+ expect ( findMax ( [ - 10 , - 5 , - 20 ] ) ) . toBe ( - 5 ) ;
43+ expect ( findMax ( [ - 1 , - 2 , - 3 ] ) ) . toBe ( - 1 ) ;
44+ } ) ;
3245
3346// Given an array with decimal numbers
3447// When passed to the max function
3548// Then it should return the largest decimal number
49+ test ( "given an array with decimal numbers, returns the largest" , ( ) => {
50+ expect ( findMax ( [ 1.5 , 2.7 , 1.9 ] ) ) . toBe ( 2.7 ) ;
51+ expect ( findMax ( [ 0.1 , 0.3 , 0.2 ] ) ) . toBe ( 0.3 ) ;
52+ } ) ;
3653
3754// Given an array with non-number values
3855// When passed to the max function
3956// Then it should return the max and ignore non-numeric values
57+ test ( "given an array with non-numeric values, ignores them" , ( ) => {
58+ expect ( findMax ( [ 'hey' , 10 , 'hi' , 60 , 10 ] ) ) . toBe ( 60 ) ;
59+ expect ( findMax ( [ true , 5 , null , 25 , 'hello' ] ) ) . toBe ( 25 ) ;
60+ } ) ;
4061
4162// Given an array with only non-number values
4263// When passed to the max function
4364// Then it should return the least surprising value given how it behaves for all other inputs
65+ test ( "given an array with only non-numeric values, returns -Infinity" , ( ) => {
66+ expect ( findMax ( [ 'hello' , 'world' , true , null ] ) ) . toBe ( - Infinity ) ;
67+ } ) ;
0 commit comments