@@ -12,32 +12,72 @@ We have set things up already so that this file can see your function from the o
1212
1313const findMax = require ( "./max.js" ) ;
1414
15+ describe ( "calculateMedian" , ( ) => {
1516// Given an empty array
1617// When passed to the max function
1718// Then it should return -Infinity
1819// Delete this test.todo and replace it with a test.
19- test . todo ( "given an empty array, returns -Infinity" ) ;
20+
21+ it ( "empty array returns -Infinity" , ( ) => {
22+ const list = [ ] ;
23+ expect ( findMax ( list ) ) . toEqual ( "-Infinity" ) ;
24+ } ) ;
2025
2126// Given an array with one number
2227// When passed to the max function
2328// Then it should return that number
2429
30+ it ( "array with one number returns that number" , ( ) => {
31+ const list = [ 2 ] ;
32+ expect ( findMax ( list ) ) . toEqual ( 2 ) ;
33+ } ) ;
34+
2535// Given an array with both positive and negative numbers
2636// When passed to the max function
2737// Then it should return the largest number overall
2838
39+ it ( "array with +ve and -ve numbers, returns largest number overall" , ( ) => {
40+ const list = [ 10 , - 15 ] ;
41+ expect ( findMax ( list ) ) . toEqual ( 10 ) ;
42+ } ) ;
43+
44+
2945// Given an array with just negative numbers
3046// When passed to the max function
3147// Then it should return the closest one to zero
3248
49+ it ( "array -ve numbers, returns closest to zero" , ( ) => {
50+ const list = [ - 1 , - 2 , - 3 , - 15 ] ;
51+ expect ( findMax ( list ) ) . toEqual ( - 1 ) ;
52+ } ) ;
53+
54+
3355// Given an array with decimal numbers
3456// When passed to the max function
3557// Then it should return the largest decimal number
3658
59+ it ( "array with decimal numbers should return largest decimal number" , ( ) => {
60+ const list = [ 1.9 , 2.8999 , 3.1 ] ;
61+ expect ( findMax ( list ) ) . toEqual ( 3.1 ) ;
62+ } ) ;
63+
64+
3765// Given an array with non-number values
3866// When passed to the max function
3967// Then it should return the max and ignore non-numeric values
4068
69+ it ( "array with non-number values, returns the max and ignore non-numeric values" , ( ) => {
70+ const list = [ 1 , "a" , 2 , "b" , 3 , "c" ] ;
71+ expect ( findMax ( list ) ) . toEqual ( 3 ) ;
72+ } ) ;
73+
74+
4175// Given an array with only non-number values
4276// When passed to the max function
4377// Then it should return the least surprising value given how it behaves for all other inputs
78+
79+ it ( "array with only non-number values, return the least surprising value given how it behaves for all other inputs" , ( ) => {
80+ const list = [ "a" , "b" , "c" ] ;
81+ expect ( findMax ( list ) ) . toEqual ( "-Infinity" ) ;
82+ } ) ;
83+ } ) ;
0 commit comments