Files
Phoenix/scripts/test_rta_profile.mjs
T

73 lines
2.6 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
const source = fs.readFileSync(new URL('../www/core/audio.js', import.meta.url), 'utf8');
const functionSource = source.match(/export function buildRtaRuntimeConfig[\s\S]*?\n\}/)?.[0];
assert.ok(functionSource, 'buildRtaRuntimeConfig must remain testable');
const context = vm.createContext({
Number,
getRtwCenters(mode) {
if (mode === '1_12') return new Array(121).fill(0);
if (mode === '1_6') return new Array(61).fill(0);
return new Array(31).fill(0);
},
});
vm.runInContext(functionSource.replace('export function', 'function'), context);
const forced = context.buildRtaRuntimeConfig({
RTA_BAR_LAYOUT: 'rtw',
RTA_ENGINE: 'fft',
RTA_BPO_MODE: '1_12',
RTA_FREQ_RANGE: 'lf',
RTA_IIR_ORDER: 2,
RTA_DETECTOR: 'peak',
RTA_PEAK_HOLD_MODE: 'manual',
RTA_PEAK_HOLD_SEC: 4,
RTA_PEAK_RESET_TOKEN: 9,
CORR_RESPONSE_S: 2.5,
CORR_RESET_TOKEN: 7,
XY_POINTS: 256,
});
assert.equal(forced.engine, 'iir');
assert.equal(forced.bpo, '1_12');
assert.equal(forced.freqRange, 'norm');
assert.equal(forced.order, 6);
assert.equal(forced.detector, 'peak');
assert.equal(forced.rtaPeakHoldMode, 'manual');
assert.equal(forced.rtaPeakHoldSeconds, 4);
assert.equal(forced.rtaPeakResetToken, 9);
assert.equal(forced.tauFast, 0.125);
assert.equal(forced.rtwCenters.length, 121);
assert.equal(forced.correlationResponseS, 2.5);
assert.equal(forced.correlationResetToken, 7);
assert.equal(forced.xyPoints, 256);
const extension = context.buildRtaRuntimeConfig({
RTA_BAR_LAYOUT: 'iec',
RTA_ENGINE: 'fft',
RTA_BPO_MODE: '1_12',
RTA_FREQ_RANGE: 'lf',
RTA_IIR_ORDER: 8,
});
assert.equal(extension.engine, 'fft');
assert.equal(extension.bpo, '1_12');
assert.equal(extension.freqRange, 'lf');
assert.equal(extension.order, 8);
const configSource = fs.readFileSync(new URL('../www/core/config.js', import.meta.url), 'utf8');
const selectionSource = configSource.match(/function applyRtaBpoSelection[\s\S]*?\n\}/)?.[0];
assert.ok(selectionSource, 'RTA BPO selection policy must remain testable');
const selectionContext = vm.createContext({
String,
CONFIG: { RTA_BPO_MODE: '1_3', RTA_BAR_LAYOUT: 'rtw' },
});
vm.runInContext(selectionSource, selectionContext);
assert.equal(selectionContext.applyRtaBpoSelection('1_6'), '1_6');
assert.equal(selectionContext.CONFIG.RTA_BPO_MODE, '1_6');
assert.equal(selectionContext.CONFIG.RTA_BAR_LAYOUT, 'rtw');
assert.equal(selectionContext.applyRtaBpoSelection('1_3'), '1_3');
assert.equal(selectionContext.CONFIG.RTA_BAR_LAYOUT, 'rtw');
console.log('RTA profile regression tests passed');