Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
AggregateEvaluator test
Browse files Browse the repository at this point in the history
Makes sure to test the two possible paths on empty input
  • Loading branch information
Tpt authored and rubensworks committed May 23, 2022
1 parent 07dd255 commit d04f8a0
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions test/integration/evaluators/AggregateEvaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ type TestCaseArgs = IBaseTestCaseArgs & { input: RDF.Bindings[] };

async function testCase({ expr, input, evalTogether }: TestCaseArgs): Promise<RDF.Term> {
const results: (RDF.Term | undefined)[] = [];

if (input.length === 0) {
results.push(AggregateEvaluator.emptyValue(expr, false));
results.push(AsyncAggregateEvaluator.emptyValue(expr, false));
} else {
// Evaluate both sync and async while awaiting all
const syncEvaluator = new AggregateEvaluator(expr, undefined, false);
const asyncEvaluator = new AsyncAggregateEvaluator(expr, undefined, false);
for (const bindings of input) {
syncEvaluator.put(bindings);
await asyncEvaluator.put(bindings);
}
results.push(syncEvaluator.result());
results.push(asyncEvaluator.result());
// If we can evaluate the aggregator all at once, we will test this to
if (evalTogether) {
const togetherEvaluator = new AsyncAggregateEvaluator(expr, undefined, false);
await Promise.all(input.map(bindings => togetherEvaluator.put(bindings)));
results.push(togetherEvaluator.result());
}
}

// Evaluate both sync and async while awaiting all
const syncEvaluator = new AggregateEvaluator(expr, undefined, false);
const asyncEvaluator = new AsyncAggregateEvaluator(expr, undefined, false);
for (const bindings of input) {
syncEvaluator.put(bindings);
await asyncEvaluator.put(bindings);
}
results.push(syncEvaluator.result());
results.push(asyncEvaluator.result());
// If we can evaluate the aggregator all at once, we will test this to
if (evalTogether) {
const togetherEvaluator = new AsyncAggregateEvaluator(expr, undefined, false);
await Promise.all(input.map(bindings => togetherEvaluator.put(bindings)));
results.push(togetherEvaluator.result());
}

const equalCheck = results.every(((value, index, array) => {
const other = array[(index + 1) % array.length];
return (!other && !value) || (value && value.equals(other));
Expand Down

0 comments on commit d04f8a0

Please sign in to comment.