Files
Aislo/resources/tester/helper_est_archive.cjs

67 lines
2.2 KiB
JavaScript

const fs = require("fs");
const p = require("../../tools/est-test/import-estx.cjs").importEstx(
fs.readFileSync(process.argv[2]),
);
const q = require("../../tools/est-test/server.cjs").calculate(p);
const out = { errors: q.calculation.errors, counts: {}, differences: [] };
for (const table of [
"HeadMainDat",
"EstMainDat",
"MachMainDat",
"CostMainDat",
"HeadTitleDat",
"MachTitleDat",
"CostTitleDat",
"Wonga",
]) {
let checked = 0,
matched = 0,
group = "";
const lookup = new Map((q.tables[table] || []).map((r) => [r.Code, r]));
for (let i = 0; i < p.tables[table].length; i++) {
const a = p.tables[table][i],
b = table.includes("Title") ? lookup.get(a.Code) : q.tables[table][i];
if (a.Index > 0) group = a.Code;
if (table === "CostMainDat") {
const markers =
a.LinkIndex === 61 ? /[\x12\x0c]([-\d.,]+)[\x12\x0c]/g : /\x12([-\d.,]+)\x12/g;
const before = [...String(a.LineData || "").matchAll(markers)],
after = [...String(b?.LineData || "").matchAll(markers)];
for (let part = 0; part < before.length; part++) {
const x = Number(before[part][1].replaceAll(",", "")),
y = after[part] ? Number(after[part][1].replaceAll(",", "")) : null;
checked++;
if (y !== null && Math.abs(x - y) < 1e-6) matched++;
else if (out.differences.filter((d) => d.table === table).length < 120)
out.differences.push({
table,
index: i,
group,
part,
before: x,
after: y,
line: a.LineData,
});
}
} else
for (const key of table === "Wonga" ? ["Cost"] : ["NC", "GC", "JC", "SC", "TC"]) {
if (a[key] === null || a[key] === undefined) continue;
checked++;
if (b && Math.abs(Number(a[key]) - Number(b[key] || 0)) < 1e-6) matched++;
else if (out.differences.filter((d) => d.table === table).length < 15)
out.differences.push({
table,
index: i,
group,
key,
code: a.Code,
before: a[key],
after: b?.[key],
});
}
}
out.counts[table] = { checked, matched };
}
console.log(JSON.stringify(out));