feat: introduce intersection calculation of charts

This commit is contained in:
syuilo
2022-02-09 03:46:58 +09:00
parent eb894c330f
commit 7fcd9435f3
15 changed files with 188 additions and 18 deletions

View File

@ -6,14 +6,17 @@ import { async, initTestDb } from './utils';
import TestChart from '../src/services/chart/charts/test';
import TestGroupedChart from '../src/services/chart/charts/test-grouped';
import TestUniqueChart from '../src/services/chart/charts/test-unique';
import TestIntersectionChart from '../src/services/chart/charts/test-intersection';
import * as _TestChart from '../src/services/chart/charts/entities/test';
import * as _TestGroupedChart from '../src/services/chart/charts/entities/test-grouped';
import * as _TestUniqueChart from '../src/services/chart/charts/entities/test-unique';
import * as _TestIntersectionChart from '../src/services/chart/charts/entities/test-intersection';
describe('Chart', () => {
let testChart: TestChart;
let testGroupedChart: TestGroupedChart;
let testUniqueChart: TestUniqueChart;
let testIntersectionChart: TestIntersectionChart;
let clock: lolex.Clock;
beforeEach(async(async () => {
@ -21,11 +24,13 @@ describe('Chart', () => {
_TestChart.entity.hour, _TestChart.entity.day,
_TestGroupedChart.entity.hour, _TestGroupedChart.entity.day,
_TestUniqueChart.entity.hour, _TestUniqueChart.entity.day,
_TestIntersectionChart.entity.hour, _TestIntersectionChart.entity.day,
]);
testChart = new TestChart();
testGroupedChart = new TestGroupedChart();
testUniqueChart = new TestUniqueChart();
testIntersectionChart = new TestIntersectionChart();
clock = lolex.install({
now: new Date(Date.UTC(2000, 0, 1, 0, 0, 0))
@ -426,6 +431,45 @@ describe('Chart', () => {
foo: [2, 0, 0],
});
}));
describe('Intersection', () => {
it('条件が満たされていない場合はカウントされない', async(async () => {
await testIntersectionChart.addA('alice');
await testIntersectionChart.addA('bob');
await testIntersectionChart.addB('carol');
await testIntersectionChart.save();
const chartHours = await testUniqueChart.getChart('hour', 3, null);
const chartDays = await testUniqueChart.getChart('day', 3, null);
assert.deepStrictEqual(chartHours, {
aAndB: [0, 0, 0],
});
assert.deepStrictEqual(chartDays, {
aAndB: [0, 0, 0],
});
}));
it('条件が満たされている場合にカウントされる', async(async () => {
await testIntersectionChart.addA('alice');
await testIntersectionChart.addA('bob');
await testIntersectionChart.addB('carol');
await testIntersectionChart.addB('alice');
await testIntersectionChart.save();
const chartHours = await testUniqueChart.getChart('hour', 3, null);
const chartDays = await testUniqueChart.getChart('day', 3, null);
assert.deepStrictEqual(chartHours, {
aAndB: [1, 0, 0],
});
assert.deepStrictEqual(chartDays, {
aAndB: [1, 0, 0],
});
}));
});
});
describe('Resync', () => {