59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from extract_cedar_gate_xs import STEP, long_section_check, profile # noqa: E402
|
|
|
|
|
|
def flat_road(ch, ground_level=101.0, surface=100.5, depth=.5, half_width=5.0):
|
|
"""Level ground over a flat road box: cut = (ground - formation) x width."""
|
|
ground = [((-15.0, ground_level), (15.0, ground_level))]
|
|
design = [((-half_width, surface), (half_width, surface)), ((-half_width, surface-depth), (half_width, surface-depth))]
|
|
return profile(ch, ground, design, 0)
|
|
|
|
|
|
class ProfileTest(unittest.TestCase):
|
|
def test_cut_is_ground_above_formation_across_the_drawn_width(self):
|
|
s = flat_road(0)
|
|
self.assertAlmostEqual(s['cutArea'], 1.0*10, places=6)
|
|
self.assertEqual(s['fillArea'], 0)
|
|
self.assertAlmostEqual(s['roadWidth'], 10)
|
|
self.assertTrue(np.isnan(s['bot'][0])) # no formation outside the drawn road
|
|
|
|
def test_fill_where_formation_is_above_ground(self):
|
|
s = flat_road(0, ground_level=99.5)
|
|
self.assertEqual(s['cutArea'], 0)
|
|
self.assertAlmostEqual(s['fillArea'], .5*10, places=6)
|
|
|
|
def test_missing_ground_is_an_error(self):
|
|
with self.assertRaises(ValueError):
|
|
profile(0, [], [((-5.0, 100.0), (5.0, 100.0))], 0)
|
|
|
|
|
|
class LongSectionCheckTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.sections = [flat_road(ch) for ch in range(0, 400, 10)]
|
|
self.panel = {'length': 390, 'rows': [{'ch': float(ch), 'ground': 101.0, 'centre': 100.5, 'left': 100.5, 'right': 100.5} for ch in range(0, 400, 10)]}
|
|
|
|
def test_agreeing_levels_pass(self):
|
|
report = long_section_check(self.sections, self.panel)
|
|
self.assertEqual(report['ground'], {'samples': 40, 'medianAbs': 0.0, 'maxAbs': 0.0})
|
|
self.assertEqual(report['design']['samples'], 120)
|
|
|
|
def test_a_long_section_for_another_road_fails(self):
|
|
for r in self.panel['rows']:
|
|
r['ground'] += .25
|
|
with self.assertRaises(ValueError):
|
|
long_section_check(self.sections, self.panel)
|
|
|
|
def test_too_few_matching_chainages_fail(self):
|
|
self.panel['rows'] = self.panel['rows'][:10]
|
|
with self.assertRaises(ValueError):
|
|
long_section_check(self.sections, self.panel)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|