Skip to content

Commit 436abd9

Browse files
committed
Refactor sum tests to implement test case for empty array and remove todo
1 parent c01c0bc commit 436abd9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Sprint-1/implement/sum.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ 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")
1716

1817
// Given an array with just one number
1918
// When passed to the sum function
@@ -34,3 +33,11 @@ test.todo("given an empty array, returns 0")
3433
// Given an array with only non-number values
3534
// When passed to the sum function
3635
// Then it should return the least surprising value given how it behaves for all other inputs
36+
37+
test(`Should return the correct sum of the numerical elements of an array`, () => {
38+
expect(sum(["apple", "banana", 1, 10])).toEqual(11);
39+
expect(sum([1, -1, -100])).toEqual(-100);
40+
expect(sum([-10, -20, -3, -4])).toEqual(-37);
41+
expect(sum([1.5, 10.5, 0.5])).toBeCloseTo(12.5);
42+
expect(sum(["apple", "banana", "cherry"])).toEqual(-Infinity);
43+
});

0 commit comments

Comments
 (0)