Esempio n. 1
0
def test_fresh_multiple_conditions():
    reset_names()
    goal = fresh(lambda x, y, z: (same(x, y), same(x, z)))
    r = goal(Substitution())
    x, y, z = variables('x1, y2, z3')
    allowed_results = [[Substitution({
        x: y,
        y: z
    })], [Substitution({
        x: y,
        z: x
    })], [Substitution({
        x: z,
        z: y
    })], [Substitution({
        x: z,
        y: z
    })]]
    assert list(r) in allowed_results
Esempio n. 2
0
 def caro(l, a):
     return fresh(lambda d: (same(a, l[0]), same(d, l[1:])))
Esempio n. 3
0
def test_run_fresh_ignore_query_var():
    q = variables('q')
    r = run(q, fresh(lambda x: same(x, 'pea')))
    assert list(r) == ['_0']
Esempio n. 4
0
def test_run_fresh():
    q = variables('q')
    r = run(q, fresh(lambda x: same([x], q)))
    assert list(r) == [['_0']]
Esempio n. 5
0
def test_fresh_multiple_vars():
    reset_names()
    goal = fresh(lambda x, y, z: same(x, y))
    r = goal(Substitution())
    assert list(r) == [Substitution({variables('x1'): variables('y2')})]
Esempio n. 6
0
def test_fresh_one_var():
    reset_names()
    goal = fresh(lambda x: same(x, 1))
    r = goal(Substitution())
    assert list(r) == [Substitution({variables('x1'): 1})]
Esempio n. 7
0
def test_fresh_no_vars():
    goal = fresh(lambda: succeed)
    r = goal(Substitution())
    assert list(r) == [Substitution()]
Esempio n. 8
0
 def cdro(l, d):
     return fresh(lambda a: same((a, d), l))
Esempio n. 9
0
 def listo(l):
     return disj(nullo(l), fresh(lambda d: (cdro(l, d), listo(d))))
Esempio n. 10
0
 def cdro(l, d):
     return fresh(lambda a: (same(a, l[0]), same(d, l[1:])))