Skip to content

Commit 357426d

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
tests added for sum.test.js in implement
1 parent 0d3fb03 commit 357426d

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

Sprint-1/implement/sum.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
function sum(elements) {
1+
function sum(list) {
2+
return 0
23
}
34

45
module.exports = sum;

Sprint-1/implement/sum.test.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)