binding_analysis_test.py (2243B)
1 #!/usr/bin/env python3 2 """Semantic-intent controls for the independent binding-analysis oracle.""" 3 import unittest 4 from binding_analysis import analyze,decision,core,call,cases 5 from base_workloads import encode as nat 6 7 8 class BindingAnalysisTests(unittest.TestCase): 9 # Identity token only: these tests do not assert this tree has selector 10 # semantics. The integration harness authenticates its actual selector. 11 selector=nat(1234567) 12 13 def test_named_controls(self): 14 expected={'singleBound':1,'branchBound':1,'constructorBound':1,'adderBound':1, 15 'sharedBound':2,'closureBound':3,'unusedBound':0,'closedBranchBound':1, 16 'alias-same-literal':1,'name-with-wrong-literal':4,'shadowed-selector':4, 17 'selector-and-branch-use':2,'partial-selector':5,'oversaturated-selector':4, 18 'lambda-shadow-unused':0,'lambda-capture':3,'literal-stem-construction':1, 19 'literal-fork-call':4,'list-duplicate':2,'opaque-consumer':4,'malformed-kind':6} 20 actual={name:decision(analyze(node,self.selector)) for name,node in cases(self.selector)} 21 for name,value in expected.items():self.assertEqual(actual[name],value,name) 22 23 def test_conditional_paths_include_condition_work(self): 24 z=core(2,0) 25 result=analyze(call(core(5,self.selector),z,core(1),z),self.selector) 26 self.assertEqual(result[0],2) 27 self.assertEqual(result[1],{1,2}) 28 self.assertEqual(decision(result),2) 29 30 def test_nested_shadowing_and_capture(self): 31 for index in [0,1]: 32 self.assertEqual(decision(analyze(core(4,core(4,core(2,index))),self.selector)),0) 33 captured=analyze(core(4,core(4,core(2,2))),self.selector) 34 self.assertEqual(captured[0],1) 35 self.assertEqual(decision(captured),3) 36 37 def test_not_a_type_or_rhs_certificate(self): 38 # The analysis intentionally has no RHS parameter. Candidate != approved 39 # rewrite; e.g. different costs or function observations of RHSs are not 40 # established by passing this occurrence/path analysis. 41 direct=analyze(core(2,0),self.selector) 42 self.assertEqual(decision(direct),1) 43 44 45 if __name__=='__main__':unittest.main()