def test_generic_sort(self): generic = GenericSort() generic.variable('x') sort = Sort('sort') sort.operation('op_gen', (generic, generic)) sort.operation('const', ()) sort2 = Sort('sort2') sort2.operation('const', ()) r = RewriteRule(sort.op_gen(generic.x(), generic.x()), generic.x()) t1 = r.apply(sort.op_gen(sort2.const(), sort2.const())) self.assertEqual(t1, sort2.const()) t2 = r.apply(sort.op_gen(sort2.const(), sort.const())) self.assertEqual(t2, sort.op_gen(sort2.const(), sort.const()))
# Observers. kv_map.operation('get', (kv_map, generic)) kv_map.operation('isempty', (kv_map, ), boolean) # Modifiers. kv_map.operation('delete', (kv_map, generic)) # Operations for the generic sort. generic.operation('equal', (generic, generic)) # ---------- Variables ---------- # kv_map.variable('m') kv_map.variable('n') # Generic variables for map keys. generic.variable('k') generic.variable('l') # Generic variables for map values. generic.variable('v') generic.variable('w') # ---------- Rewrite rules ---------- # # isempty(empty) -> true. kv_map.rewrite_rule( kv_map.isempty(kv_map.empty()), # -> boolean.true()) # isempty(empty, add(m, k, v)) -> false. kv_map.rewrite_rule(
def test_variable(self): generic = GenericSort() generic.variable('x') self.assertEqual(type(generic.x), Variable) self.assertEqual(type(generic.x()), Term)