Ejemplo n.º 1
0
def test_simple():
    tc = relation("tc")
    edge = relation("edge")
    program = [tc() <= edge()]
    abc_program = convert(program)
    strata_str = validate(abc_program)
    assert ['{tc}'] == strata_str
Ejemplo n.º 2
0
def test_no_stratification():
    p = relation("p")
    q = relation("q")
    program = [p() <= ~q(), q() <= ~p()]
    abc_program = convert(program)
    with pytest.raises(DatalogValidationException):
        validate(abc_program)
Ejemplo n.º 3
0
def test_simple_negated():
    p = relation("p")
    q = relation("q")
    program = [p() <= ~q()]
    abc_program = convert(program)
    strata_str = validate(abc_program)
    assert strata_str == ['{p}']

    pass
Ejemplo n.º 4
0
def test_pq():
    p = relation("p")
    q = relation('q')
    r = relation('r')

    program = [p() <= [q(), ~r()], q() <= r(), r() <= q()]
    abc_program = convert(program)
    strata_str = validate(abc_program)
    assert strata_str[-1] == '{p}'
Ejemplo n.º 5
0
def test_reachable():
    X = Variable("X")
    Y = Variable("Y")
    Z = Variable("Z")
    reachable = relation("reachable")
    edge = relation("edge")
    not_reachable = relation("not_reachable")
    node = relation("node")

    program = [
        reachable(X, Y) <= edge(X, Y),
        reachable(X, Y) <= [edge(X, Z), reachable(Z, Y)],
        not_reachable(X, Y) <= [node(X), node(Y), ~reachable(X, Y)],
        node(X) <= edge(X, _),
        node(X) <= edge(_, X)
    ]
    abc_program = convert(program)

    sorted_strata_str = validate(abc_program)
    exp = ['{reachable}', '{node}', '{not_reachable}']
    assert sorted_strata_str[-1] == exp[-1]