@@ -13,24 +13,57 @@ 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+ it ( "returns for []" , ( ) => {
18+ expect ( sum ( [ ] ) ) . toEqual ( 0 ) ;
19+ } ) ;
20+ // Given an array with just one number
21+ // When passed to the sum function
22+ // Then it should return that number
23+ it ( "returns for [8]" , ( ) => {
24+ expect ( sum ( [ 8 ] ) ) . toEqual ( 8 ) ;
25+ } ) ;
26+ // Given an array containing negative numbers
27+ // When passed to the sum function
28+ // Then it should still return the correct total sum
29+ it ( "returns for [8, -5, 10]" , ( ) => {
30+ expect ( sum ( [ 8 , - 5 , 10 ] ) ) . toEqual ( 13 ) ;
31+ } ) ;
1732
18- // Given an array with just one number
19- // When passed to the sum function
20- // Then it should return that number
33+ // Given an array with decimal/float numbers
34+ // When passed to the sum function
35+ // Then it should return the correct total sum
36+ it ( "returns for [10, 3.75, 2.25]" , ( ) => {
37+ expect ( sum ( [ 10 , 3.75 , 2.25 ] ) ) . toEqual ( 16 ) ;
38+ } ) ;
39+ // Given an array containing a value that isn't a number
40+ // When passed to the sum function
41+ // Then it should throw Error("sum requires an array of numbers")
2142
22- // Given an array containing negative numbers
23- // When passed to the sum function
24- // Then it should still return the correct total sum
43+ it ( "returns for [10, 20, '30']" , ( ) => {
44+ ( ) =>
45+ expect (
46+ sum ( [ 10 , 20 , "30" ] ) . toThrow (
47+ new Error ( "sum requires an array of numbers" )
48+ )
49+ ) ;
50+ } ) ;
2551
26- // Given an array with decimal/float numbers
27- // When passed to the sum function
28- // Then it should return the correct total sum
52+ // Given something that isn't an array at all, such as "hey", 42 or no argument
53+ // When passed to the sum function
54+ // Then it should throw Error("sum requires an array of numbers")
55+ it ( "returns for 'hey'" , ( ) => {
56+ ( ) =>
57+ expect ( sum ( "hey" ) ) . toThrow ( new Error ( "sum requires an array of numbers" ) ) ;
58+ } ) ;
2959
30- // Given an array containing a value that isn't a number
31- // When passed to the sum function
32- // Then it should throw Error("sum requires an array of numbers")
60+ it ( "returns for (42)" , ( ) => {
61+ ( ) =>
62+ expect ( sum ( 42 ) ) . toThrow ( new Error ( "sum requires an array of numbers" ) ) ;
63+ } ) ;
3364
34- // Given something that isn't an array at all, such as "hey", 42 or no argument
35- // When passed to the sum function
36- // Then it should throw Error("sum requires an array of numbers")
65+ it ( "returns for ('')" , ( ) => {
66+ ( ) =>
67+ expect ( sum ( "" ) ) . toThrow ( new Error ( "sum requires an array of numbers" ) ) ;
68+ } ) ;
69+ } ) ;
0 commit comments