Files
Phoenix/scripts/test_phase_wheel.mjs
T

20 lines
925 B
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
const source = fs.readFileSync(new URL('../www/views/phase_wheel.js', import.meta.url), 'utf8');
const context = vm.createContext({ Number, Math });
const smoothingSource = source.match(/export function smoothingAlpha[\s\S]*?\n\}/)?.[0];
assert.ok(smoothingSource, 'time-based smoothing must remain testable');
vm.runInContext(smoothingSource.replace('export function', 'function'), context);
const oneFrame = context.smoothingAlpha(1 / 60, 0.2);
const twoFrames = 1 - Math.pow(1 - oneFrame, 2);
assert.ok(Math.abs(twoFrames - context.smoothingAlpha(1 / 30, 0.2)) < 1e-12,
'smoothing over equal real time must not depend on the display frame rate');
assert.doesNotMatch(source, /auto\.gain \* PHASE_AGC_BASE_GAIN/,
'AGC target gain must not be multiplied a second time');
console.log('phase wheel regression tests passed');