Files
wickra/bindings/node/__tests__/completeness.test.js
T
kingchenc d4b3f9dbd1 feat: add Alt-Chart Bars (Renko, Kagi, Point & Figure) via a BarBuilder trait (#146)
Introduces a BarBuilder trait for price-driven chart constructors that emit a variable number of bars per candle (deliberately not Indicator). Adds Renko (box-size bricks, 2-box reversal), Kagi (reversal-amount segments) and Point & Figure (box-size X/O columns, N-box reversal) in a new Alt-Chart Bars family, with custom Python/Node/WASM bindings, a dedicated fuzz target, tests and docs. Indicator count 292 -> 295.
2026-06-02 21:56:00 +02:00

80 lines
3.1 KiB
JavaScript

// Completeness contract for the Wickra Node bindings: every exported indicator
// class must expose the full streaming + batch + lifecycle interface. This
// catches a new indicator being wired into the binding without the standard
// methods (or an export silently disappearing) without needing a hand-written
// test per indicator.
const test = require('node:test');
const assert = require('node:assert/strict');
const wickra = require('..');
// Bar builders (Renko / Kagi / Point & Figure) implement the `BarBuilder`
// contract, not `Indicator`: they emit a variable number of completed bars per
// candle and have no fixed warmup or ready state. They expose update/batch/reset
// but intentionally not isReady/warmupPeriod, so they are excluded from the
// Indicator completeness contract below (their interface is covered by the
// dedicated bar-builder tests).
const BAR_BUILDERS = new Set(['RenkoBars', 'KagiBars', 'PointAndFigureBars']);
// An "indicator class" is an exported constructor whose prototype carries the
// streaming `update` method. This excludes `version` (a plain function), the bar
// builders, and any non-indicator export.
function indicatorClasses() {
return Object.keys(wickra).filter((name) => {
const value = wickra[name];
return (
typeof value === 'function' &&
value.prototype &&
typeof value.prototype.update === 'function' &&
!BAR_BUILDERS.has(name)
);
});
}
test('the binding exports the full indicator catalogue', () => {
const names = indicatorClasses();
// The published catalogue is 214 indicators. Guard against a regression that
// silently drops exported classes (e.g. a stale or partial native build).
assert.ok(
names.length >= 200,
`expected at least 200 indicator classes, got ${names.length}`,
);
});
test('every exported indicator exposes update / batch / reset / isReady / warmupPeriod', () => {
const required = ['update', 'batch', 'reset', 'isReady', 'warmupPeriod'];
const missing = [];
for (const name of indicatorClasses()) {
const proto = wickra[name].prototype;
for (const method of required) {
if (typeof proto[method] !== 'function') {
missing.push(`${name}.${method}`);
}
}
}
assert.deepEqual(
missing,
[],
`indicator classes missing required methods: ${missing.join(', ')}`,
);
});
test('a freshly constructed indicator reports not-ready with a positive warmup', () => {
// Every indicator that takes no constructor arguments must still satisfy the
// pre-warmup contract. (Indicators with required parameters are exercised by
// the dedicated suites; here we cover the zero-arg ones generically.)
let checked = 0;
for (const name of indicatorClasses()) {
let instance;
try {
instance = new wickra[name]();
} catch {
continue; // needs constructor arguments — covered elsewhere
}
assert.equal(instance.isReady(), false, `${name} should start un-ready`);
assert.ok(instance.warmupPeriod() >= 1, `${name} warmup must be >= 1`);
checked += 1;
}
assert.ok(checked > 0, 'expected at least one zero-arg indicator to check');
});