@@ -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+ } ) ;
1719
1820// Given an array with just one number
1921// When passed to the sum function
2022// Then it should return that number
23+ test ( "given an array with one number, returns that number" , ( ) => {
24+ expect ( sum ( [ 42 ] ) ) . toEqual ( 42 ) ;
25+ } ) ;
2126
2227// Given an array containing negative numbers
2328// When passed to the sum function
2429// Then it should still return the correct total sum
30+ test ( "given an array with negative numbers, returns the correct sum" , ( ) => {
31+ expect ( sum ( [ - 10 , - 20 , - 30 ] ) ) . toEqual ( - 60 ) ;
32+ expect ( sum ( [ - 5 , - 3 , - 2 ] ) ) . toEqual ( - 10 ) ;
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 numbers, returns the correct sum" , ( ) => {
39+ expect ( sum ( [ 1.5 , 2.5 , 3.0 ] ) ) . toEqual ( 7 ) ;
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-numeric values, ignores them and returns the sum" , ( ) => {
46+ expect ( sum ( [ "hey" , 10 , "hi" , 60 , 10 ] ) ) . toEqual ( 80 ) ;
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 with only non-numeric values, returns 0" , ( ) => {
53+ expect ( sum ( [ "hey" , "hi" , null , undefined ] ) ) . toEqual ( 0 ) ;
54+ } ) ;
0 commit comments