@@ -10,27 +10,56 @@ const sum = require("./sum.js");
1010
1111// Acceptance Criteria:
1212
13+ describe ( "sum" , ( ) => {
1314// Given an empty array
1415// When passed to the sum function
1516// Then it should return 0
16- test . todo ( "given an empty array, returns 0" )
17+ it ( "empty array returns 0" , ( ) => {
18+ const list = [ ] ;
19+ expect ( sum ( list ) ) . toEqual ( 0 ) ;
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+ it ( "array with one number returns number" , ( ) => {
26+ const list = [ 1 ] ;
27+ expect ( sum ( list ) ) . toEqual ( 1 ) ;
28+ } ) ;
2129
2230// Given an array containing negative numbers
2331// When passed to the sum function
2432// Then it should still return the correct total sum
2533
34+ it ( "array with negative numbers returns correct sum" , ( ) => {
35+ const list = [ - 1 , - 2 , - 3 ] ;
36+ expect ( sum ( list ) ) . toEqual ( - 6 ) ;
37+ } ) ;
38+
2639// Given an array with decimal/float numbers
2740// When passed to the sum function
2841// Then it should return the correct total sum
2942
43+ it ( "array with decimal numbers returns correct sum" , ( ) => {
44+ const list = [ 1.1 , 2.2 , 3.3 ] ;
45+ expect ( sum ( list ) ) . toEqual ( 6.6 ) ;
46+ } ) ;
47+
3048// Given an array containing non-number values
3149// When passed to the sum function
3250// Then it should ignore the non-numerical values and return the sum of the numerical elements
3351
52+ it ( "array with non-number values returns sum of numerical values only" , ( ) => {
53+ const list = [ 1 ] ;
54+ expect ( sum ( list ) ) . toEqual ( 1 ) ;
55+ } ) ;
56+
3457// Given an array with only non-number values
3558// When passed to the sum function
3659// Then it should return the least surprising value given how it behaves for all other inputs
60+
61+ it ( "array with non-number values only returns least surprising output" , ( ) => {
62+ const list = [ 1 ] ;
63+ expect ( sum ( list ) ) . toEqual ( 0 ) ;
64+ } ) ;
65+ } ) ;
0 commit comments