Skip to content

Commit b70a0a4

Browse files
committed
Add tests for NaN handling and Infinity cases in sum function
1 parent 87afb14 commit b70a0a4

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎Sprint-1/implement/sum.test.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@ test("given an array containing non-number values, return correct sum total and
4949
test("given an array with only non-number values, return the least surprising value", () => {
5050
expect(sum(["the", "world"])).toBe(0);
5151
});
52+
// Given an array containing NaN and valid numbers
53+
// When passed to the sum function
54+
// Then it should ignore NaN and sum the valid numbers
55+
test("given an array containing NaN, ignores NaN and returns the sum of valid numbers", () => {
56+
expect(sum([NaN, 1])).toBe(1);
57+
});
58+
59+
// Given an array with positive and negative Infinity
60+
// When passed to the sum function
61+
// Then it should return NaN (undefined mathematical operation)
62+
test("given an array with Infinity and -Infinity, returns NaN", () => {
63+
expect(sum([Infinity, -Infinity])).toBeNaN();
64+
});

0 commit comments

Comments
 (0)