Esempio n. 1
0
def test_condeseq():
    x = var('x')
    assert set(run(0, x, condeseq(([eq(x, 2)], [eq(x, 3)])))) == {2, 3}
    assert set(run(0, x, condeseq([[eq(x, 2), eq(x, 3)]]))) == set()

    goals = ([eq(x, i)] for i in count())  # infinite number of goals
    assert run(1, x, condeseq(goals)) == (0, )
    assert run(1, x, condeseq(goals)) == (1, )
Esempio n. 2
0
 def goal(x, y, z):
     if not isvar(x) and not isvar(y):
         return eq(op(x, y), z)
     if not isvar(y) and not isvar(z) and revop:
         return eq(x, revop(z, y))
     if not isvar(x) and not isvar(z) and revop:
         return eq(y, revop(z, x))
     raise EarlyGoalError()
Esempio n. 3
0
def test_bindstar():
    x = var('x')
    stream = tuple({x: i} for i in range(5))
    success = lambda s: (s,)
    assert tuple(bindstar(stream, success)) == stream
    assert tuple(bindstar(stream, eq(x, 3))) == ({x: 3},)
    assert tuple(bindstar(stream, success, eq(x, 3))) == ({x: 3},)
    assert tuple(bindstar(stream, eq(x, 2), eq(x, 3))) == ()
Esempio n. 4
0
 def goal(x, y, z):
     if not isvar(x) and not isvar(y):
         return eq(op(x, y), z)
     if not isvar(y) and not isvar(z) and revop:
         return eq(x, revop(z, y))
     if not isvar(x) and not isvar(z) and revop:
         return eq(y, revop(z, x))
     raise EarlyGoalError()
Esempio n. 5
0
def test_run():
    x, y, z = map(var, "xyz")
    assert run(1, x, eq(x, 1)) == (1,)
    assert run(2, x, eq(x, 1)) == (1,)
    assert run(0, x, eq(x, 1)) == (1,)
    assert run(1, x, eq(x, (y, z)), eq(y, 3), eq(z, 4)) == ((3, 4),)
    assert set(run(2, x, conde([eq(x, 1)], [eq(x, 2)]))) == set((1, 2))
Esempio n. 6
0
def test_run():
    x, y, z = map(var, 'xyz')
    assert run(1, x, eq(x, 1)) == (1, )
    assert run(2, x, eq(x, 1)) == (1, )
    assert run(0, x, eq(x, 1)) == (1, )
    assert run(1, x, eq(x, (y, z)), eq(y, 3), eq(z, 4)) == ((3, 4), )
    assert set(run(2, x, conde([eq(x, 1)], [eq(x, 2)]))) == set((1, 2))
Esempio n. 7
0
def test_goaleval():
    x, y = var('x'), var('y')
    g = eq(x, 2)
    assert goaleval(g) == g
    assert callable(goaleval((eq, x, 2)))
    raises(EarlyGoalError, lambda: goaleval((membero, x, y)))
    assert callable(goaleval((lall, (eq, x, 2))))
Esempio n. 8
0
def test_goaleval():
    x, y = var("x"), var("y")
    g = eq(x, 2)
    assert goaleval(g) == g
    assert callable(goaleval((eq, x, 2)))
    raises(EarlyGoalError, lambda: goaleval((membero, x, y)))
    assert callable(goaleval((lall, (eq, x, 2))))
Esempio n. 9
0
def test_goaleval():
    x, y = var('x'), var('y')
    g = eq(x, 2)
    assert goaleval(g) == g
    assert callable(goaleval((eq, x, 2)))
    with raises(EarlyGoalError):
        goaleval((membero, x, y))
    assert callable(goaleval((lallgreedy, (eq, x, 2))))
Esempio n. 10
0
def buildo(op, args, obj):
    """ obj is composed of op on args

    Example: in add(1,2,3) ``add`` is the op and (1,2,3) are the args

    Checks op_regsitry for functions to define op/arg relationships
    """
    if not isvar(obj):
        oop, oargs = op_args(obj)
        return lall((eq, op, oop), (eq, args, oargs))
    else:
        try:
            return eq(obj, build(op, args))
        except TypeError:
            raise EarlyGoalError()
    raise EarlyGoalError()
Esempio n. 11
0
def test_lany():
    x = var("x")
    assert len(tuple(lany(eq(x, 2), eq(x, 3))({}))) == 2
    assert len(tuple(lany((eq, x, 2), (eq, x, 3))({}))) == 2
Esempio n. 12
0
def test_conde():
    x = var("x")
    assert results(conde([eq(x, 2)], [eq(x, 3)])) == ({x: 2}, {x: 3})
    assert results(conde([eq(x, 2), eq(x, 3)])) == ()
Esempio n. 13
0
def test_dict():
    x = var()
    assert run(0, x, eq({1: x}, {1: 2})) == (2,)
Esempio n. 14
0
def test_eq():
    x = var("x")
    assert tuple(eq(x, 2)({})) == ({x: 2},)
    assert tuple(eq(x, 2)({x: 3})) == ()
Esempio n. 15
0
def test_run_output_reify():
    x = var()
    assert run(0, (1, 2, x), eq(x, 3)) == ((1, 2, 3),)
Esempio n. 16
0
def gt(x, y):
    """ x > y """
    if not isvar(x) and not isvar(y):
        return eq(x > y, True)
    else:
        raise EarlyGoalError()
Esempio n. 17
0
def test_eq():
    x = var('x')
    assert tuple(eq(x, 2)({})) == ({x: 2}, )
    assert tuple(eq(x, 2)({x: 3})) == ()
Esempio n. 18
0
def test_dict():
    x = var()
    assert run(0, x, eq({1: x}, {1: 2})) == (2, )
Esempio n. 19
0
def test_conde():
    x = var('x')
    assert tuple(conde([eq(x, 2)], [eq(x, 3)])({})) == ({x: 2}, {x: 3})
    assert tuple(conde([eq(x, 2), eq(x, 3)])({})) == ()
Esempio n. 20
0
def test_lany():
    x = var('x')
    assert len(tuple(lany(eq(x, 2), eq(x, 3))({}))) == 2
    assert len(tuple(lany((eq, x, 2), (eq, x, 3))({}))) == 2
Esempio n. 21
0
def gt(x, y):
    """ x > y """
    if not isvar(x) and not isvar(y):
        return eq(x > y, True)
    else:
        raise EarlyGoalError()
Esempio n. 22
0
def test_run_output_reify():
    x = var()
    assert run(0, (1, 2, x), eq(x, 3)) == ((1, 2, 3), )
Esempio n. 23
0
def test_conde():
    x = var('x')
    assert results(conde([eq(x, 2)], [eq(x, 3)])) == ({x: 2}, {x: 3})
    assert results(conde([eq(x, 2), eq(x, 3)])) == ()