File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ const sum = require("./sum.js");
1313// Given an empty array
1414// When passed to the sum function
1515// Then it should return 0
16- test . todo ( "given an empty array, returns 0" )
1716
1817// Given an array with just one number
1918// When passed to the sum function
@@ -34,3 +33,11 @@ test.todo("given an empty array, returns 0")
3433// Given an array with only non-number values
3534// When passed to the sum function
3635// Then it should return the least surprising value given how it behaves for all other inputs
36+
37+ test ( `Should return the correct sum of the numerical elements of an array` , ( ) => {
38+ expect ( sum ( [ "apple" , "banana" , 1 , 10 ] ) ) . toEqual ( 11 ) ;
39+ expect ( sum ( [ 1 , - 1 , - 100 ] ) ) . toEqual ( - 100 ) ;
40+ expect ( sum ( [ - 10 , - 20 , - 3 , - 4 ] ) ) . toEqual ( - 37 ) ;
41+ expect ( sum ( [ 1.5 , 10.5 , 0.5 ] ) ) . toBeCloseTo ( 12.5 ) ;
42+ expect ( sum ( [ "apple" , "banana" , "cherry" ] ) ) . toEqual ( - Infinity ) ;
43+ } ) ;
You can’t perform that action at this time.
0 commit comments