Ejemplo n.º 1
0
def test_names():

    good = ["a", "b", "name", "complex_name", "proposition10"]
    bad = ["Future", "X", "$", "", "40a", "niceName"]

    for name in good:
        str(PLTLfAtomic(name)) == name

    for name in bad:
        with pytest.raises(ValueError):
            str(PLTLfAtomic(name)) == name
Ejemplo n.º 2
0
def test_mona():
    parser = PLTLfParser()
    a, b, c = [PLTLfAtomic(c) for c in "abc"]
    tt = PLTLfTrue()
    ff = PLTLfFalse()

    assert a.to_mona(v="max($)") == "(max($) in A)"
    assert b.to_mona(v="max($)") == "(max($) in B)"
    assert c.to_mona(v="max($)") == "(max($) in C)"
    assert tt.to_mona(v="max($)") == "true"
    assert ff.to_mona(v="max($)") == "false"

    f = parser("!(a & !b)")
    assert f.to_mona(v="max($)") == "~(((max($) in A) & ~((max($) in B))))"

    f = parser("!(!a | b)")
    assert f.to_mona(v="max($)") == "~((~((max($) in A)) | (max($) in B)))"

    f = parser("!(a <-> b)")
    assert (
        f.to_nnf().to_mona(v="max($)") ==
        "((~((max($) in A)) | ~((max($) in B))) & ((max($) in A) | (max($) in B)))"
    )

    # Before
    f = parser("Y(a & b)")
    assert (
        f.to_mona(v="max($)") ==
        "(ex1 v_1: v_1 in $ & v_1=max($)-1 & max($)>0 & ((v_1 in A) & (v_1 in B)))"
    )

    # Since
    f = parser("a S b")
    assert (
        f.to_mona(v="max($)") ==
        "(ex1 v_1: v_1 in $ & 0<=v_1&v_1<=max($) & (v_1 in B) & (all1 v_2: v_2 in $ & v_1<v_2&v_2<=max($)"
        " => (v_2 in A)))")

    # Once and Historically
    f = parser("O(a & b)")
    assert (
        f.to_mona(v="max($)") ==
        "(ex1 v_1: v_1 in $ & 0<=v_1&v_1<=max($) & ((v_1 in A) & (v_1 in B)) & (all1 v_2: "
        "v_2 in $ & v_1<v_2&v_2<=max($) => true))")
    f = parser("a & O(b)")
    assert (
        f.to_mona(v="max($)") ==
        "((max($) in A) & (ex1 v_1: v_1 in $ & 0<=v_1&v_1<=max($) & (v_1 in B) & (all1 v_2: v_2 in $ & v_1<v_2&v_2<=max($) => "
        "true)))")
    f = parser("H(a | b)")
    assert (
        f.to_mona(v="max($)") ==
        "~((ex1 v_1: v_1 in $ & 0<=v_1&v_1<=max($) & ~(((v_1 in A) | (v_1 in B))) & (all1 v_2: "
        "v_2 in $ & v_1<v_2&v_2<=max($) => true)))")
Ejemplo n.º 3
0
def test_nnf():
    parser = PLTLfParser()
    a, b, c = [PLTLfAtomic(c) for c in "abc"]

    f = parser("!(a & !b)")
    assert f.to_nnf() == PLTLfOr([PLTLfNot(a), b])

    f = parser("!(!a | b)")
    assert f.to_nnf() == PLTLfAnd([a, PLTLfNot(b)])

    f = parser("!(a <-> b)")
    assert f.to_nnf() == PLTLfAnd(
        [PLTLfOr([PLTLfNot(a), PLTLfNot(b)]),
         PLTLfOr([a, b])])
Ejemplo n.º 4
0
def test_negate():
    parser = PLTLfParser()
    sa, sb, sc = "a", "b", "c"
    a, b, c = PLTLfAtomic(sa), PLTLfAtomic(sb), PLTLfAtomic(sc)

    a_and_b = PLTLfAnd([a, b])
    not_a_or_not_b = PLTLfOr([PLTLfNot(a), PLTLfNot(b)])
    assert a_and_b.negate() == not_a_or_not_b

    a_and_b_and_c = PLTLfAnd([a, b, c])
    not_a_or_not_b_or_not_c = PLTLfOr([PLTLfNot(a), PLTLfNot(b), PLTLfNot(c)])
    assert a_and_b_and_c.negate() == not_a_or_not_b_or_not_c

    before_a = PLTLfBefore(a)
    weakBefore_not_a = PLTLfWeakBefore(PLTLfNot(a))
    assert before_a.negate() == weakBefore_not_a

    once_a = PLTLfOnce(a)
    false_pastRelease_not_a = PLTLfPastRelease([PLTLfFalse(), PLTLfNot(a)])
    assert once_a.negate() == false_pastRelease_not_a

    historically_a = PLTLfHistorically(a)
    true_since_not_a = PLTLfSince([PLTLfTrue(), PLTLfNot(a)])
    assert historically_a.negate() == true_since_not_a
Ejemplo n.º 5
0
def test_parser():
    parser = PLTLfParser()
    a, b, c = [PLTLfAtomic(c) for c in "abc"]

    assert parser("!a | b <-> !(a & !b) <-> a->b") == PLTLfEquivalence([
        PLTLfOr([PLTLfNot(a), b]),
        PLTLfNot(PLTLfAnd([a, PLTLfNot(b)])),
        PLTLfImplies([a, b]),
    ])

    assert parser("(Y a)") == PLTLfBefore(a)

    assert parser("(O (a&b)) <-> !(H (!a | !b) )") == PLTLfEquivalence([
        PLTLfOnce(PLTLfAnd([a, b])),
        PLTLfNot(PLTLfHistorically(PLTLfOr([PLTLfNot(a),
                                            PLTLfNot(b)]))),
    ])

    assert parser("(a S b S !c)") == PLTLfSince([a, b, PLTLfNot(c)])
Ejemplo n.º 6
0
def test_nnf():
    parser = PLTLfParser()
    a, b, c = [PLTLfAtomic(c) for c in "abc"]

    f = parser("!(a & !b)")
    assert f.to_nnf() == PLTLfOr([PLTLfNot(a), b])

    f = parser("!(!a | b)")
    assert f.to_nnf() == PLTLfAnd([a, PLTLfNot(b)])

    f = parser("!(a <-> b)")
    assert f.to_nnf() == PLTLfAnd(
        [PLTLfOr([PLTLfNot(a), PLTLfNot(b)]),
         PLTLfOr([a, b])])

    # Yesterday and Weak Yesterday
    f = parser("!(Y (a & b))")
    assert f.to_nnf() == PLTLfWeakBefore(PLTLfOr([PLTLfNot(a), PLTLfNot(b)]))

    f = parser("!(WY (a & b))")
    assert f.to_nnf() == PLTLfBefore(PLTLfOr([PLTLfNot(a), PLTLfNot(b)]))

    # Once and Historically
    f = parser("!(O (a | b))")
    assert (f.to_nnf() == PLTLfHistorically(
        PLTLfAnd([PLTLfNot(a), PLTLfNot(b)])).to_nnf())

    # Since
    f = parser("!(a S b)")
    assert f.to_nnf() == PLTLfPastRelease([PLTLfNot(a), PLTLfNot(b)])
    f = parser("!(a P b)")
    assert f.to_nnf() == PLTLfSince([PLTLfNot(a), PLTLfNot(b)])

    f = parser("!(O (a | b))")
    assert (f.to_nnf() == PLTLfHistorically(
        PLTLfAnd([PLTLfNot(a), PLTLfNot(b)])).to_nnf())
    f = parser("!(H (a | b))")
    assert f.to_nnf() == PLTLfOnce(PLTLfAnd([PLTLfNot(a),
                                             PLTLfNot(b)])).to_nnf()
Ejemplo n.º 7
0
 def pltlf_symbol(self, args):
     """Parse PLTLf Symbol."""
     assert len(args) == 1
     token = args[0]
     symbol = str(token)
     return PLTLfAtomic(symbol)