Skip to content

Commit

Permalink
test: add test for mixed amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ivelazco committed Jun 17, 2020
1 parent 55f27f3 commit 4f78f8b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/sum-prop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 4f78f8b

Please sign in to comment.