def test_apply(self): sort = Sort('sort') sort.operation('op', (sort, sort)) sort.operation('op2', (sort, )) sort.operation('eq', (sort, sort)) sort.operation('const', ()) sort.variable('x') sort.variable('y') rule = RewriteRule( sort.op(sort.x(), sort.y()), sort.op2(sort.x()), [(sort.eq(sort.x(), sort.y()), sort.eq(sort.x(), sort.y()))]) term = Term(sort.op, (sort.const(), sort.const())) term2 = rule.apply(term) self.assertEqual(term2, sort.op2(sort.const()))
def test_instanciation(self): sort = Sort('sort') sort.operation('op', (sort, sort)) sort.operation('op2', (sort, )) sort.operation('eq', (sort, sort)) sort.variable('x') sort.variable('y') rule = RewriteRule( sort.op(sort.x(), sort.y()), sort.op2(sort.x()), [(sort.eq(sort.x(), sort.y()), sort.eq(sort.x(), sort.y()))]) self.assertEqual(type(rule), RewriteRule) self.assertEqual(rule.lhs, sort.op(sort.x(), sort.y())) self.assertEqual(rule.rhs, sort.op2(sort.x())) self.assertEqual( rule.conditions, [(sort.eq(sort.x(), sort.y()), sort.eq(sort.x(), sort.y()))])
def test_str_representation(self): sort = Sort('sort') sort.operation('op', (sort, sort)) sort.operation('op2', (sort, )) sort.operation('eq', (sort, sort)) sort.variable('x') sort.variable('y') rule = RewriteRule( sort.op(sort.x(), sort.y()), sort.op2(sort.x()), [(sort.eq(sort.x(), sort.y()), sort.eq(sort.x(), sort.y()))]) self.assertEqual( str(rule), '(sort.eq(sort.x, sort.y) ==\ sort.eq(sort.x, sort.y)), => sort.op(sort.x, sort.y) -> sort.op2(sort.x)')
def test_match(self): sort = Sort('sort') sort.operation('op', (sort, )) sort.operation('op2', (sort, sort)) sort.variable('x') sort.variable('y') t1 = sort.op(sort.x()) t2 = sort.op(sort.op(sort.y())) t3 = sort.op2(sort.x(), sort.y()) match1, binding1 = t1.match(t2) match2, _ = t1.match(t3) self.assertTrue(match1) self.assertEqual(binding1[sort.x], sort.op(sort.y())) self.assertFalse(match2)