def setUp(self): self.clean_state() self.monitor = FilterMonitor()
class TestFilterMonitor(unittest.TestCase): """ Test Filter Monitor class """ def clean_state(self): self.monitor = None def setUp(self): self.clean_state() self.monitor = FilterMonitor() def tearDown(self): self.clean_state() def test_empty_monitor(self): # when_nothing_added self.then_all_statistics_are_empty() def then_all_statistics_are_empty(self): self.then_total_count_is(0) def then_total_count_is(self, expected_count): self.assertEqual(expected_count, self.monitor.count) def test_monitor_accepts(self): self.when_triangles_are_accepted() self.then_total_count_is(8) self.then_accepted_triangle_count_is_correct(8) self.then_rejected_triangle_count_is_correct(0) self.then_refined_triangle_count_is_correct(0) def when_triangles_are_accepted(self, reason=None): for triangle in WaveFront.unit_sphere: self.monitor.accept(triangle, reason) def then_accepted_triangle_count_is_correct(self, expected_count): self.assertEqual(expected_count, self.monitor.accept_count) self.then_count_by_action_and_reason_is_correct(expected_count, TriangleClassification.Accept) def then_rejected_triangle_count_is_correct(self, expected_count): self.assertEqual(expected_count, self.monitor.reject_count) self.then_count_by_action_and_reason_is_correct(expected_count, TriangleClassification.Reject) def then_refined_triangle_count_is_correct(self, expected_count): self.assertEqual(expected_count, self.monitor.refine_count) self.then_count_by_action_and_reason_is_correct(expected_count, TriangleClassification.Refine) def test_monitor_rejects(self): self.when_triangles_are_rejected() self.then_total_count_is(8) self.then_accepted_triangle_count_is_correct(0) self.then_rejected_triangle_count_is_correct(8) self.then_refined_triangle_count_is_correct(0) def when_triangles_are_rejected(self, reason=None): for triangle in WaveFront.unit_sphere: self.monitor.reject(triangle, reason) def test_monitor_refines(self): self.when_triangles_are_refined() self.then_total_count_is(8) self.then_accepted_triangle_count_is_correct(0) self.then_rejected_triangle_count_is_correct(0) self.then_refined_triangle_count_is_correct(8) def when_triangles_are_refined(self, reason=None): for triangle in WaveFront.unit_sphere: self.monitor.refine(triangle, reason) def test_monitor_works_with_multiple_additions(self): self.when_triangles_are_accepted("alpha") self.when_triangles_are_accepted("beta") self.when_triangles_are_accepted("gamma") self.when_triangles_are_refined() self.when_triangles_are_rejected("delta") self.when_triangles_are_accepted() self.when_triangles_are_accepted("beta") self.when_triangles_are_refined() self.when_triangles_are_rejected() self.when_triangles_are_refined() self.then_accepted_triangle_count_is_correct(5 * 8) self.then_rejected_triangle_count_is_correct(2 * 8) self.then_refined_triangle_count_is_correct(3 * 8) self.then_total_count_is((5 + 2 + 3) * 8) self.then_count_by_action_and_reason_is_correct( 1 * 8, TriangleClassification.Accept, "alpha") self.then_count_by_action_and_reason_is_correct( 2 * 8, TriangleClassification.Accept, "beta") self.then_count_by_action_and_reason_is_correct( 1 * 8, TriangleClassification.Accept, "gamma") self.then_count_by_action_and_reason_is_correct( 1 * 8, TriangleClassification.Reject, "delta") self.assertTrue("alpha" in self.monitor.reasons) def then_count_by_action_and_reason_is_correct(self, expected_count, action=None, reason=None): self.assertEqual(expected_count, self.monitor.action_count(action, reason))