def test_disj_x_never(): x = variables("x") goal = disj(same("olive", x), never) s_inf = goal(Substitution()) assert next(s_inf) == Substitution({x: "olive"}) s_inf = assert_suspended(s_inf) s_inf = assert_suspended(s_inf)
def test_disj(): x = variables("x") goal = disj(same("olive", x), same("oil", x)) assert set(goal(Substitution())) == { Substitution({x: "olive"}), Substitution({x: "oil"}) }
def test_ifte_disj(): x, y = variables("x, y") goal = ifte(disj(same(True, x), same(False, x)), same(False, y), same(True, y)) assert list(goal(Substitution())) == [ Substitution({ x: True, y: False }), Substitution({ x: False, y: False }) ]
def test_reify_run_goal_inf(): x = variables("x") goal = disj(same("olive", x), same("oil", x)) results = map(reify(x), run_goal(goal)) assert list(results) == ['olive', 'oil']
def test_reify_some(): x = variables("x") goal = disj(same("olive", x), same("oil", x)) subs = take(5, goal(Substitution())) results = map(reify(x), subs) assert list(results) == ['olive', 'oil']
def teacupo(t): return disj(same('tea', t), same('cup', t))
def listo(l): return disj(nullo(l), fresh(lambda d: (cdro(l, d), listo(d))))