import unittest from g1_register_candidates import engineering_rule from g1_registration_checkpoint import first_block_projection def routes(p1,p2,s1,s2): return [{'route':route,'parity':parity,'residual_max_two_way_area_pps_p95':value} for route,parity,value in [('physical',1,p1),('physical',-1,p2),('scale_free',1,s1),('scale_free',-1,s2)]] class RuleChecks(unittest.TestCase): def test_physical_mean_rg_and_best_branch(self): r=engineering_rule(routes(1,.1,1,2),10,10,{'physical':.02,'scale_free':.02}) self.assertEqual(r['engineering_status'],'LINK_UNDER_FIXED_RULE');self.assertAlmostEqual(r['combined_score'],.5) def test_scale_gate_excludes_even_perfect_physical_fit(self): r=engineering_rule(routes(0,0,.03,.04),1,2,{'physical':.02,'scale_free':.02}) self.assertFalse(r['routes']['physical']['size_gate_pass']);self.assertEqual(r['engineering_status'],'BAND_REVIEW_REQUIRED') def test_threshold_and_band_endpoints(self): for x,status in [(1,'LINK_UNDER_FIXED_RULE'),(2,'BAND_REVIEW_REQUIRED'),(2.01,'OUTSIDE_FIXED_RULE')]: r=engineering_rule(routes(x,x,x,x),1,1,{'physical':1,'scale_free':1});self.assertEqual(r['engineering_status'],status) def test_branch_label_requires_strict_threshold_and_twofold_gap(self): r=engineering_rule(routes(.1,.15,.1,.15),1,1,{'physical':1,'scale_free':1}) self.assertEqual(r['routes']['physical']['branch_label'],'branch-ambiguous (near-symmetric)') r=engineering_rule(routes(.1,.21,.1,.21),1,1,{'physical':1,'scale_free':1}) self.assertEqual(r['routes']['physical']['branch_label'],'det+ preferred') def test_first_100_cost_and_start_stop_boundaries(self): rows=[{'status':'PASS','cpu_seconds':90,'max_starts_per_branch':4,'geometry_load_wall_seconds':.2} for _ in range(100)] self.assertEqual(first_block_projection(rows,2012)['decision'],'CONTINUE') for r in rows[:85]:r['max_starts_per_branch']=14 self.assertEqual(first_block_projection(rows,2012)['decision'],'CONTINUE') rows[85]['max_starts_per_branch']=14 self.assertIn('fourteen_or_more_start_share_over_85_percent',first_block_projection(rows,2012)['stop_reasons']) for r in rows:r['cpu_seconds']=200 self.assertIn('projected_worker_cpu_over_100_hours',first_block_projection(rows,2012)['stop_reasons']) if __name__=='__main__':unittest.main(verbosity=2)