diff --git a/M02_MasterTemplete/CostFlow/M02_CF_Model.ts b/M02_MasterTemplete/CostFlow/M02_CF_Model.ts index f6ada09ca..d19f3f431 100644 --- a/M02_MasterTemplete/CostFlow/M02_CF_Model.ts +++ b/M02_MasterTemplete/CostFlow/M02_CF_Model.ts @@ -188,13 +188,19 @@ export function addBox( ); const box: CfBox = { id, kind, name, color: BOX_COLOR[kind], unit: "-", x, y }; if (kind === "input") box.input = { mode: "variable", elements: [], variables: [] }; - if (kind === "function") + if (kind === "function") { + // 출력 이름은 로직 안에서 겹치지 않게 「결과 1」 「결과 2」 … — 다른 함수 상자의 받는 알약과 섞이지 않음 + const taken = lg.boxes.flatMap((b) => (b.func ? [b.func.output.name] : [])); + let n = 1; + while (taken.includes(`${tl("Result")} ${n}`)) n++; + const out = `${tl("Result")} ${n}`; box.func = { - sheet: { id: `s-${id}`, 이름: name, 칸: { A1: { 값: tl("Result") } } }, + sheet: { id: `s-${id}`, 이름: name, 칸: { A1: { 값: out } } }, inputs: [], variables: [], - output: { cell: "B1", name: tl("Result"), unit: "-" }, + output: { cell: "B1", name: out, unit: "-" }, }; + } if (kind === "output") box.output = { cost: "노무비", unit: "-" }; return { lg: { ...lg, boxes: [...lg.boxes, box] }, box }; } diff --git a/resources/tester/test_m02_cf_model.py b/resources/tester/test_m02_cf_model.py index 0e9ea8cce..818541127 100644 --- a/resources/tester/test_m02_cf_model.py +++ b/resources/tester/test_m02_cf_model.py @@ -322,3 +322,27 @@ def test_같은_이름_받는_알약은_번호() -> None: "out(x.boxes.find(y => y.id === g.id).func.inputs.map(i => i.port));" ) assert got == ["석공", "노무비", "석공 (2)", "할증"] + + +def test_함수_출력_기본_이름은_겹치지_않음_받는_알약은_번호() -> None: + got = _run( + "let lg = M.newLogic(); let r = add(lg, 'function'); lg = r.lg; const f1 = r.box;\n" + "r = add(lg, 'function'); lg = r.lg; const f2 = r.box;\n" + "r = add(lg, 'function'); lg = r.lg; const f3 = r.box;\n" + "lg = M.removeBox(lg, f2.id); r = add(lg, 'function'); lg = r.lg; const f4 = r.box;\n" + "lg = M.link(lg, { box: f1.id, name: '결과 1' }, { box: f3.id, name: '' }).lg;\n" + "lg = M.link(lg, { box: f4.id, name: '결과 2' }, { box: f3.id, name: '' }).lg;\n" + "r = add(lg, 'function'); lg = r.lg; const f5 = r.box;\n" + "lg = M.updateBox(lg, f5.id, { func: { ...f5.func, output: { ...f5.func.output, name: '결과 1' } } });\n" + "lg = M.link(lg, { box: f5.id, name: '결과 1' }, { box: f3.id, name: '' }).lg;\n" + "out([[f1, f3, f4, f5].map(b => [b.func.output.name, b.func.sheet.칸.A1.값])," + " lg.boxes.find(b => b.id === f3.id).func.inputs.map(i => i.port)]);" + ) + names, ports = got + assert names == [ + ["결과 1", "결과 1"], + ["결과 3", "결과 3"], + ["결과 2", "결과 2"], + ["결과 4", "결과 4"], + ] + assert ports == ["결과 1", "결과 2", "결과 1 (2)"]