Exemplo n.º 1
0
    def test__parse(self):
        for i, entry in enumerate([
            ('func', Atom('func')),
            ('func()', Atom('func', [])),
            ('func(term)', Atom('func', ['term'])),
            ('func(term, 5.0)', Atom('func', ['term', 5.0])),
            ('func(term, 5.0, True)', Atom('func', ['term', 5.0, True])),
        ]):
            content, expected = entry
            with self.subTest(i=i, value=entry):
                result = Atom.parse(content)

                assert_that(result, 'Atom.parse(content: str) -> Atom:') \
                    .is_equal_to(expected)
Exemplo n.º 2
0
    def test__substitute(self):
        for i, entry in enumerate([
            (Atom.parse('pred'), {}, Atom.parse('pred')),
            (Atom.parse('pred'), {'X': 'a'}, Atom.parse('pred')),
            (Atom.parse('pred'), {'Y': 'X'}, Atom.parse('pred')),
            (Atom.parse('pred(a)'), {}, Atom.parse('pred(a)')),
            (Atom.parse('pred(a)'), {'X': 'a'}, Atom.parse('pred(a)')),
            (Atom.parse('pred(a)'), {'Y': 'X'}, Atom.parse('pred(a)')),
            (Atom.parse('pred(X)'), {}, Atom.parse('pred(X)')),
            (Atom.parse('pred(X)'), {'X': 'a'}, Atom.parse('pred(a)')),
            (Atom.parse('pred(X)'), {'Y': 'X'}, Atom.parse('pred(X)')),
            (Atom.parse('pred(Y)'), {}, Atom.parse('pred(Y)')),
            (Atom.parse('pred(Y)'), {'X': 'a'}, Atom.parse('pred(Y)')),
            (Atom.parse('pred(Y)'), {'Y': 'X'}, Atom.parse('pred(X)')),
            (Atom.parse('pred(X, Y)'), {}, Atom.parse('pred(X, Y)')),
            (Atom.parse('pred(X, Y)'), {'X': 'a'}, Atom.parse('pred(a, Y)')),
            (Atom.parse('pred(X, Y)'), {'Y': 'X'}, Atom.parse('pred(X, X)')),
        ]):
            atom, subst, expected = entry
            with self.subTest(i=i, value=entry):
                result = atom.substitute(subst)

                assert_that(result, 'Atom.substitute(self, subst: Substitution) -> Atom:') \
                    .is_equal_to(expected)