@@ -13,24 +13,55 @@ 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+ const inputNumber = [ ] ;
18+ const result = sum ( inputNumber ) ;
19+ expect ( result ) . 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
2125
26+ test ( "given an array with 1 number, it returns the sam number" , ( ) => {
27+ const inputNumber = [ 34 ] ;
28+ const result = sum ( inputNumber ) ;
29+ expect ( result ) . toEqual ( 34 ) ;
30+ } ) ;
31+
2232// Given an array containing negative numbers
2333// When passed to the sum function
2434// Then it should still return the correct total sum
2535
36+ test ( "given an array containing negative numbers" , ( ) => {
37+ const inputNegative = [ 10 , - 5 , 20 , - 15 ] ;
38+ const result = sum ( inputNegative )
39+ expect ( result ) . toEqual ( 10 ) ;
40+ } ) ;
41+
2642// Given an array with decimal/float numbers
2743// When passed to the sum function
2844// Then it should return the correct total sum
45+ test ( "Given an array with decimal/float numbers" , ( ) => {
46+ const inputFloat = [ 10.2 , 10.3 ] ;
47+ const result = sum ( inputFloat ) ;
48+ expect ( result ) . toEqual ( 20.5 ) ;
49+ } ) ;
2950
3051// Given an array containing non-number values
3152// When passed to the sum function
3253// Then it should ignore the non-numerical values and return the sum of the numerical elements
54+ test ( "Given an array containing non-number values" , ( ) => {
55+ const inputNonNumbers = [ 1 , "apple" , 2 , true , 3 ] ;
56+ const result = sum ( inputNonNumbers ) ;
57+ expect ( result ) . toEqual ( 6 )
58+ } ) ;
3359
3460// Given an array with only non-number values
3561// When passed to the sum function
3662// Then it should return the least surprising value given how it behaves for all other inputs
63+ test ( "Given an array with only non-number values" , ( ) => {
64+ const nonNumbers = [ "helo" , "hi" ] ;
65+ const result = sum ( nonNumbers ) ;
66+ expect ( result ) . toEqual ( 0 )
67+ } ) ;
0 commit comments