Skip to content

Commit

Permalink
fix large part of aggeragtor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jitsedesmet committed Apr 5, 2024
1 parent 7a9392f commit 7938868
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createFuncMediator } from '@comunica/actor-functions-wrapper-all/test/util';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext, Bus } from '@comunica/core';
import { ExpressionEvaluatorFactory } from '@comunica/expression-evaluator';
import { BF, DF, makeAggregate } from '@comunica/jest';
import type { IExpressionEvaluatorFactory } from '@comunica/types';
import { BF, DF, getMockEEFactory, makeAggregate } from '@comunica/jest';
import { ArrayIterator } from 'asynciterator';
import { ActorBindingsAggregatorFactoryAverage } from '../lib';

describe('ActorBindingsAggregatorFactoryAverage', () => {
let bus: any;
let expressionEvaluatorFactory: IExpressionEvaluatorFactory;
let expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;

beforeEach(() => {
bus = new Bus({ name: 'bus' });
Expand All @@ -25,39 +25,41 @@ describe('ActorBindingsAggregatorFactoryAverage', () => {
}),
};

expressionEvaluatorFactory = new ExpressionEvaluatorFactory({
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
mediatorFunctions: createFuncMediator(),
});
});

describe('An ActorBindingsAggregatorFactoryCount instance', () => {
let actor: ActorBindingsAggregatorFactoryAverage;

beforeEach(() => {
actor = new ActorBindingsAggregatorFactoryAverage({ name: 'actor', bus });
actor = new ActorBindingsAggregatorFactoryAverage({
name: 'actor',
bus,
factory: expressionEvaluatorFactory,
});
});

describe('test', () => {
it('accepts average 1', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('avg', false),
})).resolves.toEqual({});
});

it('accepts average 2', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('avg', true),
})).resolves.toEqual({});
});

it('rejects sum', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('sum', false),
})).rejects.toThrow();
Expand All @@ -66,7 +68,6 @@ describe('ActorBindingsAggregatorFactoryAverage', () => {

it('should run', () => {
return expect(actor.run({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('avg', false),
})).resolves.toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { createFuncMediator } from '@comunica/actor-functions-wrapper-all/test/util';
import type { IBindingsAggregator } from '@comunica/bus-bindings-aggeregator-factory';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext } from '@comunica/core';
import { ExpressionEvaluatorFactory, RegularOperator } from '@comunica/expression-evaluator';
import { BF, decimal, DF, double, float, int, makeAggregate } from '@comunica/jest';
import type { IActionContext, IExpressionEvaluatorFactory } from '@comunica/types';
import { RegularOperator } from '@comunica/expression-evaluator';
import { BF, decimal, DF, double, float, getMockEEFactory, int, makeAggregate } from '@comunica/jest';
import type { IActionContext } from '@comunica/types';
import type * as RDF from '@rdfjs/types';
import { ArrayIterator } from 'asynciterator';
import { AverageAggregator } from '../lib/AverageAggregator';
Expand All @@ -15,12 +17,15 @@ async function runAggregator(aggregator: IBindingsAggregator, input: RDF.Binding
}

async function createAggregator({ expressionEvaluatorFactory, context, distinct }: {
expressionEvaluatorFactory: IExpressionEvaluatorFactory;
expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;
context: IActionContext;
distinct: boolean;
}): Promise<AverageAggregator> {
return new AverageAggregator(
await expressionEvaluatorFactory.createEvaluator(makeAggregate('avg', distinct).expression, context),
(await expressionEvaluatorFactory.run({
algExpr: makeAggregate('avg', distinct).expression,
context,
})).expressionEvaluator,
distinct,
await expressionEvaluatorFactory.createFunction({
context,
Expand All @@ -36,7 +41,7 @@ async function createAggregator({ expressionEvaluatorFactory, context, distinct
}

describe('AverageAggregator', () => {
let expressionEvaluatorFactory: IExpressionEvaluatorFactory;
let expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;
let context: IActionContext;

beforeEach(() => {
Expand All @@ -53,9 +58,10 @@ describe('AverageAggregator', () => {
}),
};

expressionEvaluatorFactory = new ExpressionEvaluatorFactory({
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
mediatorFunctions: createFuncMediator(),
});

context = new ActionContext();
Expand Down Expand Up @@ -139,3 +145,4 @@ describe('AverageAggregator', () => {
});
});
});

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext, Bus } from '@comunica/core';
import { ExpressionEvaluatorFactory } from '@comunica/expression-evaluator';
import { makeAggregate } from '@comunica/jest';
import type { IExpressionEvaluatorFactory } from '@comunica/types';
import { getMockEEFactory, makeAggregate } from '@comunica/jest';
import { Algebra } from 'sparqlalgebrajs';
import { Wildcard } from 'sparqljs';
import { ActorBindingsAggregatorFactoryCount } from '../lib';

describe('ActorExpressionEvaluatorAggregateCount', () => {
let bus: any;
let expressionEvaluatorFactory: IExpressionEvaluatorFactory;
let expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;

beforeEach(() => {
bus = new Bus({ name: 'bus' });
Expand All @@ -17,7 +16,7 @@ describe('ActorExpressionEvaluatorAggregateCount', () => {
async mediate(arg: any) { return {}; },
};

expressionEvaluatorFactory = new ExpressionEvaluatorFactory({
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
});
Expand All @@ -27,29 +26,30 @@ describe('ActorExpressionEvaluatorAggregateCount', () => {
let actor: ActorBindingsAggregatorFactoryCount;

beforeEach(() => {
actor = new ActorBindingsAggregatorFactoryCount({ name: 'actor', bus });
actor = new ActorBindingsAggregatorFactoryCount({
name: 'actor',
bus,
factory: expressionEvaluatorFactory,
});
});

describe('test', () => {
it('accepts count 1', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('count', false),
})).resolves.toEqual({});
});

it('accepts count 2', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('count', true),
})).resolves.toEqual({});
});

it('rejects wildcard', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: {
type: Algebra.types.EXPRESSION,
Expand All @@ -68,7 +68,6 @@ describe('ActorExpressionEvaluatorAggregateCount', () => {

it('rejects sum', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('sum', false),
})).rejects.toThrow();
Expand All @@ -77,7 +76,6 @@ describe('ActorExpressionEvaluatorAggregateCount', () => {

it('should run', () => {
return expect(actor.run({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('count', false),
})).resolves.toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IBindingsAggregator } from '@comunica/bus-bindings-aggeregator-factory';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext } from '@comunica/core';
import { ExpressionEvaluatorFactory } from '@comunica/expression-evaluator';
import { BF, DF, int, makeAggregate } from '@comunica/jest';
import type { IActionContext, IExpressionEvaluatorFactory } from '@comunica/types';
import { BF, DF, getMockEEFactory, int, makeAggregate } from '@comunica/jest';
import type { IActionContext } from '@comunica/types';
import type * as RDF from '@rdfjs/types';
import { ArrayIterator } from 'asynciterator';
import { CountAggregator } from '../lib';
Expand All @@ -15,18 +15,21 @@ async function runAggregator(aggregator: IBindingsAggregator, input: RDF.Binding
}

async function createAggregator({ expressionEvaluatorFactory, context, distinct }: {
expressionEvaluatorFactory: IExpressionEvaluatorFactory;
expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;
context: IActionContext;
distinct: boolean;
}): Promise<CountAggregator> {
return new CountAggregator(
await expressionEvaluatorFactory.createEvaluator(makeAggregate('count', distinct).expression, context),
(await expressionEvaluatorFactory.run({
algExpr: makeAggregate('count', distinct).expression,
context,
})).expressionEvaluator,
distinct,
);
}

describe('CountAggregator', () => {
let expressionEvaluatorFactory: IExpressionEvaluatorFactory;
let expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;
let context: IActionContext;

beforeEach(() => {
Expand All @@ -43,7 +46,7 @@ describe('CountAggregator', () => {
}),
};

expressionEvaluatorFactory = new ExpressionEvaluatorFactory({
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext, Bus } from '@comunica/core';
import { ExpressionEvaluatorFactory } from '@comunica/expression-evaluator';
import { BF, DF, makeAggregate } from '@comunica/jest';
import type { IExpressionEvaluatorFactory } from '@comunica/types';
import { BF, DF, getMockEEFactory, makeAggregate } from '@comunica/jest';
import { ArrayIterator } from 'asynciterator';
import { ActorBindingsAggregatorFactoryGroupConcat } from '../lib';

describe('ActorBindingsAggregatorFactoryGroupConcat', () => {
let bus: any;
let expressionEvaluatorFactory: IExpressionEvaluatorFactory;
let expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;

beforeEach(() => {
bus = new Bus({ name: 'bus' });
Expand All @@ -25,7 +24,7 @@ describe('ActorBindingsAggregatorFactoryGroupConcat', () => {
}),
};

expressionEvaluatorFactory = new ExpressionEvaluatorFactory({
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
});
Expand All @@ -35,29 +34,30 @@ describe('ActorBindingsAggregatorFactoryGroupConcat', () => {
let actor: ActorBindingsAggregatorFactoryGroupConcat;

beforeEach(() => {
actor = new ActorBindingsAggregatorFactoryGroupConcat({ name: 'actor', bus });
actor = new ActorBindingsAggregatorFactoryGroupConcat({
name: 'actor',
bus,
factory: expressionEvaluatorFactory,
});
});

describe('test', () => {
it('accepts group_concat 1', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('group_concat', false),
})).resolves.toEqual({});
});

it('accepts group_concat 2', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('group_concat', true),
})).resolves.toEqual({});
});

it('rejects sum', () => {
return expect(actor.test({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('sum', false),
})).rejects.toThrow();
Expand All @@ -66,7 +66,6 @@ describe('ActorBindingsAggregatorFactoryGroupConcat', () => {

it('should run', () => {
return expect(actor.run({
factory: expressionEvaluatorFactory,
context: new ActionContext(),
expr: makeAggregate('group_concat', false),
})).resolves.toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IBindingsAggregator } from '@comunica/bus-bindings-aggeregator-factory';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext } from '@comunica/core';
import { ExpressionEvaluatorFactory } from '@comunica/expression-evaluator';
import { BF, DF, int, makeAggregate } from '@comunica/jest';
import type { IActionContext, IExpressionEvaluatorFactory } from '@comunica/types';
import { BF, DF, getMockEEFactory, int, makeAggregate } from '@comunica/jest';
import type { IActionContext } from '@comunica/types';
import type * as RDF from '@rdfjs/types';
import { ArrayIterator } from 'asynciterator';
import { GroupConcatAggregator } from '../lib/GroupConcatAggregator';
Expand All @@ -15,21 +15,22 @@ async function runAggregator(aggregator: IBindingsAggregator, input: RDF.Binding
}

async function createAggregator({ expressionEvaluatorFactory, context, distinct, separator }: {
expressionEvaluatorFactory: IExpressionEvaluatorFactory;
expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;
context: IActionContext;
distinct: boolean;
separator?: string;
}): Promise<GroupConcatAggregator> {
return new GroupConcatAggregator(
await expressionEvaluatorFactory.createEvaluator(
makeAggregate('group_concat', distinct, separator).expression, context,
),
(await expressionEvaluatorFactory.run({
algExpr: makeAggregate('group_concat', distinct, separator).expression,
context,
})).expressionEvaluator,
distinct,
separator,
);
}
describe('CountAggregator', () => {
let expressionEvaluatorFactory: IExpressionEvaluatorFactory;
let expressionEvaluatorFactory: ActorExpressionEvaluatorFactory;
let context: IActionContext;

beforeEach(() => {
Expand All @@ -46,7 +47,7 @@ describe('CountAggregator', () => {
}),
};

expressionEvaluatorFactory = new ExpressionEvaluatorFactory({
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
});
Expand Down
Loading

0 comments on commit 7938868

Please sign in to comment.