Intelligence, Advanced Charting & Trading Platform

1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { analyzeObservationSeries } from '../src/data-proof.mjs';
4
5 test('measures cadence, max gap and duplicate timestamps', () => {
6 const result = analyzeObservationSeries([
7 { timestamp: '2026-10-05T12:00:00Z', price: 100 },
8 { timestamp: '2026-10-05T12:01:00Z', price: 101 },
9 { timestamp: '2026-10-05T12:01:00Z', price: 101 },
10 { timestamp: '2026-10-05T12:03:00Z', price: 102 },
11 ]);
12
13 assert.equal(result.count, 4);
14 assert.equal(result.uniqueTimestampCount, 3);
15 assert.equal(result.duplicateTimestampCount, 1);
16 assert.equal(result.maxGapMs, 120_000);
17 assert.equal(result.medianCadenceMs, 90_000);
18 });
19
20 test('reports out-of-order input without silently reclassifying it as clean', () => {
21 const result = analyzeObservationSeries([
22 { timestamp: '2026-10-05T12:02:00Z', price: 100 },
23 { timestamp: '2026-10-05T12:01:00Z', price: 101 },
24 { timestamp: '2026-10-05T12:03:00Z', price: 102 },
25 ]);
26 assert.equal(result.outOfOrderCount, 1);
27 });
28
29 test('rejects invalid timestamps and prices', () => {
30 assert.throws(() => analyzeObservationSeries([
31 { timestamp: 'bad', price: 100 },
32 ]), /timestamp/i);
33
34 assert.throws(() => analyzeObservationSeries([
35 { timestamp: '2026-10-05T12:00:00Z', price: 0 },
36 ]), /price/i);
37 });
38
39 test('returns null cadence metrics when fewer than two unique timestamps exist', () => {
40 const result = analyzeObservationSeries([
41 { timestamp: '2026-10-05T12:00:00Z', price: 100 },
42 ]);
43 assert.equal(result.maxGapMs, null);
44 assert.equal(result.medianCadenceMs, null);
45 });