Skip to content

Commit 81373b2

Browse files
committed
Fix & test ASUM
1 parent 3befd34 commit 81373b2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/operations.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ describe('Test parseExpression', () => {
189189
expect(parseExpression('OR(a, b)', { a: false, b: true })).toBe(true);
190190
expect(parseExpression('OR(a, b)', { a: false, b: false })).toBe(false);
191191
});
192+
193+
test('ASUM op', () => {
194+
expect(parseExpression('ASUM(a, b)', { a: [{b: 5}, {b: 10}, {b: 0}, {b: 15}] })).toBe(30);
195+
expect(parseExpression('ASUM(a, MULTIPLY(b, c))', { a: [{b: 5, c: 1}, {b: 10, c: 2}, {b: 1000, c: 0}, {b: 15, c: 10}] })).toBe(175);
196+
});
192197
});
193198

194199
describe('Test parseOp', () => {

src/operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function parseExpression(exp: string, values: Record<string, any>): any {
8989
// aggregated sum
9090
return (
9191
(values[a] as unknown[])?.reduce(
92-
(acc, item) => acc + parseExpression(b, { value: item } as typeof values),
92+
(acc, item) => acc + parseExpression(b, item as typeof values),
9393
0
9494
) ?? 0
9595
);

0 commit comments

Comments
 (0)