Exemple #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
Exemple #2
0
 def caro(l, a):
     return fresh(lambda d: (same(a, l[0]), same(d, l[1:])))
Exemple #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']
Exemple #4
0
def test_run_fresh():
    q = variables('q')
    r = run(q, fresh(lambda x: same([x], q)))
    assert list(r) == [['_0']]
Exemple #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')})]
Exemple #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})]
Exemple #7
0
def test_fresh_no_vars():
    goal = fresh(lambda: succeed)
    r = goal(Substitution())
    assert list(r) == [Substitution()]
Exemple #8
0
 def cdro(l, d):
     return fresh(lambda a: same((a, d), l))
Exemple #9
0
 def listo(l):
     return disj(nullo(l), fresh(lambda d: (cdro(l, d), listo(d))))
Exemple #10
0
 def cdro(l, d):
     return fresh(lambda a: (same(a, l[0]), same(d, l[1:])))