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
def caro(l, a): return fresh(lambda d: (same(a, l[0]), same(d, l[1:])))
def test_run_fresh_ignore_query_var(): q = variables('q') r = run(q, fresh(lambda x: same(x, 'pea'))) assert list(r) == ['_0']
def test_run_fresh(): q = variables('q') r = run(q, fresh(lambda x: same([x], q))) assert list(r) == [['_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')})]
def test_fresh_one_var(): reset_names() goal = fresh(lambda x: same(x, 1)) r = goal(Substitution()) assert list(r) == [Substitution({variables('x1'): 1})]
def test_fresh_no_vars(): goal = fresh(lambda: succeed) r = goal(Substitution()) assert list(r) == [Substitution()]
def cdro(l, d): return fresh(lambda a: same((a, d), l))
def listo(l): return disj(nullo(l), fresh(lambda d: (cdro(l, d), listo(d))))
def cdro(l, d): return fresh(lambda a: (same(a, l[0]), same(d, l[1:])))