fix(est): preserve precision and parse source notes

This commit is contained in:
2026-11-05 17:57:49 +09:00
parent 3e9fb28714
commit f255ebc0fe
3 changed files with 143 additions and 11 deletions
+122
View File
@@ -135,3 +135,125 @@ def test_subtotal_includes_price_only_rows_and_updates_truncated_final_amount():
149380,
158440,
]
def test_operator_followed_by_spaces_does_not_start_a_new_assignment():
result = run(
"math",
r"""[1700,2000].map(weight=>EstText.calculate([
{Index:1,Code:'forest',LineData:'forest'},
{LineData:` N = 54.93 q = 250 W = ${weight}`},
{LineData:' Q = N × q ÷ W = 54.93 × 250 ÷ 1,700 = \x128.08\x12 ㎥/hr'},
{LineData:' V = Q × 2 = \x1216.16\x12'}
]))""",
)
assert all(item["errors"] == [] for item in result)
assert [item["rows"][2]["TC"] for item in result] == [8.08, 6.87]
assert [item["rows"][3]["TC"] for item in result] == [16.16, 13.74]
def test_curly_wrapped_results_and_explanatory_calculations_keep_their_text():
result = run(
"math",
r"""EstText.calculate([
{Index:1,Code:'forest',LineData:'forest'},
{LineData:' {0.91m×0.91m×0.6m = \x120.49686\x12㎥}'},
{LineData:' {0.49686 ×2.6Ton = \x121.29\x12}'},
{LineData:' ※ ㎡당 중량 1.6개 ×1,325÷1,000 = \x122.12\x12Ton/㎡'}
])""",
)
assert result["errors"] == []
assert [row["TC"] for row in result["rows"][1:]] == [0.49686, 1.29, 2.12]
assert result["rows"][1]["LineData"].strip().startswith("{")
assert result["rows"][1]["LineData"].endswith("}")
def test_won_unit_glyphs_are_units_instead_of_operators():
result = run(
"math",
r"""EstText.calculate([
{Index:1,Code:'money',LineData:'money'},
{LineData:' 0.0347㎥ / 2.5 × 0 \\/㎥ = \x120\x12'},
{LineData:' 0.0347㎥ / 2.5 × 2500 \\/㎥ = \x1234.7\x12'},
{LineData:' 2㎥ × 2500₩/㎥ = \x125000\x12'}
])""",
)
assert result["errors"] == []
assert [row["TC"] for row in result["rows"][1:]] == [0, 34.7, 5000]
def test_range_conditions_are_not_assigned_arbitrary_values():
result = run(
"math",
r"""EstText.calculate([
{Index:1,Code:'range',LineData:'range'},
{LineData:' 앙카핀 (D=13, L=450~600mm) 1.0㎡ : 별도계상'},
{LineData:' H = 0~4m : (기계80%, 인력20%)'},
{LineData:' Q = 2 × 3 = \x126\x12'},
{LineData:' V = H × 2 = \x128\x12'}
])""",
)
assert len(result["errors"]) == 1
assert "참조 항목 없음: H" in result["errors"][0]
assert result["rows"][3]["TC"] == 6
def test_quantity_subtotal_keeps_six_digits_before_pricing():
result = run(
"math",
r"""[4.4,5].map(length=>EstText.calculate([
{Index:1,Code:'sign',LineData:'sign'},
{Level:2,LineData:'각재 수량'},
{Diget:7,DigetIndex:1,LineData:` 0.09 ×0.09 ×${length}m ×2개 = \x120.07128\x12`},
{Diget:7,DigetIndex:1,LineData:' 0.06 ×0.06 ×2.28m ×5개 = \x120.04104\x12'},
{Diget:7,DigetIndex:1,LineData:' 0.06 ×0.06 ×2.28m ×7개 = \x120.057456\x12'},
{Diget:7,DigetIndex:1,LinkIndex:61,LineData:' 소 계 : Q1 = \x0c0.169776\x0c ㎥/개소'},
{SCheck:-2,LinkIndex:5,LineData:' 재료비 : \x03577,842\x03 × Q1 = 577,842 × 0.169776 = \x1298,103.7\x12'}
]))""",
)
assert all(item["errors"] == [] for item in result)
assert [item["rows"][5]["TC"] for item in result] == [0.169776, 0.179496]
assert [item["rows"][6]["TC"] for item in result] == [98103.7, 103720.3]
def test_declaration_can_follow_an_hour_unit_with_a_single_space():
result = run(
"math",
r"""EstText.calculate([
{Index:1,Code:'transport',LineData:'transport'},
{LineData:' L = 1.0Km{?} V1 = 5.5Km/hr V2 = 9.3Km/hr t=35분'},
{LineData:' Q = t × 2 = \x1270\x12'}
])""",
)
assert result["errors"] == []
assert result["rows"][2]["TC"] == 70
def test_fullwidth_unit_slash_and_ground_level_annotations():
result = run(
"math",
r"""EstText.calculate([
{Index:1,Code:'annotations',LineData:'annotations'},
{LineData:' Q = 23.32 ㎥/hr'},
{LineData:' D1 = {-}6.6m [평균지반고]'},
{LineData:' D2 = {-}18.6m [기초터파기 평균 저면 EL.]'},
{LineData:' V = Q + D1 - D2 = \x1235.32\x12',Precision:2}
])""",
)
assert result["errors"] == []
assert result["rows"][4]["TC"] == 35.32
def test_spaced_metre_unit_is_not_a_second_variable_declaration():
result = run(
"math",
r"""EstText.calculate([
{Index:1,Code:'spaced_unit',LineData:'spaced_unit'},
{LineData:' L7 = 4.5m'},
{LineData:' Q2 = L7 / 0.8 M = 4.5 / 0.8 = \x125.63\x12 개'},
{SCheck:-2,LineData:' 재료비 : \x033,000\x03 × Q2 = 3,000 × 5.63 = \x1216,890\x12'}
])""",
)
assert result["errors"] == []
assert result["rows"][2]["TC"] == 5.63
assert result["rows"][3]["TC"] == 16890