ModelTranslator: adaptive ray distance pure functions
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
25f84f8557
commit
3ae981e40d
@@ -43,5 +43,40 @@ class TestBboxMismatch(unittest.TestCase):
|
||||
self.assertFalse(bb.bbox_mismatch((1.0, 0.0, 3.0), (1.0, 0.0, 3.0)))
|
||||
|
||||
|
||||
class TestPercentile(unittest.TestCase):
|
||||
def test_interpolates(self):
|
||||
self.assertAlmostEqual(bb.percentile([0.0, 10.0], 0.25), 2.5)
|
||||
|
||||
def test_rejects_empty(self):
|
||||
with self.assertRaises(ValueError):
|
||||
bb.percentile([], 0.99)
|
||||
|
||||
def test_rejects_bad_q(self):
|
||||
with self.assertRaises(ValueError):
|
||||
bb.percentile([1.0], 1.1)
|
||||
|
||||
|
||||
class TestAdaptiveRayDistance(unittest.TestCase):
|
||||
def test_p99_with_safety(self):
|
||||
r = bb.adaptive_ray_distance([0.002] * 20, (1.0, 0.0, 0.0))
|
||||
self.assertAlmostEqual(r["distance_p99"], 0.002)
|
||||
self.assertAlmostEqual(r["value"], 0.003) # 0.002*1.5,未夹
|
||||
self.assertFalse(r["capped"])
|
||||
|
||||
def test_lower_floor(self):
|
||||
r = bb.adaptive_ray_distance([0.0], (1.0, 0.0, 0.0))
|
||||
self.assertAlmostEqual(r["value"], 0.0005) # 下限 0.05%
|
||||
self.assertFalse(r["capped"])
|
||||
|
||||
def test_upper_cap(self):
|
||||
r = bb.adaptive_ray_distance([0.02], (1.0, 0.0, 0.0))
|
||||
self.assertAlmostEqual(r["value"], 0.01) # 夹到 1% 上限
|
||||
self.assertTrue(r["capped"])
|
||||
|
||||
def test_zero_bbox_raises(self):
|
||||
with self.assertRaises(ValueError):
|
||||
bb.adaptive_ray_distance([0.01], (0.0, 0.0, 0.0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user