@@ -13,24 +13,42 @@ 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" )
16+ test ( "given an empty array, returns 0" , ( ) => {
17+ expect ( sum ( [ ] ) ) . toEqual ( 0 ) ;
18+ } ) ;
19+
1720
1821// Given an array with just one number
1922// When passed to the sum function
2023// Then it should return that number
24+ test ( "given an array with one number, returns the same number" , ( ) => {
25+ expect ( sum ( [ 7 ] ) ) . toEqual ( 7 ) ;
26+ } ) ;
2127
2228// Given an array containing negative numbers
2329// When passed to the sum function
2430// Then it should still return the correct total sum
31+ test ( "given an array containing negative numbers, returns the total sum" , ( ) => {
32+ expect ( sum ( [ - 4 , - 15 , - 12 ] ) ) . toEqual ( - 31 ) ;
33+ } ) ;
2534
2635// Given an array with decimal/float numbers
2736// When passed to the sum function
2837// Then it should return the correct total sum
38+ test ( "given an array with decimal/float numbers, returns the correct sum" , ( ) => {
39+ expect ( sum ( [ 4.1 , 5.4 , 7.8 ] ) ) . toEqual ( 17.3 ) ;
40+ } ) ;
2941
3042// Given an array containing non-number values
3143// When passed to the sum function
3244// Then it should ignore the non-numerical values and return the sum of the numerical elements
45+ test ( "given an array with non-number values, ignores the non-number values and returns the correct sum" , ( ) => {
46+ expect ( sum ( [ 'fish' , 4 , 'dog' , 5 , , 'pizza' , 10 ] ) ) . toEqual ( 19 ) ;
47+ } ) ;
3348
3449// Given an array with only non-number values
3550// When passed to the sum function
3651// Then it should return the least surprising value given how it behaves for all other inputs
52+ test ( "given an array of only non-numeric values, returns 0" , ( ) => {
53+ expect ( sum ( [ 'fish' , 'dog' , 'pizza' ] ) ) . toEqual ( 0 ) ;
54+ } ) ;
0 commit comments