@@ -13,24 +13,48 @@ 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 just one number, should return that number" , ( ) => {
24+ expect ( sum ( [ 1 ] ) ) . toEqual ( 1 ) ;
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 containing negative numbers,should return the correct total sum" , ( ) => {
31+ expect ( sum ( [ - 2 , - 4 , - 1 ] ) ) . toEqual ( - 7 ) ;
32+ } ) ;
2533
2634// Given an array with decimal/float numbers
2735// When passed to the sum function
2836// Then it should return the correct total sum
37+ test ( "given an array wit decimal numbers, should return correct total sum" , ( ) => {
38+ expect ( sum ( [ 3.1 , 2.1 , 8.8 ] ) ) . toEqual ( 14 ) ;
39+ } ) ;
2940
3041// Given an array containing a value that isn't a number
3142// When passed to the sum function
3243// Then it should throw Error("sum requires an array of numbers")
44+ test ( "given an array containing a value that is not a number, should throw Error(sum requires an array of numbers)" , ( ) => {
45+ expect ( ( ) => sum ( [ NaN , 21 ] ) ) . toThrow ( "sum requires an array of numbers" ) ;
46+ } ) ;
3347
3448// Given something that isn't an array at all, such as "hey", 42 or no argument
3549// When passed to the sum function
3650// Then it should throw Error("sum requires an array of numbers")
51+ test ( "given something that isn't an array at all, should throw Error(sum requires an array of numbers)" , ( ) => {
52+ expect ( ( ) => sum ( 21 ) ) . toThrow ( "sum requires an array of numbers" ) ;
53+ } ) ;
54+
55+ test ( "given something that isn't an array at all, should throw Error(sum requires an array of numbers)" , ( ) => {
56+ expect ( ( ) => sum ( "hello" ) ) . toThrow ( "sum requires an array of numbers" ) ;
57+ } ) ;
58+ test ( "given something that isn't an array at all, should throw Error(sum requires an array of numbers)" , ( ) => {
59+ expect ( ( ) => sum ( ) ) . toThrow ( "sum requires an array of numbers" ) ;
60+ } ) ;
0 commit comments