diff --git a/src/sum-prop.test.js b/src/sum-prop.test.js index 52b6021..64697bd 100644 --- a/src/sum-prop.test.js +++ b/src/sum-prop.test.js @@ -32,16 +32,20 @@ test('should ignore `undefined` elements in the array', () => { expect(sumProp(2, 'amount', [{ amount: 30 }, undefined, { amount: 12 }, undefined])).toBe(42); }); +test('should overflow result to `Infinity` if sum goes above `MAX_SAFE_INTEGER`', () => { + expect(sumProp(1, 'amount', [{ amount: Number.MAX_SAFE_INTEGER }, { amount: 1 }])).toBe(Infinity); +}); + test('should underflow total value to zero if sum is betweem `1e-7` and `-1e-7`', () => { expect(sumProp(2, 'foo', [{ foo: 0.00000000001 }, { foo: 0.00000000002 }])).toBe(0); expect(sumProp(2, 'foo', [{ foo: -0.00000000001 }, { foo: -0.00000000002 }])).toBe(0); }); -test('should return the sum of all negative ', () => { - expect(sumProp(1, 'amount', [{ amount: Number.MAX_SAFE_INTEGER }, { amount: 1 }])).toBe(Infinity); +test('should sum all negative numeric values present at the given property in the array', () => { + expect(sumProp(2, 'amount', [{ amount: -10 }, { amount: -20 }, { amount: -12 }])).toBe(-42); }); -test('should sum all negative numerical values present at the given property in the array', () => { - expect(sumProp(2, 'amount', [{ amount: -10 }, { amount: -20 }, { amount: -12 }])).toBe(-42); +test('should sum all numeric values ( negatives and positives ) present at the given property in the array', () => { + expect(sumProp(2, 'amount', [{ amount: -10 }, { amount: 20 }, { amount: -12 }])).toBe(-2); });