git @ Cat's Eye Technologies Samovar / 2c93efa
Some of these methods are unused. Chris Pressey 6 years ago
2 changed file(s) with 24 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
6363 return False
6464 return True
6565
66 def contains(self, other):
67 if self == other:
68 return True
69 for st in self.subterms:
70 if st.contains(other):
71 return True
72 return False
73
74 def replace(self, old, new):
75 if self == old:
76 return new
77 else:
78 return Term(self.constructor, subterms=[subterm.replace(old, new) for subterm in self.subterms])
79
8066 def match(self, term, unifier):
8167 if self.constructor != term.constructor:
8268 raise ValueError("`%s` != `%s`" % (self.constructor, term.constructor))
2222
2323 self.assertEqual(t2, Term('actor', subterms=[Term('alice')]))
2424
25 def test_term_replace(self):
25 def test_term_match_ground(self):
26 t1 = Term('actor', subterms=[Term('alice')])
27 p1 = Term('actor', subterms=[Term('alice')])
28 u = {}
29 p1.match(t1, u)
30 self.assertEqual(u, {})
31
32 def test_term_no_match_ground(self):
33 t1 = Term('actor', subterms=[Term('alice')])
34 p1 = Term('actor', subterms=[Term('bob')])
35 u = {}
36 with self.assertRaises(ValueError):
37 p1.match(t1, u)
38 self.assertEqual(u, {})
39
40 def test_term_match_bind_var(self):
41 t1 = Term('actor', subterms=[Term('alice')])
42 p1 = Term('actor', subterms=[Var('?A')])
43 u = {}
44 p1.match(t1, u)
45 self.assertEqual(u, {u'?A': Term('alice')})
46
47 def test_term_subst(self):
2648 t = Term('actor', subterms=[Var('?A')])
27 r = t.replace(Var('?A'), Term('alice'))
49 r = t.subst({u'?A': Term('alice')})
2850 self.assertEqual(r, Term('actor', subterms=[Term('alice')]))
2951
3052