Esempio n. 1
0
def test_membero():
    x = var('x')
    assert set(run(5, x, membero(x, (1, 2, 3)), membero(x, (2, 3, 4)))) \
           == {2, 3}

    assert run(5, x, membero(2, (1, x, 3))) == (2, )
    assert run(0, x, (membero, 1, (1, 2, 3))) == (x, )
    assert run(0, x, (membero, 1, (2, 3))) == ()
Esempio n. 2
0
def test_membero():
    x = var('x')
    assert set(run(5, x, membero(x, (1, 2, 3)), membero(x, (2, 3, 4)))) \
           == {2, 3}

    assert run(5, x, membero(2, (1, x, 3))) == (2, )
    assert run(0, x, (membero, 1, (1, 2, 3))) == (x, )
    assert run(0, x, (membero, 1, (2, 3))) == ()
Esempio n. 3
0
def test_uneval_membero():
    x, y = var(), var()
    assert set(run(100, x, membero(y, ((1, 2, 3), (4, 5, 6))),
                   membero(x, y))) == {
                       1,
                       2,
                       3,
                       4,
                       5,
                       6,
                   }
Esempio n. 4
0
def test_lall(lall_impl):
    x, y = var('x'), var('y')
    assert results(lall_impl((eq, x, 2))) == ({x: 2}, )
    assert results(lall_impl((eq, x, 2), (eq, x, 3))) == ()
    assert results(lall_impl()) == ({}, )

    assert run(0, x, lall_impl((eq, y, (1, 2)), (membero, x, y)))
    assert run(0, x, lall_impl()) == (x, )
    with pytest.raises(EarlyGoalError):
        run(0, x, lall_impl(membero(x, y)))
Esempio n. 5
0
def test_typeo_basic():
    a_lv, q_lv = var(), var()

    assert run(0, q_lv, typeo(q_lv, int)) == (q_lv,)
    assert run(0, q_lv, typeo(1, int)) == (q_lv,)
    assert run(0, q_lv, typeo(1, str)) == ()
    assert run(0, q_lv, typeo("hi", str)) == (q_lv,)
    assert run(0, q_lv, typeo([], q_lv)) == (q_lv,)
    # Invalid second arg type (i.e. not a type)
    assert run(0, q_lv, typeo(1, 1)) == ()
    assert run(0, q_lv, membero(q_lv, (1, "cat", 2.2, "hat")), typeo(q_lv, str)) == (
        "cat",
        "hat",
    )

    with raises(ValueError):
        run(0, q_lv, typeo(a_lv, str), typeo(a_lv, int))
Esempio n. 6
0
def test_membero():
    x, y = var(), var()

    assert set(run(5, x, membero(x, (1, 2, 3)), membero(x,
                                                        (2, 3, 4)))) == {2, 3}

    assert run(5, x, membero(2, (1, x, 3))) == (2, )
    assert run(0, x, membero(1, (1, 2, 3))) == (x, )
    assert run(0, x, membero(1, (2, 3))) == ()

    g = membero(x, (0, 1, 2))
    assert tuple(r[x] for r in g({})) == (0, 1, 2)

    def in_cons(x, y):
        if issubclass(type(y), ConsPair):
            return x == y.car or in_cons(x, y.cdr)
        else:
            return False

    res = run(4, x, membero(1, x))
    assert all(in_cons(1, r) for r in res)

    res = run(4, (x, y), membero(x, y))
    assert all(in_cons(i, r) for i, r in res)
Esempio n. 7
0
def test_membero_can_be_reused():
    g = membero(x, (0, 1, 2))
    assert list(goaleval(g)({})) == [{x: 0}, {x: 1}, {x: 2}]
    assert list(goaleval(g)({})) == [{x: 0}, {x: 1}, {x: 2}]
Esempio n. 8
0
 def lefto(q, p, lst):
     if isvar(lst):
         raise EarlyGoalError()
     return membero((q, p), zip(lst, lst[1:]))
Esempio n. 9
0
def test_typo():
    assert results(typo(3, int))
    assert not results(typo(3.3, int))
    assert run(0, x, membero(x, (1, 'cat', 2.2, 'hat')), (typo, x, str)) ==\
            ('cat', 'hat')
Esempio n. 10
0
def test_membero_can_be_reused():
    g = membero(x, (0, 1, 2))
    assert list(goaleval(g)({})) == [{x: 0}, {x: 1}, {x: 2}]
    assert list(goaleval(g)({})) == [{x: 0}, {x: 1}, {x: 2}]
Esempio n. 11
0
 def lefto(q, p, lst):
     if isvar(lst):
         raise EarlyGoalError()
     return membero((q, p), zip(lst, lst[1:]))
Esempio n. 12
0
def test_typo():
    assert results(typo(3, int))
    assert not results(typo(3.3, int))
    assert run(0, x, membero(x, (1, 'cat', 2.2, 'hat')), (typo, x, str)) ==\
            ('cat', 'hat')