48 lines
1.9 KiB
JavaScript
48 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
// Run from the repo root with node --require <this file> test/<suite>.js.
|
|
// This one-off comparison retains the pre-refactor generator as its oracle.
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
const Module = require('node:module');
|
|
const { execFileSync } = require('node:child_process');
|
|
const root = path.resolve(__dirname, '../../../..');
|
|
const filename = path.join(root, 'src/compile/complex-junction.js');
|
|
const baseline = new Module(filename, module);
|
|
baseline.filename = filename;
|
|
baseline.paths = Module._nodeModulePaths(path.dirname(filename));
|
|
baseline._compile(
|
|
execFileSync('git', ['show', '1679d1b:src/compile/complex-junction.js'], { cwd: root, encoding: 'utf8' }),
|
|
filename,
|
|
);
|
|
const current = require(filename);
|
|
const build = current.buildComplexJunctionGeometry;
|
|
let comparisons = 0;
|
|
const shapes = new Set();
|
|
const diagnostics = new Set();
|
|
let shifted = 0;
|
|
let crossingEdits = 0;
|
|
current.buildComplexJunctionGeometry = function (model, cluster, helpers) {
|
|
const values = {};
|
|
const functions = {};
|
|
for (const [key, value] of Object.entries(helpers)) {
|
|
(typeof value === 'function' ? functions : values)[key] = value;
|
|
}
|
|
const copied = structuredClone({ model, cluster, values });
|
|
const expected = baseline.exports.buildComplexJunctionGeometry(copied.model, copied.cluster, {
|
|
...copied.values,
|
|
...functions,
|
|
});
|
|
const actual = build(model, cluster, helpers);
|
|
assert.deepStrictEqual(actual, expected, `generator output changed for ${cluster.id}`);
|
|
comparisons++;
|
|
shapes.add(actual.shape?.kind || 'early-return');
|
|
for (const item of actual.diagnostics) diagnostics.add(item.rule);
|
|
if (helpers.clusterIslandOffsetMeters) shifted++;
|
|
if (helpers.clusterCrossingControls?.size) crossingEdits++;
|
|
return actual;
|
|
};
|
|
process.on('exit', () => {
|
|
console.log('Generator parity:', { comparisons, shapes: [...shapes], shifted, crossingEdits, diagnostics: [...diagnostics] });
|
|
});
|