1// Runs the MATLAB validation script (../matlab/woodblock_validate.m) through
2// numbl in Node, checking the implementation against the woodblock.py
3// reference diagnostics and the listener targets in woodblock.md §7.
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 === 'woodblock_validate.m')!;
17const t0 = performance.now();
18const result = executeCode(main.source, { displayResults: false }, workspaceFiles, 'woodblock_validate.m');
19process.stdout.write(result.output.join(''));
20console.log(`total time : ${((performance.now() - t0) / 1000).toFixed(2)} s`);
22if (result.output.join('').includes('MISMATCH')) {
23 process.exit(1);
24}