def test_simple_reduce(self): s = Substitution() # variables ending with '#N' are considered as renamed s['A#0'] = Variable('I') s['I'] = Atomic('p') s['X'] = Variable('C#0') result = Substitution() result['I'] = Atomic('p') s.reduce() self.assertEquals(result, s)
def test_reduce_with_compound(self): s = Substitution() # variables ending with '#N' are considered as renamed s['A#0'] = Variable('I') s['B'] = Compound('p', Variable('A#0')) s['I'] = Atomic('q') result = Substitution() result['I'] = Atomic('q') result['B'] = Compound('p', Variable('A#0')) s.reduce() self.assertEquals(result, s)
def test_simple_flatten(self): s = Substitution() s['A'] = Variable('B') s['B'] = Atomic(1) self.assertEquals(Variable('B'), s.get('A')) s.flatten() self.assertEquals(Atomic(1), s.get('A')) self.assertEquals(Atomic(1), s['B'])
def test_update(self): s1 = Substitution() s1['A'] = Variable('B') s1['B'] = Atomic(1) s2 = Substitution() s2['A'] = Variable('C') s2['D'] = Atomic(2) s1.update(s2) b = s1.get('A') # A is still bound to a variable... self.assertTrue(isinstance(b, Variable)) # ...but the variable has been updated to point to 1 self.assertEquals(Atomic(1), b.value) # C is updated to reflect its proper status self.assertEquals(Atomic(1), s1['C']) # D is left as it is self.assertEquals(Atomic(2), s1['D'])
def test_get_binding(self): s = Substitution() s['A'] = Variable('B') s['B'] = Atomic(1) self.assertEquals(Atomic(1), s['A']) self.assertEquals(Atomic(1), s['B'])
def test_empty_semantics(self): s = Substitution() self.assertFalse(s)
def test_flatten_with_compound(self): s = Substitution() s['A'] = Variable('I') s['B'] = Compound('p', Variable('A')) s.flatten() self.assertEquals(Compound('p', Variable('I')), s['B'])
def test_set_existing_binding(self): s = Substitution() s['A'] = Atomic(1) s['A'] = Atomic(2) self.assertEquals(Atomic(1), s['A'])