-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathTrackStateProcessor.spec.ts
More file actions
73 lines (66 loc) · 2.27 KB
/
Copy pathTrackStateProcessor.spec.ts
File metadata and controls
73 lines (66 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, expect, it } from 'vitest';
import type { Telemetry } from '@irdashies/types';
import { TrackStateProcessor } from './TrackStateProcessor';
const frame = (values: Record<string, unknown[]>): Telemetry =>
Object.fromEntries(
Object.entries(values).map(([key, current]) => [key, { value: current }])
) as unknown as Telemetry;
describe('TrackStateProcessor', () => {
it('projects positional, pit, and warning state', () => {
const processor = new TrackStateProcessor();
processor.onFrame(
frame({
CamCarIdx: [2],
CarIdxLapDistPct: [0.1004, 0.2005, 0.30049],
CarIdxOnPitRoad: [0, 1, 0],
CarIdxTrackSurface: [3, 2, 3],
CarIdxClassPosition: [1, 2, 3],
CarLeftRight: [2],
IsOnTrack: [true],
OnPitRoad: [true],
Speed: [41.5],
EngineWarnings: [16],
SessionNum: [1],
})
);
expect(processor.snapshot()).toMatchObject({
focusCarIdx: 2,
carIdxLapDistPct: [0.1, 0.201, 0.3],
carIdxOnPitRoad: [false, true, false],
carIdxTrackSurface: [3, 2, 3],
carIdxClassPosition: [1, 2, 3],
carLeftRight: 2,
isOnTrack: true,
onPitRoad: true,
speed: 41.5,
engineWarnings: 16,
sessionNum: 1,
version: 1,
});
});
it('reuses buffers, publishes only changes, and resets on disconnect', () => {
const processor = new TrackStateProcessor();
const telemetry = frame({ CarIdxLapDistPct: [0.25], IsOnTrack: [true] });
processor.onFrame(telemetry);
const positions = processor.snapshot().carIdxLapDistPct;
processor.onFrame(telemetry);
expect(processor.snapshot().version).toBe(1);
expect(processor.snapshot().carIdxLapDistPct).toBe(positions);
processor.onLifecycle({ type: 'disconnect' });
expect(processor.snapshot()).toMatchObject({
carIdxLapDistPct: [],
isOnTrack: false,
sessionNum: null,
version: 2,
});
});
it('ignores sub-millipercent position movement', () => {
const processor = new TrackStateProcessor();
processor.onFrame(frame({ CarIdxLapDistPct: [0.12341] }));
processor.onFrame(frame({ CarIdxLapDistPct: [0.12344] }));
expect(processor.snapshot()).toMatchObject({
carIdxLapDistPct: [0.123],
version: 1,
});
});
});