@@ -13,24 +13,44 @@ 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+ describe ( "sum" , ( ) => {
17+ test ( "given an empty array, returns 0" , ( ) => {
18+ expect ( sum ( [ ] ) ) . toBe ( 0 ) ;
19+ } ) ;
20+
1721
1822// Given an array with just one number
1923// When passed to the sum function
2024// Then it should return that number
25+ test ( "given an array with just one number, returns that number" , ( ) => {
26+ expect ( sum ( [ 4 ] ) ) . toBe ( 4 ) ;
27+ } ) ;
2128
2229// Given an array containing negative numbers
2330// When passed to the sum function
2431// Then it should still return the correct total sum
32+ test ( "given an array containing negative numbers, returns the correct total sum" , ( ) => {
33+ expect ( sum ( [ 10 , - 5 , - 15 ] ) ) . toBe ( - 10 ) ;
34+ } ) ;
2535
2636// Given an array with decimal/float numbers
2737// When passed to the sum function
2838// Then it should return the correct total sum
39+ test ( "given an array with decimal/float numbers, returns the correct total sum" , ( ) => {
40+ expect ( sum ( [ 1.5 , 2.5 , 3 ] ) ) . toBe ( 7 ) ;
41+ } ) ;
2942
3043// Given an array containing non-number values
3144// When passed to the sum function
3245// Then it should ignore the non-numerical values and return the sum of the numerical elements
46+ test ( "given an array containing non-number values, ignores them and returns the sum of the numerical elements" , ( ) => {
47+ expect ( sum ( [ 10 , "hi" , 20 , null , 5 ] ) ) . toBe ( 35 ) ;
48+ } ) ;
3349
3450// Given an array with only non-number values
3551// When passed to the sum function
3652// Then it should return the least surprising value given how it behaves for all other inputs
53+ test ( "given an array with only non-number values, returns 0" , ( ) => {
54+ expect ( sum ( [ "a" , "b" , null , undefined ] ) ) . toBe ( 0 ) ;
55+ } ) ;
56+ } ) ;
0 commit comments