84 lines
2.8 KiB
JavaScript
84 lines
2.8 KiB
JavaScript
|
|
const test = require('node:test');
|
||
|
|
const assert = require('node:assert/strict');
|
||
|
|
|
||
|
|
const { showWorkingCurves, showCoG } = require('../../src/display/workingCurves');
|
||
|
|
|
||
|
|
function makePredictors(overrides = {}) {
|
||
|
|
return {
|
||
|
|
hasCurve: true,
|
||
|
|
cog: 0.65,
|
||
|
|
cogIndex: 7,
|
||
|
|
NCog: 0.5,
|
||
|
|
minEfficiency: 0.4,
|
||
|
|
currentEfficiencyCurve: { x: [0, 1], y: [0.4, 0.8] },
|
||
|
|
absDistFromPeak: 0.15,
|
||
|
|
relDistFromPeak: 0.3,
|
||
|
|
calcCog: () => ({ cog: 0.65, cogIndex: 7, NCog: 0.5, minEfficiency: 0.4 }),
|
||
|
|
getCurrentCurves: () => ({
|
||
|
|
powerCurve: { x: [0, 1], y: [10, 20] },
|
||
|
|
flowCurve: { x: [0, 1], y: [0, 5] },
|
||
|
|
}),
|
||
|
|
...overrides,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
test('showWorkingCurves returns the expected shape when curves exist', () => {
|
||
|
|
const p = makePredictors();
|
||
|
|
const out = showWorkingCurves(p);
|
||
|
|
assert.deepEqual(out.powerCurve, { x: [0, 1], y: [10, 20] });
|
||
|
|
assert.deepEqual(out.flowCurve, { x: [0, 1], y: [0, 5] });
|
||
|
|
assert.equal(out.cog, 0.65);
|
||
|
|
assert.equal(out.cogIndex, 7);
|
||
|
|
assert.equal(out.NCog, 0.5);
|
||
|
|
assert.equal(out.minEfficiency, 0.4);
|
||
|
|
assert.deepEqual(out.currentEfficiencyCurve, { x: [0, 1], y: [0.4, 0.8] });
|
||
|
|
assert.equal(out.absDistFromPeak, 0.15);
|
||
|
|
assert.equal(out.relDistFromPeak, 0.3);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('showWorkingCurves returns error envelope when hasCurve is false', () => {
|
||
|
|
const out = showWorkingCurves(makePredictors({ hasCurve: false }));
|
||
|
|
assert.deepEqual(out, { error: 'No curve data available' });
|
||
|
|
});
|
||
|
|
|
||
|
|
test('showWorkingCurves handles null predictors safely', () => {
|
||
|
|
const out = showWorkingCurves(null);
|
||
|
|
assert.equal(out.error, 'No curve data available');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('showCoG returns CoG data with rounded NCogPercent when curves exist', () => {
|
||
|
|
const p = makePredictors();
|
||
|
|
const out = showCoG(p);
|
||
|
|
assert.equal(out.cog, 0.65);
|
||
|
|
assert.equal(out.cogIndex, 7);
|
||
|
|
assert.equal(out.NCog, 0.5);
|
||
|
|
// 0.5 * 100 = 50.0, rounded *100 /100 still 50
|
||
|
|
assert.equal(out.NCogPercent, 50);
|
||
|
|
assert.equal(out.minEfficiency, 0.4);
|
||
|
|
assert.deepEqual(out.currentEfficiencyCurve, { x: [0, 1], y: [0.4, 0.8] });
|
||
|
|
assert.equal(out.absDistFromPeak, 0.15);
|
||
|
|
assert.equal(out.relDistFromPeak, 0.3);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('showCoG rounds NCogPercent to 2 decimal places', () => {
|
||
|
|
const p = makePredictors({
|
||
|
|
calcCog: () => ({ cog: 0.1, cogIndex: 1, NCog: 0.123456, minEfficiency: 0.2 }),
|
||
|
|
});
|
||
|
|
const out = showCoG(p);
|
||
|
|
assert.equal(out.NCogPercent, 12.35);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('showCoG returns degraded shape when hasCurve is false', () => {
|
||
|
|
const out = showCoG(makePredictors({ hasCurve: false }));
|
||
|
|
assert.equal(out.error, 'No curve data available');
|
||
|
|
assert.equal(out.cog, 0);
|
||
|
|
assert.equal(out.NCog, 0);
|
||
|
|
assert.equal(out.cogIndex, 0);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('showCoG handles null predictors safely', () => {
|
||
|
|
const out = showCoG(null);
|
||
|
|
assert.equal(out.error, 'No curve data available');
|
||
|
|
assert.equal(out.cog, 0);
|
||
|
|
});
|