"""산출 요약(최소·중앙·최대) 검사 — 2026-09-07 조율 창 권고. 이것은 **검사가 아니라 눈에 띄게 하는 장치**다. 기준을 정해 걸러 내지 않는다 — 임도 물량은 ㎥·㎡·m·ton 이 섞여 「얼마 이하면 이상하다」를 한 벌로 못 정한다. 그래서 시험도 「단위를 안 섞는가」·「없는 값을 0 으로 만들지 않는가」를 본다. """ from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT)) from common_util.common_util_quantity_spread import spread, spread_by_unit # noqa: E402 def test_값이_없으면_0이_아니라_없음() -> None: """0 으로 만들면 「값이 0 인 것」과 구별이 안 된다.""" assert spread([]) is None assert spread_by_unit([], value_key="amount") == {} def test_단위를_안_섞음() -> None: """㎥ 와 ton 을 한 통에 넣으면 최솟값이 뜻을 잃는다.""" rows = [ {"unit": "㎥", "amount": 2526.99}, {"unit": "㎥", "amount": 90.51}, {"unit": "ton", "amount": 23.89}, ] result = spread_by_unit(rows, value_key="amount") assert result["㎥"]["min"] == 90.51 assert result["㎥"]["max"] == 2526.99 assert result["ton"]["count"] == 1 def test_자릿수가_어긋난_값이_최솟값에서_드러남() -> None: """서브가 겪은 「합계 68.8원」 같은 것 — 값이 있기는 하니 시험은 안 잡는다. 최솟값이 나머지와 자릿수가 다르면 사람이 본다.""" rows = [{"unit": "㎡", "amount": v} for v in (13518.6, 18952.3, 68.8)] result = spread_by_unit(rows, value_key="amount") assert result["㎡"]["min"] == 68.8 assert result["㎡"]["max"] == 18952.3 def test_숫자가_아닌_값은_건너뜀() -> None: rows = [{"unit": "㎥", "amount": None}, {"unit": "㎥", "amount": 5.0}] assert spread_by_unit(rows, value_key="amount")["㎥"]["count"] == 1 def test_단위가_없으면_물음표로_모음() -> None: assert "?" in spread_by_unit([{"amount": 1.0}], value_key="amount")