示例#1
0
def test_unify_lists_with_makelist():
    yp = YP()
    v1 = yp.variable()
    l1 = yp.listpair(yp.atom("a"), yp.listpair(yp.atom("b"), yp.ATOM_NIL))
    l2 = yp.makelist([yp.atom("a"), v1])
    r = [v1.get_value() for x in unify(l1, l2)]
    assert r == [yp.atom("b")]
示例#2
0
def test_run_lists_script(get_compiled_file):
    yp = YP()
    yp.load_script_from_file(get_compiled_file('lists.prolog'))
    l = yp.makelist([
        yp.atom(x) for x in [
            'Johnny', 'Dee Dee', 'Joey', 'Tommy', 'Marky', 'Richie', 'Elvis',
            'C. J.'
        ]
    ])
    q = yp.query('member', [yp.atom('Richie'), l])
    r = list(q)
    assert r == [False]
    v1 = yp.variable()
    v2 = yp.variable()
    v3 = yp.variable()
    q = yp.query('testlist', [yp.makelist([v1, v2, v3])])
    r = [[v1.get_value(), v2.get_value(), v3.get_value()] for x in q]
    assert r == [[yp.atom('red'), yp.atom('green'), yp.atom('blue')]]
示例#3
0
def test_load_scripts_overwrite_multiple_definitions(get_compiled_file):
    yp = YP()
    yp.load_script_from_file(get_compiled_file('defs1.prolog'), overwrite=True)
    yp.load_script_from_file(get_compiled_file('defs2.prolog'), overwrite=True)
    v1 = yp.variable()
    v2 = yp.variable()
    v3 = yp.variable()
    q = yp.query('testlist', [yp.makelist([v1, v2, v3])])
    r = [(v1.get_value(), v2.get_value(), v3.get_value()) for x in q]
    assert set(r) == set([(yp.atom('cyan'), yp.atom('magenta'),
                           yp.atom('yellow'))])