diff --git a/resources/tester/test_est_jdl_special.py b/resources/tester/test_est_jdl_special.py index 41396e2e8..15e762296 100644 --- a/resources/tester/test_est_jdl_special.py +++ b/resources/tester/test_est_jdl_special.py @@ -142,3 +142,24 @@ def test_jdl_fixed_unit_percent_exports_a_consistent_quantity(): assert result["part"]["F_MPRICE"] == result["part"]["F_MCOST"] == 10 assert result["row"]["GC"] == 10 assert result["total"] == 20 + + +def test_jdl_estimate_percent_quantity_and_fixed_amount_round_trip(): + project = json.loads((ROOT / "tools/est-test/sample.json").read_text(encoding="utf-8")) + for table in project["tables"]: + project["tables"][table] = [] + script = """const fs=require('fs'),j=require('./tools/est-test/jdl.cjs'),a=require('./tools/est-test/archive.cjs'); + const p=JSON.parse(fs.readFileSync(0,'utf8')),blank=structuredClone(p); + p.tables.StuffcDat=[{Code:'M',Name:'material',GC:200,TC:200}]; + p.tables.EstMainDat=[{Code:'M',Name:'rate',Unite:'%',LinkIndex:5,GN:10,GU:200,GC:20,TC:20}, + {Name:'fixed',Unite:'%',CalcIndex:1,GC:30,TC:30},{LinkIndex:54}]; + const out=j.output(p),files=a.unpack(out.bytes),parts=j.parse('mainpart.txt',files.get('mainpart.txt')), + back=j.read(out.bytes,blank); + process.stdout.write(JSON.stringify({parts,rows:back.tables.EstMainDat}));""" + result = json.loads( + subprocess.check_output( + ["node", "-e", script], input=json.dumps(project).encode(), cwd=ROOT + ) + ) + assert [part["F_QQTY"] for part in result["parts"]] == [10, 100] + assert [row["TC"] for row in result["rows"] if not row.get("Level")] == [20, 30, 50] diff --git a/resources/tester/test_est_native_export.py b/resources/tester/test_est_native_export.py index bdfb4a586..975a011f2 100644 --- a/resources/tester/test_est_native_export.py +++ b/resources/tester/test_est_native_export.py @@ -567,7 +567,7 @@ def fixture(path): ] stride = 25 + sum(width + 1 for _, _, width in fields) data = bytearray(512 + 768 * len(fields) + stride) - data[8:24] = bytes.fromhex("068abe8e592364cb403d71d2e3bc64d0") + data[8:25] = bytes.fromhex("068abe8e592364cb403d71d2e3bc64d001") struct.pack_into(" 0.000001 + Math.abs((gn / (["%", "%"].includes(row.Unite) ? 100 : 1)) * (m + l + e) - num(row.TC)) > + 0.000001 ) { key = source(0, { Code: "LITERAL" + ++serial, @@ -237,7 +238,7 @@ function output(project) { JC: row.JC, SC: row.SC, }); - gn = 1; + gn = ["%", "%"].includes(row.Unite) ? 100 : 1; m = num(row.GC); l = num(row.NC); e = num(row.JC) + num(row.SC); @@ -638,9 +639,10 @@ function read(bytes, project) { LinkIndex: source.kind, CalcIndex: 0, }; - row.GC = Math.trunc(row.GN * row.GU); - row.NC = Math.trunc(row.GN * row.NU); - row.JC = Math.trunc(row.GN * row.JU); + const quantity = row.GN / (["%", "%"].includes(row.Unite) ? 100 : 1); + row.GC = Math.trunc(quantity * row.GU); + row.NC = Math.trunc(quantity * row.NU); + row.JC = Math.trunc(quantity * row.JU); row.SC = 0; row.TC = row.GC + row.NC + row.JC; row.TU = row.GU + row.NU + row.JU; diff --git a/tools/est-test/start.cmd b/tools/est-test/start.cmd index c93a6a10a..0a6c5418e 100644 --- a/tools/est-test/start.cmd +++ b/tools/est-test/start.cmd @@ -1,4 +1,4 @@ @echo off cd /d "%~dp0" -node server.cjs +node watch-server.cjs pause