mjbuehler's picture
Upload complete research archive under data/ (part 9)
76f6432 verified
Raw History Blame Contribute Delete
2.17 kB
// Runs the HFX validation suite in Node and writes validation_results.json / .md
const fs = require('fs'), path = require('path');
const HFX = require(path.join(__dirname, '..', 'app', 'src', 'hfx_core.js'));
const v = HFX.runValidation((s) => console.log(s));
const rows = v.results.map(r => ({ id: r.id, name: r.name, expected: r.expected, observed: r.observed, error: r.error, tolerance: r.tol, pass: r.pass, absolute: r.absolute, details: r.details }));
const out = { core: HFX.NAME, coreVersion: HFX.VERSION, build: HFX.BUILD, date: new Date().toISOString(), node: process.version, allPass: v.allPass, essentialPass: v.essentialPass, elapsedMs: v.elapsedMs, tests: rows };
fs.writeFileSync(path.join(__dirname, 'validation_results.json'), JSON.stringify(out, null, 2));
const fmt = (x) => typeof x === 'number' ? (Number.isInteger(x) ? String(x) : x.toPrecision(8)) : String(x);
let md = '# HFX validation results\n\nCore ' + HFX.VERSION + ' (build ' + HFX.BUILD + '), Node ' + process.version + ', ' + out.date + '\n\n' +
'All tests pass: **' + v.allPass + '**; essential tests pass: **' + v.essentialPass + '**; elapsed ' + v.elapsedMs.toFixed(0) + ' ms\n\n' +
'| ID | Test | Expected | Observed | Error | Tolerance | Status |\n|---|---|---|---|---|---|---|\n';
for (const r of rows) md += '| ' + r.id + ' | ' + r.name + ' | ' + fmt(r.expected) + ' | ' + fmt(r.observed) + ' | ' + (isNaN(r.error) ? '-' : r.error.toExponential(2)) + (r.absolute ? ' (abs)' : ' (rel)') + ' | ' + r.tolerance + ' | ' + (r.pass ? 'PASS' : '**FAIL**') + ' |\n';
md += '\n## Details\n\n' + rows.map(r => '- **' + r.id + '**: ' + r.details).join('\n') + '\n';
fs.writeFileSync(path.join(__dirname, 'validation_report.md'), md);
for (const r of rows) console.log((r.pass ? 'PASS ' : 'FAIL ') + r.id.padEnd(5) + ' ' + r.name.slice(0, 70).padEnd(72) + ' err=' + (isNaN(r.error) ? '-' : r.error.toExponential(2)) + ' tol=' + r.tolerance + (r.pass ? '' : ' exp=' + fmt(r.expected) + ' obs=' + fmt(r.observed) + ' :: ' + r.details));
console.log('ALL PASS:', v.allPass, ' ESSENTIAL PASS:', v.essentialPass, ' elapsed', v.elapsedMs.toFixed(0), 'ms');
process.exit(v.essentialPass ? 0 : 1);