def test_subterms(self): """A Variable supports iterating its subterms.""" x = Variable(name='x') expected_subterm_set = {((), x)} actual_subterm_set = set(x.subterms()) self.assertEqual(expected_subterm_set, actual_subterm_set)
def test_positions(self): """A Variable supports iterating its positions.""" x = Variable(name='x') expected_position_set = {()} actual_position_set = set(x.positions()) self.assertEqual(expected_position_set, actual_position_set)
def test_call(self): """A Function symbol can be called to create a Term.""" f = Function(name='f', arity=2) x = Variable(name='x') y = Variable(name='y') term = f(x, y) self.assertIsInstance(term, Term)
def setUp(self) -> None: """Set up useful stuff for testing.""" self.f = Function('f', 2) self.g = Function('g', 1) self.a = Constant('a') self.b = Constant('b') self.c = Constant('c') self.x = Variable('x') self.y = Variable('y') self.z = Variable('z')
def setUp(self): """Set up useful stuff for testing.""" self.f = Function('f', 2) self.g = Function('g', 1) self.x = Variable('x') self.y = Variable('y') self.z = Variable('z') self.g_subterm = Term(root=self.g, children=(self.x, )) self.f_subterm = Term(root=self.f, children=(self.y, self.z)) self.term = Term(root=self.f, children=(self.g_subterm, self.f_subterm))
def test_variables(self): """A Variable supports iterating its variables.""" x = Variable(name='x') expected_variables = {x} actual_variables = set(variables(x)) self.assertEqual(expected_variables, actual_variables)
def test_fresh_throws(self): """The fresh_variable function throws for non-pool objects. For variables that were not generated by a VariablePool, and for other random objects, fresh_variable should raise a ValueError. """ x = Variable('x') y1 = IndexedVariable('y', 1) z = 5 with self.assertRaises(ValueError): fresh_variable(x) with self.assertRaises(ValueError): fresh_variable(y1) with self.assertRaises(ValueError): fresh_variable(z)
def test_getitem_invalid(self): """A Variable has no non-root position.""" x = Variable(name='x') with self.assertRaises(KeyError): x[(0, )]
def test_getitem_root(self): """A Variable is its own root subterm.""" x = Variable(name='x') self.assertIs(x[()], x)
def test_str(self): """A Variable formats as a string.""" x = Variable(name='x') self.assertEqual(str(x), '?x')