72 lines
2.8 KiB
Python
72 lines
2.8 KiB
Python
import unittest
|
|
|
|
import numpy as np
|
|
|
|
from B06_wf3_ProfileCross.B06_wf3_ProfileCross_Engine_Sampler import (
|
|
CallableSurfaceSampler,
|
|
DtmGridSampler,
|
|
)
|
|
from B06_wf3_ProfileCross.B06_wf3_ProfileCross_Engine_Section import (
|
|
SectionGenerationOptions,
|
|
format_station,
|
|
generate_sections,
|
|
)
|
|
|
|
|
|
class FormatStationTest(unittest.TestCase):
|
|
def test_format(self) -> None:
|
|
self.assertEqual(format_station(0.0), "STA.0+000.000")
|
|
self.assertEqual(format_station(1234.5), "STA.1+234.500")
|
|
self.assertEqual(format_station(20.0), "STA.0+020.000")
|
|
|
|
|
|
class DtmGridSamplerTest(unittest.TestCase):
|
|
def test_sample_inside_and_outside(self) -> None:
|
|
x = np.array([0.0, 1.0, 2.0])
|
|
y = np.array([0.0, 1.0, 2.0])
|
|
z = np.array([[0.0, 1.0, 2.0], [1.0, 2.0, 3.0], [2.0, 3.0, 4.0]])
|
|
valid = np.ones((3, 3), dtype=bool)
|
|
sampler = DtmGridSampler(x, y, z, valid)
|
|
|
|
zq, vq = sampler.sample_xy(np.array([[0.5, 0.5], [10.0, 10.0]]))
|
|
self.assertTrue(vq[0])
|
|
self.assertFalse(vq[1]) # 격자 밖
|
|
self.assertAlmostEqual(zq[0], 1.0) # 이중선형 보간
|
|
|
|
def test_invalid_shape(self) -> None:
|
|
with self.assertRaises(ValueError):
|
|
DtmGridSampler(np.array([0.0]), np.array([0.0, 1.0]), np.zeros((2, 1)), np.ones((2, 1)))
|
|
|
|
|
|
class GenerateSectionsTest(unittest.TestCase):
|
|
def test_straight_route(self) -> None:
|
|
sampler = CallableSurfaceSampler(lambda xy: 5.0 + 0.05 * xy[:, 0] + 0.02 * xy[:, 1])
|
|
polyline = [[float(x), 0.0, 5.0 + 0.05 * x] for x in range(0, 101, 10)]
|
|
|
|
result = generate_sections(
|
|
polyline,
|
|
sampler,
|
|
SectionGenerationOptions(station_interval_m=20.0, cross_half_width_m=10.0),
|
|
)
|
|
|
|
self.assertEqual(result["status"], "completed")
|
|
self.assertAlmostEqual(result["longitudinal"]["length_m"], 100.0)
|
|
self.assertEqual(result["summary"]["station_count"], 6)
|
|
self.assertEqual(len(result["cross_sections"]), 6)
|
|
# 횡단 샘플: ±10m를 0.5m 간격 → 41개
|
|
self.assertEqual(len(result["cross_sections"][0]["samples"]), 41)
|
|
# BP/EP 종류 표기
|
|
self.assertEqual(result["longitudinal"]["stations"][0]["kind"], "bp")
|
|
self.assertEqual(result["longitudinal"]["stations"][-1]["kind"], "ep")
|
|
|
|
def test_invalid_options(self) -> None:
|
|
sampler = CallableSurfaceSampler(lambda xy: np.zeros(len(xy)))
|
|
polyline = [[0.0, 0.0, 0.0], [10.0, 0.0, 0.0]]
|
|
with self.assertRaises(ValueError):
|
|
generate_sections(polyline, sampler, SectionGenerationOptions(station_interval_m=0.0))
|
|
|
|
def test_too_short_polyline(self) -> None:
|
|
sampler = CallableSurfaceSampler(lambda xy: np.zeros(len(xy)))
|
|
with self.assertRaises(ValueError):
|
|
generate_sections([[0.0, 0.0, 0.0]], sampler)
|