const EstVerification = (() => { function run(sample, expected) { const machine = EstMachine.calculate( sample.tables.MachMainDat, sample.tables.MachGijunDat, sample.options, ); const head = EstRows.head(sample.tables.HeadMainDat, sample.options); const estimate = EstRows.estimate(sample.tables.EstMainDat, sample.options); const text = EstText.calculate(sample.tables.CostMainDat, sample.options); const wonga = EstWonga.calculate(sample.tables.Wonga, sample.options); const results = []; function check(group, id, actual, wanted) { const differences = []; for (const [key, value] of Object.entries(wanted)) if (Math.abs((actual[key] || 0) - (value || 0)) > 1e-6) differences.push({ field: key, expected: value, actual: actual[key] }); results.push({ group, id, pass: !differences.length, differences }); } for (const row of expected.machine.rows) if (Object.hasOwn(row, "stored")) check( "기계경비", row.slot, machine.rows[row.slot], typeof row.stored === "object" ? row.stored : { [row.field]: row.stored }, ); for (const row of sample.tables.MachTitleDat) check( "기계 목록", row.Code, machine.titles.find((r) => r.Code === row.Code) || {}, Object.fromEntries(["TC", "NC", "GC", "JC"].map((k) => [k, row[k]])), ); for (const row of expected.head_est.head) check("일위대가", row.source_slot, head.rows[row.source_slot], row.stored); for (const row of expected.head_est.est) check("내역서", row.slot, estimate.rows[row.slot], row.stored); for (const row of text.checks) check("단가산출 결과", row.slot, { value: row.calculated }, { value: row.stored }); for (const row of expected.linedata.rows) if (row.kind === "title") check("단가산출 목록", row.slot, text.rows[row.slot], row.stored); for (const row of expected.wonga.results) check("원가계산서", row.Gubun, wonga.rows[row.row_position], { Cost: Number(row.stored) }); return { checked: results.length, passed: results.filter((r) => r.pass).length, failed: results.filter((r) => !r.pass).length, errors: [ ...machine.errors, ...head.errors, ...estimate.errors, ...text.errors, ...wonga.errors, ], results, }; } return { run }; })();