mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
2a4b71b3d9
A lock flight chained into one group of more than 30 parts broke the checklist's contract and made every decision about it fail; an entry now names its nearest part and the first others, a portage lists at most 30 obstacles and a checklist at most 100 own entries. Reading along a line takes in the parts of a lock the corridor cut off, so its data basis no longer depends on how the route runs. A line or an area stands at the middle of its extent, so adding a node leaves it in place, and an earlier decision is judged by where the obstacle was, not by the route point of its passage. The cache keeps its readings without their lines, for one data version at a time, and the data version is read without the region boundaries.
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
/**
|
|
* PaddleCheckCache: the readings of the last lines for one version of the
|
|
* obstacle data, kept without their lines, the least recently used one
|
|
* dropped once it holds more than it keeps, and all of them dropped with a
|
|
* new version.
|
|
*/
|
|
import { PaddleCheckCache, type PaddleCheckEvaluation } from '../../../src/nest/tours/tour-paddle-check.cache';
|
|
import type { PaddleCheckLine } from '@trek/shared';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const line = (totalM: number): PaddleCheckLine => ({ points: [], alongM: [], totalM, portages: [], locks: [] });
|
|
|
|
function evaluation(totalM: number): PaddleCheckEvaluation {
|
|
return {
|
|
line: line(totalM),
|
|
candidates: [],
|
|
own: [],
|
|
dataKeys: new Set([`node/${totalM}`]),
|
|
complete: true,
|
|
data: { data: 'covered', data_as_of: null, read_at: null },
|
|
};
|
|
}
|
|
|
|
describe('PaddleCheckCache', () => {
|
|
it('PCC-001: answers what it was given with the line it is asked for, and nothing it was not', () => {
|
|
const cache = new PaddleCheckCache();
|
|
cache.atVersion('v1');
|
|
cache.set('a', evaluation(1));
|
|
const asked = line(7);
|
|
const hit = cache.get('a', asked);
|
|
expect(hit?.line).toBe(asked);
|
|
expect(hit?.dataKeys.has('node/1')).toBe(true);
|
|
expect(cache.get('b', asked)).toBeUndefined();
|
|
cache.set('a', evaluation(2));
|
|
expect(cache.get('a', asked)?.dataKeys.has('node/2')).toBe(true);
|
|
});
|
|
|
|
it('PCC-002: past 64 readings drops the one used longest ago, a reading just read is kept', () => {
|
|
const cache = new PaddleCheckCache();
|
|
cache.atVersion('v1');
|
|
for (let i = 0; i < 64; i++) cache.set(`line-${i}`, evaluation(i));
|
|
expect(cache.get('line-0', line(0))).toBeDefined();
|
|
cache.set('line-64', evaluation(64));
|
|
expect(cache.get('line-0', line(0))).toBeDefined();
|
|
expect(cache.get('line-1', line(1))).toBeUndefined();
|
|
expect(cache.get('line-64', line(64))).toBeDefined();
|
|
});
|
|
|
|
it('PCC-003: a new version of the data drops every reading, the same version keeps them', () => {
|
|
const cache = new PaddleCheckCache();
|
|
cache.atVersion('v1');
|
|
cache.set('a', evaluation(1));
|
|
cache.atVersion('v1');
|
|
expect(cache.get('a', line(1))).toBeDefined();
|
|
cache.atVersion('v2');
|
|
expect(cache.get('a', line(1))).toBeUndefined();
|
|
});
|
|
});
|