import os import sys import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import bl_decimate as bd class TestDecimateRatio(unittest.TestCase): def test_normal_reduction(self): self.assertAlmostEqual(bd.decimate_ratio(5000, 1500000), 5000 / 1500000.0) def test_current_below_target_returns_one(self): self.assertEqual(bd.decimate_ratio(5000, 3000), 1.0) def test_current_equal_target_returns_one(self): self.assertEqual(bd.decimate_ratio(5000, 5000), 1.0) def test_zero_current_returns_one(self): self.assertEqual(bd.decimate_ratio(5000, 0), 1.0) class TestWithinTolerance(unittest.TestCase): def test_exact_hit(self): self.assertTrue(bd.within_tolerance(5000, 5000)) def test_within_3_percent(self): self.assertTrue(bd.within_tolerance(5000, 5150)) # +3% self.assertTrue(bd.within_tolerance(5000, 4850)) # -3% def test_outside_3_percent(self): self.assertFalse(bd.within_tolerance(5000, 5200)) self.assertFalse(bd.within_tolerance(5000, 4700)) def test_zero_target_is_false(self): self.assertFalse(bd.within_tolerance(0, 0)) class TestCountIslands(unittest.TestCase): def test_no_faces(self): self.assertEqual(bd.count_islands(0, []), 0) def test_no_pairs_each_face_is_island(self): self.assertEqual(bd.count_islands(3, []), 3) def test_chain_merges_to_one(self): self.assertEqual(bd.count_islands(4, [(0, 1), (1, 2), (2, 3)]), 1) def test_two_groups(self): self.assertEqual(bd.count_islands(5, [(0, 1), (3, 4)]), 3) # {0,1} {2} {3,4} def test_duplicate_pairs_ok(self): self.assertEqual(bd.count_islands(2, [(0, 1), (1, 0), (0, 1)]), 1) class TestFlippedFraction(unittest.TestCase): def test_empty_is_zero(self): self.assertEqual(bd.flipped_fraction([]), 0.0) def test_mixed(self): self.assertAlmostEqual(bd.flipped_fraction([0.1, -0.2, 0.3, 0.4]), 0.25) def test_all_positive(self): self.assertEqual(bd.flipped_fraction([0.1, 0.2]), 0.0) class TestFillRatio(unittest.TestCase): def test_sum(self): self.assertAlmostEqual(bd.fill_ratio([0.2, 0.3]), 0.5) def test_clamped_to_one(self): self.assertEqual(bd.fill_ratio([0.8, 0.9]), 1.0) def test_empty_is_zero(self): self.assertEqual(bd.fill_ratio([]), 0.0) class TestUvGateOk(unittest.TestCase): def test_clean_passes(self): self.assertTrue(bd.uv_gate_ok(0.0, 0.0)) def test_boundary_passes(self): self.assertTrue(bd.uv_gate_ok(bd.UV_FLIP_TOL, bd.UV_OVERLAP_TOL)) def test_flip_exceeds_fails(self): self.assertFalse(bd.uv_gate_ok(0.03, 0.0)) def test_overlap_exceeds_fails(self): self.assertFalse(bd.uv_gate_ok(0.0, 0.09)) def test_overlap_none_treated_as_zero(self): self.assertTrue(bd.uv_gate_ok(0.01, None)) if __name__ == "__main__": unittest.main()