1// Runs the MATLAB validation script (../matlab/maraca_validate.m) through
2// numbl in Node: closed-form identities, exact reproducibility of the seeded
3// impact process, and the pinned end-to-end diagnostics.
4// Run with: npm run selftest
6import { readFileSync, readdirSync } from 'fs';
7import { join, dirname } from 'path';
8import { fileURLToPath } from 'url';
9import { executeCode } from 'numbl';
11const matlabDir = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'matlab');
12const workspaceFiles = readdirSync(matlabDir)
13 .filter((f) => f.endsWith('.m'))
14 .map((f) => ({ name: f, source: readFileSync(join(matlabDir, f), 'utf8') }));
16const main = workspaceFiles.find((f) => f.name === 'maraca_validate.m')!;
17const t0 = performance.now();
18const result = executeCode(main.source, { displayResults: false }, workspaceFiles, 'maraca_validate.m');
19const text = result.output.join('');
20process.stdout.write(text);
21console.log(`total time : ${((performance.now() - t0) / 1000).toFixed(2)} s`);
23if (text.includes('MISMATCH') || text.includes('FAILED')) {
24 process.exit(1);
25}