Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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')
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
 def test_getitem_invalid(self):
     """A Variable has no non-root position."""
     x = Variable(name='x')
     with self.assertRaises(KeyError):
         x[(0, )]
Ejemplo n.º 9
0
 def test_getitem_root(self):
     """A Variable is its own root subterm."""
     x = Variable(name='x')
     self.assertIs(x[()], x)
Ejemplo n.º 10
0
 def test_str(self):
     """A Variable formats as a string."""
     x = Variable(name='x')
     self.assertEqual(str(x), '?x')