tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

binding_semantics_test.py (1373B)


      1 #!/usr/bin/env python3
      2 """Intent tests for the independent constructor/selector demand oracle."""
      3 import unittest
      4 from binding_semantics import expected,Bottom
      5 from http_headers import LEAF,TRUE
      6 from base_workloads import encode as nat
      7 
      8 
      9 class SemanticOracleTests(unittest.TestCase):
     10     def test_negation_ignores_unknown_child(self):
     11         self.assertEqual(expected('z',[3,0],0),LEAF)
     12         self.assertEqual(expected('z',[5,0],0),LEAF)
     13         with self.assertRaises(Bottom):expected('z',[4,0],0)
     14 
     15     def test_unselected_branch_is_not_evaluated(self):
     16         expr=('choose','z','leaf','flag')
     17         self.assertEqual(expected(expr,[4,0],0),LEAF)
     18         with self.assertRaises(Bottom):expected(expr,[4,1],0)
     19 
     20     def test_pair_root_and_projection_do_not_force_other_child(self):
     21         expr=('pair','x','leaf')
     22         self.assertEqual(expected(expr,[4,0],1),nat(2))
     23         self.assertEqual(expected(expr,[4,0],3),LEAF)
     24         with self.assertRaises(Bottom):expected(expr,[4,0],2)
     25         with self.assertRaises(Bottom):expected(expr,[4,0],0)
     26 
     27     def test_selector_uses_root_not_boolean_canonicality(self):
     28         expr=('choose','z','leaf','flag')
     29         self.assertEqual(expected(expr,[0,2],0),TRUE)
     30         self.assertEqual(expected(expr,[0,5],0),TRUE)
     31         with self.assertRaises(Bottom):expected(expr,[0,4],0)
     32 
     33 
     34 if __name__=='__main__':unittest.main()