Publish B17 terminal evidence and gate calibration v2 fixed execution scope
This commit is contained in:
1 parent
1e1d5a6515
commit
d67da6382b
57 files changed
+612570
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import json,tempfile,unittest
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
from phase2_b17_math import tail_weights,validate_review
|
||||
from phase2_h1_worker_v2 import sha
|
||||
from phase2_b17 import decision,admission
|
||||
|
||||
class Weights(unittest.TestCase):
|
||||
def test_equal_mass_top_tenth(self):
|
||||
w=tail_weights(np.arange(10.),np.ones(10));self.assertAlmostEqual(w[-1]/w[0],4);self.assertAlmostEqual(w.sum(),10)
|
||||
def test_tie_mass_shared(self):
|
||||
w=tail_weights([0,1,1],[8,1,1]);np.testing.assert_allclose(w/w[0],[1,2.5,2.5]);self.assertAlmostEqual(w.mean(),1)
|
||||
def test_large_node_mass_fractional(self):
|
||||
w=tail_weights([0,1],[1,9]);np.testing.assert_allclose(w/w[0],[1,1+3/9]);self.assertAlmostEqual(w.sum(),2)
|
||||
def test_constant_label_unit_weights(self):np.testing.assert_array_equal(tail_weights([5,5,5],[1,2,7]),np.ones(3))
|
||||
def test_permutation_and_positive_scale(self):
|
||||
t=np.array([1.,3.,2.]);m=np.array([3.,6.,1.]);p=np.array([2,0,1]);np.testing.assert_allclose(tail_weights(t*7,m*4),tail_weights(t,m));np.testing.assert_allclose(tail_weights(t[p],m[p]),tail_weights(t,m)[p])
|
||||
def test_bad_mass(self):
|
||||
with self.assertRaises(ValueError):tail_weights([1,2],[0,1])
|
||||
def test_screen_boundaries(self):
|
||||
def d(v,h):return decision({'last_location':dict(components=dict(new=204,A=204),new_minus_A=dict(value=v,high=h))})
|
||||
self.assertEqual(d(-.010,-1e-8),'SCREEN_PASS_NOT_CONFIRMED');self.assertEqual(d(-.009999,-.002),'PRUNE_B17_FIXED_RECIPE');self.assertEqual(d(-.02,0),'PRUNE_B17_FIXED_RECIPE');self.assertEqual(d(-.02,None),'PARK_UNDEFINED')
|
||||
def test_budget_reservation(self):
|
||||
self.assertTrue(admission(5000,2,1500));self.assertFalse(admission(5000,3,1500));self.assertFalse(admission(6000,0,300,6300))
|
||||
|
||||
class Review(unittest.TestCase):
|
||||
def test_real_receipt_identity_and_mutation(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
b=Path(d);source=b/'source.py';source.write_text('fixed source\n');p=b/'review.json';binding=dict(reviewed_commit='abc',contract_sha256='contract',launch_proof_sha256='proof',code_sha256={'source.py':sha(source)})
|
||||
good=dict(binding,verdict='PASS');p.write_text(json.dumps(good));validate_review(p,binding,b)
|
||||
for key,value in [('verdict','FAIL'),('reviewed_commit','wrong'),('contract_sha256','wrong'),('launch_proof_sha256','wrong'),('code_sha256',{})]:
|
||||
p.write_text(json.dumps(dict(good,**{key:value})))
|
||||
with self.assertRaises(PermissionError):validate_review(p,binding,b)
|
||||
bad=dict(good);del bad['verdict'];p.write_text(json.dumps(bad))
|
||||
with self.assertRaises(PermissionError):validate_review(p,binding,b)
|
||||
p.write_text(json.dumps(good));source.write_text('changed source\n')
|
||||
with self.assertRaises(PermissionError):validate_review(p,binding,b)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user