Ejemplo n.º 1
0
def test_functor_arities():
    s = compile_prolog_from_string(
        '''
    likes(A,B) :- person(A), person(B), friend(A,B).
    likes(A,B,C) :- person(A),person(B), person(C), friend(A,B), friend(A,C).
    likes(A,B) :- person(A), person(B), person(C), foe(A,C), foe(B,C).
    person(mike).
    person(joe).
    person(pete).
    person(zack).
    friend(mike,pete).
    friend(mike,joe).
    foe(joe,zack).
    foe(pete,zack).
    ''', TestContext)

    yp = YP()
    yp.load_script_from_string(s, overwrite=False)
    X = yp.variable()
    Y = yp.variable()
    q = yp.query('likes', [X, Y])
    r = [(to_python(X.get_value()), to_python(Y.get_value())) for x in q]
    assert set(r) == set([
        ('mike', 'pete'),
        ('mike', 'joe'),
        ('joe', 'pete'),
        ('joe', 'joe'),
        ('pete', 'pete'),
        ('pete', 'joe'),
    ])
Ejemplo n.º 2
0
def test_load_script_from_string(get_compiled_file):
    yp = YP()
    with open(get_compiled_file('geometricobjects.prolog'), 'r') as f:
        yp.load_script_from_string(f.read(), overwrite=False)
    Y = yp.variable()
    q = yp.query('horizontal', [
        yp.functor('seg',
                   [yp.functor('point', [1, 1]),
                    yp.functor('point', [2, Y])])
    ])
    r = [Y.get_value() for x in q]
    assert r == [1]