"""층따기 밑수 — 성토부 아래 원지반의 지표면 길이(m). 근거(2026-09-09 사용자 확정: 단위 ㎡) — 별표2 · 임도기술교본 6장 4절 「경사가 1:4보다 급한 지반 위에 성토를 하는 경우 원지반 표면에 층따기」. 면적은 측점 사이를 이어 B08 이 내고, 여기서는 **측점 하나의 밑수 길이**만 낸다. """ from __future__ import annotations import math import sys from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[2] if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) from B06_Section.B06_Section_Engine_Areas import ( # noqa: E402 _BENCH_CUT_MIN_GROUND_SLOPE, _bench_cut_length, ) def test_완만한_지반은_층따기를_안_한다() -> None: """1:4(25%)보다 완만하면 대상이 아니다 — 성토가 있어도 0.""" offsets = [0.0, 1.0, 2.0] grounds = [0.0, 0.2, 0.4] # 20 % 경사 diffs = [-1.0, -1.0, -1.0] # 전 구간 성토 assert _bench_cut_length(offsets, grounds, diffs) == 0.0 def test_급한_지반의_성토부만_빗변으로_센다() -> None: offsets = [0.0, 1.0, 2.0] grounds = [0.0, 0.5, 1.0] # 50 % 경사 — 대상 diffs = [-1.0, -1.0, -1.0] expected = 2 * math.hypot(1.0, 0.5) assert _bench_cut_length(offsets, grounds, diffs) == expected def test_절토부는_안_센다() -> None: """층따기는 성토부 아래 원지반에만 한다.""" offsets = [0.0, 1.0] grounds = [0.0, 0.5] diffs = [1.0, 1.0] # 절토 assert _bench_cut_length(offsets, grounds, diffs) == 0.0 def test_절성토_경계는_영교점까지만_센다() -> None: offsets = [0.0, 1.0] grounds = [0.0, 0.5] diffs = [1.0, -1.0] # 가운데에서 절토→성토 expected = math.hypot(1.0, 0.5) * 0.5 assert math.isclose(_bench_cut_length(offsets, grounds, diffs), expected, rel_tol=1e-12) def test_내리막도_오르막과_같이_센다() -> None: """기울기의 방향이 아니라 급한지만 본다.""" up = _bench_cut_length([0.0, 1.0], [0.0, 0.5], [-1.0, -1.0]) down = _bench_cut_length([0.0, 1.0], [0.5, 0.0], [-1.0, -1.0]) assert math.isclose(up, down, rel_tol=1e-12) def test_문턱값이_법정_1대4_이다() -> None: assert _BENCH_CUT_MIN_GROUND_SLOPE == 0.25 def test_설계_결과에_밑수가_실린다() -> None: """엔진 결과 dict 에 키가 있어야 B08 이 읽는다.""" from B06_Section.B06_Section_Engine_Design import compute_cross_design ground = [ {"offset_m": offset / 2.0, "elevation_m": 100.0 - (offset / 2.0) * 0.5} for offset in range(-24, 25) ] result = compute_cross_design( ground, 100.0, ground_type="soil", section_mode="left_cut", ) assert "bench_cut_length_m" in result assert result["bench_cut_length_m"] >= 0.0