Beispiel #1
0
    def test_k(self):
        fsm = self.simplemodel()

        lt = eval_simple_expression(fsm, "at.local")
        lf = eval_simple_expression(fsm, "af.local")
        g = eval_simple_expression(fsm, "global")
        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        specs = parseCTLK("K<'at'> 'at.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        katt = evalCTLK(fsm, spec)
        self.assertEqual(katt, lt)

        specs = parseCTLK("K<'at'> 'af.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        katf = evalCTLK(fsm, spec)
        self.assertEqual(katf, false)

        specs = parseCTLK("K<'at'> 'global'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        katf = evalCTLK(fsm, spec)
        self.assertEqual(katf, g)
Beispiel #2
0
    def test_ex(self):
        fsm = self.model()

        c1p = eval_simple_expression(fsm, "c1.payer")
        c2p = eval_simple_expression(fsm, "c2.payer")
        c3p = eval_simple_expression(fsm, "c3.payer")
        c1h = eval_simple_expression(fsm, "c1.coin = head")
        c2h = eval_simple_expression(fsm, "c2.coin = head")
        c3h = eval_simple_expression(fsm, "c3.coin = head")
        odd = eval_simple_expression(fsm, "countsay = odd")
        unk = eval_simple_expression(fsm, "countsay = unknown")

        specs = parseCTLK("EX ('c1.payer' & ~'c2.payer' & ~'c3.payer')")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        ex = evalCTLK(fsm, spec)
        self.assertEqual(ex, c1p & ~c2p & ~c3p & fsm.bddEnc.statesMask)

        specs = parseCTLK("EX 'countsay = odd'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        ex = evalCTLK(fsm, spec)

        self.assertTrue(odd & fsm.bddEnc.statesMask <= ex)
        self.assertTrue(
            (unk & c1p & ~c2p & ~c3p) & fsm.bddEnc.statesMask <= ex)
        self.assertTrue((unk & c1p & c2p & c3p) & fsm.bddEnc.statesMask <= ex)
Beispiel #3
0
    def test_d_simple(self):
        fsm = self.simplemodel()

        lt = eval_simple_expression(fsm, "at.local")
        lf = eval_simple_expression(fsm, "af.local")
        g = eval_simple_expression(fsm, "global")
        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        specs = parseCTLK("'af.local' -> D<'at','af'> 'af.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        geg = evalCTLK(fsm, spec)
        self.assertEqual(geg, true)

        specs = parseCTLK("'af.local' & D<'at'> 'af.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        geg = evalCTLK(fsm, spec)
        self.assertEqual(geg, false)

        specs = parseCTLK("'af.local' -> D<'af'> 'af.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        geg = evalCTLK(fsm, spec)
        self.assertEqual(geg, true)
Beispiel #4
0
    def test_e_dincry(self):
        fsm = self.model()

        c1p = eval_simple_expression(fsm, "c1.payer")
        c2p = eval_simple_expression(fsm, "c2.payer")
        c3p = eval_simple_expression(fsm, "c3.payer")
        c1h = eval_simple_expression(fsm, "c1.coin = head")
        c2h = eval_simple_expression(fsm, "c2.coin = head")
        c3h = eval_simple_expression(fsm, "c3.coin = head")
        odd = eval_simple_expression(fsm, "countsay = odd")
        even = eval_simple_expression(fsm, "countsay = even")
        unk = eval_simple_expression(fsm, "countsay = unknown")
        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        specs = parseCTLK("'countsay = even' -> E<'c1','c2'> ~'c1.payer'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        een1 = evalCTLK(fsm, spec)
        self.assertEqual(een1, true)

        specs = parseCTLK("E<'c2','c3'> ~'c1.payer'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        en1 = evalCTLK(fsm, spec)
        self.assertTrue(even & fsm.reachable_states <= en1)
Beispiel #5
0
    def test_c_dincry(self):
        fsm = self.model()

        c1p = eval_simple_expression(fsm, "c1.payer")
        c2p = eval_simple_expression(fsm, "c2.payer")
        c3p = eval_simple_expression(fsm, "c3.payer")
        c1h = eval_simple_expression(fsm, "c1.coin = head")
        c2h = eval_simple_expression(fsm, "c2.coin = head")
        c3h = eval_simple_expression(fsm, "c3.coin = head")
        odd = eval_simple_expression(fsm, "countsay = odd")
        even = eval_simple_expression(fsm, "countsay = even")
        unk = eval_simple_expression(fsm, "countsay = unknown")
        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        specs = parseCTLK("'countsay = odd' -> "
                          "C<'c1','c2','c3'> "
                          "('c1.payer' | 'c2.payer' | 'c3.payer')")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        oc123 = evalCTLK(fsm, spec)
        self.assertTrue(fsm.reachable_states <= oc123)

        specs = parseCTLK("'countsay = even' -> "
                          "C<'c1','c2','c3'> "
                          "(~'c1.payer' & ~'c2.payer' & ~'c3.payer')")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        ec123 = evalCTLK(fsm, spec)
        self.assertTrue(fsm.reachable_states <= ec123)
Beispiel #6
0
 def test_full_witness(self):
     fsm = self.model()
     
     spec = parseCTLK("EF (EX nK<'c1'> 'c2.payer' & EG nD<'c1','c2'> 'c3.payer')")[0]
     self.assertIsNotNone(spec)
     state = fsm.pick_one_state(fsm.init & evalCTLK(fsm, spec))
     self.assertIsNotNone(state)
     
     expl = explain_witness(fsm, state, spec)
     self.assertIsNotNone(expl)
     
     
     spec = parseCTLK("E[nE<'c1','c2'> 'c3.payer' U"
                     " E[ nC<'c1','c3'> ('c1.payer' | 'c2.payer') W"
                     " nC<'c2'> ('c1.coin = head' <-> 'c2.coin = head')]]")[0]
     self.assertIsNotNone(spec)
     state = fsm.pick_one_state(fsm.init & evalCTLK(fsm, spec))
     self.assertIsNotNone(state)
     
     expl = explain_witness(fsm, state, spec)
     self.assertIsNotNone(expl)
     
     
     spec = parseCTLK("AG(~'c1.payer' | E<'c1'> ('c1.payer' -> "
                      "C<'c2','c3'> AF 'c1.payer'))")[0]
     self.assertIsNotNone(spec)
     state = fsm.pick_one_state(fsm.init & evalCTLK(fsm, spec))
     self.assertIsNotNone(state)
     
     expl = explain_witness(fsm, state, spec)
     self.assertIsNotNone(expl)
Beispiel #7
0
    def test_full_countex(self):
        fsm = self.model()

        spec = parseCTLK("'c2.payer' -> A[AX ('c1.payer' | ~'c1.payer')"
                         " U K<'c1'> ('c2.payer')]")[0]
        self.assertIsNotNone(spec)
        self.assertTrue((fsm.init & ~evalCTLK(fsm, spec)).isnot_false())
        state = fsm.pick_one_state(fsm.init & ~evalCTLK(fsm, spec))
        self.assertIsNotNone(state)

        expl = explain_countex(fsm, state, spec)
        self.assertIsNotNone(expl)

        print(xml_countex(fsm, expl, spec))

        spec = parseCTLK("AG(~'c1.payer' | E<'c1'> ('c1.payer' -> "
                         "C<'c2','c3'> AF 'c1.payer'))")[0]
        self.assertIsNotNone(spec)
        self.assertTrue((fsm.init & ~evalCTLK(fsm, spec)).isnot_false())
        state = fsm.pick_one_state(fsm.init & ~evalCTLK(fsm, spec))
        self.assertIsNotNone(state)

        expl = explain_countex(fsm, state, spec)
        self.assertIsNotNone(expl)

        print(xml_countex(fsm, expl, spec))
Beispiel #8
0
    def test_fail(self):
        kos = [
            "", "'test", "A<'test'>H 'q'", "O", "A<'a'>E<'e'>G 'true'",
            "E<'ac'>[A<'ac'>['a' E<'ac'>['b' W 'c'] W 'd'] "
            "U A<'ac'>['e' U 'f']]", "A<'t't'>G 'q'"
        ]

        for s in kos:
            with self.assertRaises(ParseException):
                parseCTLK(s)
Beispiel #9
0
    def test_weird(self):
        s = """
            AF (
                (K<'c1'> (AF (K<'c1'> 'c2.payer' | K<'c1'> ~'c2.payer')))
                |
                (K<'c1'> (~AF (K<'c1'> 'c2.payer' | K<'c1'> ~'c2.payer')))
               )
            """
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), AF)
        self.assertEqual(type(ast.child), Or)
        self.assertEqual(type(ast.child.left), K)
        self.assertEqual(type(ast.child.left.agent), Atom)
        self.assertEqual(ast.child.left.agent.value, "c1")
        self.assertEqual(type(ast.child.left.child), AF)
        self.assertEqual(type(ast.child.left.child.child), Or)
        self.assertEqual(type(ast.child.left.child.child.left), K)
        self.assertEqual(type(ast.child.left.child.child.right), K)
        self.assertEqual(type(ast.child.left.child.child.right.agent), Atom)
        self.assertEqual(ast.child.left.child.child.right.agent.value, "c1")
        self.assertEqual(type(ast.child.left.child.child.right.child), Not)
        self.assertEqual(type(ast.child.left.child.child.right.child.child),
                         Atom)
        self.assertEqual(ast.child.left.child.child.right.child.child.value,
                         "c2.payer")
        self.assertEqual(type(ast.child.right), K)
Beispiel #10
0
    def test_eu_d(self):
        s = "E[D<'a'>'r' & 'd' U 's' | nD<'b','c'> 'q']"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), EU)
        self.assertEqual(type(ast.left), And)
        self.assertEqual(type(ast.left.left), D)
        self.assertEqual(type(ast.left.left.group), list)
        self.assertEqual(len(ast.left.left.group), 1)
        self.assertEqual(type(ast.left.left.group[0]), Atom)
        self.assertEqual(ast.left.left.group[0].value, "a")
        self.assertEqual(type(ast.left.right), Atom)
        self.assertEqual(ast.left.right.value, "d")
        self.assertEqual(type(ast.right), Or)
        self.assertEqual(type(ast.right.left), Atom)
        self.assertEqual(ast.right.left.value, "s")
        self.assertEqual(type(ast.right.right), nD)
        self.assertEqual(type(ast.right.right.group), list)
        self.assertEqual(len(ast.right.right.group), 2)
        self.assertEqual(type(ast.right.right.group[0]), Atom)
        self.assertEqual(ast.right.right.group[0].value, "b")
        self.assertEqual(type(ast.right.right.group[1]), Atom)
        self.assertEqual(ast.right.right.group[1].value, "c")
        self.assertEqual(type(ast.right.right.child), Atom)
        self.assertEqual(ast.right.right.child.value, "q")
Beispiel #11
0
    def test_logicals(self):
        s = "'a' & 'c' -> (~'b' | 'c')"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertTrue(isinstance(ast, Spec))
        self.assertTrue(isinstance(ast, Implies))
        self.assertTrue(isinstance(ast.left, Spec))
        self.assertTrue(isinstance(ast.left, And))
        self.assertTrue(isinstance(ast.left.left, Spec))
        self.assertTrue(isinstance(ast.left.left, Atom))
        self.assertEqual(ast.left.left.value, "a")
        self.assertTrue(isinstance(ast.left.right, Spec))
        self.assertTrue(isinstance(ast.left.right, Atom))
        self.assertEqual(ast.left.right.value, "c")
        self.assertTrue(isinstance(ast.right, Spec))
        self.assertTrue(isinstance(ast.right, Or))
        self.assertTrue(isinstance(ast.right.left, Spec))
        self.assertTrue(isinstance(ast.right.left, Not))
        self.assertTrue(isinstance(ast.right.left.child, Spec))
        self.assertTrue(isinstance(ast.right.left.child, Atom))
        self.assertEqual(ast.right.left.child.value, "b")
        self.assertTrue(isinstance(ast.right.right, Spec))
        self.assertTrue(isinstance(ast.right.right, Atom))
        self.assertEqual(ast.right.right.value, "c")
Beispiel #12
0
    def test_init(self):
        fsm = self.model()

        specs = parseCTLK("Init")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        self.assertEqual(fsm.init, evalCTLK(fsm, spec))
Beispiel #13
0
    def test_false(self):
        s = "False"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertTrue(isinstance(ast, Spec))
        self.assertTrue(isinstance(ast, FalseExp))
Beispiel #14
0
    def test_reachable(self):
        fsm = self.model()

        specs = parseCTLK("Reachable")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        self.assertEqual(fsm.reachable_states, evalCTLK(fsm, spec))
Beispiel #15
0
    def test_reachable(self):
        s = "Reachable"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertTrue(isinstance(ast, Spec))
        self.assertTrue(isinstance(ast, Reachable))
Beispiel #16
0
    def test_init(self):
        s = "Init"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertTrue(isinstance(ast, Spec))
        self.assertTrue(isinstance(ast, Init))
Beispiel #17
0
    def test_atom(self):
        s = "'c <= 3'"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertTrue(isinstance(ast, Spec))
        self.assertTrue(isinstance(ast, Atom))
        self.assertEqual(ast.value, "c <= 3")
Beispiel #18
0
    def test_ex(self):
        s = "EX 'a'"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), EX)
        self.assertEqual(type(ast.child), Atom)
        self.assertEqual(ast.child.value, "a")
Beispiel #19
0
    def test_full(self):
        s = """
            A[
                K<'a'> EF Init
                &
                AG E<'a','b'> (True | 'r')
            U
                nC<'c','a'> E['s' W False -> AX 's']
            ] -> Reachable
            """
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), Implies)
        self.assertEqual(type(ast.left), AU)
        self.assertEqual(type(ast.left.left), And)

        # K<'a'> EF Init
        self.assertEqual(type(ast.left.left.left), K)
        self.assertEqual(type(ast.left.left.left.agent), Atom)
        self.assertEqual(ast.left.left.left.agent.value, "a")
        self.assertEqual(type(ast.left.left.left.child), EF)
        self.assertEqual(type(ast.left.left.left.child.child), Init)

        # AG E<'a','b'> (True | 'r')
        self.assertEqual(type(ast.left.left.right), AG)
        self.assertEqual(type(ast.left.left.right.child), E)
        self.assertEqual(type(ast.left.left.right.child.group), list)
        self.assertEqual(len(ast.left.left.right.child.group), 2)
        self.assertEqual(type(ast.left.left.right.child.group[0]), Atom)
        self.assertEqual(ast.left.left.right.child.group[0].value, "a")
        self.assertEqual(type(ast.left.left.right.child.group[1]), Atom)
        self.assertEqual(ast.left.left.right.child.group[1].value, "b")
        self.assertEqual(type(ast.left.left.right.child.child), Or)
        self.assertEqual(type(ast.left.left.right.child.child.left), TrueExp)
        self.assertEqual(type(ast.left.left.right.child.child.right), Atom)
        self.assertEqual(ast.left.left.right.child.child.right.value, "r")

        # nC<'c','a'> E['s' W False -> AX 's']
        self.assertEqual(type(ast.left.right), nC)
        self.assertEqual(type(ast.left.right.group), list)
        self.assertEqual(len(ast.left.right.group), 2)
        self.assertEqual(type(ast.left.right.group[0]), Atom)
        self.assertEqual(ast.left.right.group[0].value, "c")
        self.assertEqual(type(ast.left.right.group[1]), Atom)
        self.assertEqual(ast.left.right.group[1].value, "a")
        self.assertEqual(type(ast.left.right.child), EW)
        self.assertEqual(type(ast.left.right.child.left), Atom)
        self.assertEqual(ast.left.right.child.left.value, "s")
        self.assertEqual(type(ast.left.right.child.right), Implies)
        self.assertEqual(type(ast.left.right.child.right.left), FalseExp)
        self.assertEqual(type(ast.left.right.child.right.right), AX)
        self.assertEqual(type(ast.left.right.child.right.right.child), Atom)
        self.assertEqual(ast.left.right.child.right.right.child.value, "s")

        self.assertEqual(type(ast.right), Reachable)
Beispiel #20
0
    def test_false(self):
        fsm = self.model()

        false = eval_simple_expression(fsm, "FALSE")

        specs = parseCTLK("False")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        self.assertEqual(false, evalCTLK(fsm, spec))
Beispiel #21
0
    def test_true(self):
        fsm = self.model()

        true = eval_simple_expression(fsm, "TRUE")

        specs = parseCTLK("True")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        self.assertEqual(true, evalCTLK(fsm, spec))
Beispiel #22
0
    def test_k_ex(self):
        fsm = self.simplemodel()

        lt = eval_simple_expression(fsm, "at.local")
        lf = eval_simple_expression(fsm, "af.local")
        g = eval_simple_expression(fsm, "global")
        true = eval_simple_expression(fsm, "TRUE")

        specs = parseCTLK("K<'at'> EX 'global'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        kex = evalCTLK(fsm, spec)
        self.assertEqual(kex, true)

        specs = parseCTLK("K<'at'> EX ~'global'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        kexn = evalCTLK(fsm, spec)
        self.assertEqual(kexn, true)
Beispiel #23
0
    def test_not(self):
        fsm = self.model()

        c1p = eval_simple_expression(fsm, "c1.payer")

        specs = parseCTLK("~'c1.payer'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        c1pCTLK = evalCTLK(fsm, spec)
        self.assertEqual(~c1p, c1pCTLK)
Beispiel #24
0
    def test_not(self):
        s = "~'a'"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertTrue(isinstance(ast, Spec))
        self.assertTrue(isinstance(ast, Not))
        self.assertTrue(isinstance(ast.child, Spec))
        self.assertTrue(isinstance(ast.child, Atom))
        self.assertEqual(ast.child.value, "a")
Beispiel #25
0
    def test_k(self):
        s = "K<'c'> 'a'"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), K)
        self.assertEqual(type(ast.agent), Atom)
        self.assertEqual(ast.agent.value, "c")
        self.assertEqual(type(ast.child), Atom)
        self.assertEqual(ast.child.value, "a")
Beispiel #26
0
    def test_and(self):
        fsm = self.model()

        c1p = eval_simple_expression(fsm, "c1.payer")
        odd = eval_simple_expression(fsm, "countsay = odd")

        specs = parseCTLK("'c1.payer' & 'countsay = odd'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        c1paco = evalCTLK(fsm, spec)
        self.assertEqual(c1p & odd, c1paco)
Beispiel #27
0
    def test_implies(self):
        fsm = self.model()

        c1p = eval_simple_expression(fsm, "c1.payer")
        odd = eval_simple_expression(fsm, "countsay = odd")

        specs = parseCTLK("'c1.payer' -> 'countsay = odd'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]

        c1pico = evalCTLK(fsm, spec)
        self.assertEqual(c1p.imply(odd), c1pico)
Beispiel #28
0
    def test_ex_and(self):
        s = "EX 'a' & 'b'"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), And)
        self.assertEqual(type(ast.left), EX)
        self.assertEqual(type(ast.left.child), Atom)
        self.assertEqual(ast.left.child.value, "a")
        self.assertEqual(type(ast.right), Atom)
        self.assertEqual(ast.right.value, "b")
Beispiel #29
0
    def test_epistemic_temporal_logical(self):
        s = "nK<'ag'> AX ~'b'"
        asts = parseCTLK(s)
        self.assertEqual(len(asts), 1)

        ast = asts[0]
        self.assertEqual(type(ast), nK)
        self.assertEqual(type(ast.agent), Atom)
        self.assertEqual(ast.agent.value, "ag")
        self.assertEqual(type(ast.child), AX)
        self.assertEqual(type(ast.child.child), Not)
        self.assertEqual(type(ast.child.child.child), Atom)
        self.assertEqual(ast.child.child.child.value, "b")
Beispiel #30
0
    def test_simple_ex(self):
        fsm = self.simplemodel()

        lt = eval_simple_expression(fsm, "at.local")
        lf = eval_simple_expression(fsm, "af.local")
        g = eval_simple_expression(fsm, "global")

        specs = parseCTLK("EX 'af.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        ex = evalCTLK(fsm, spec)
        # ex :
        #  l1, !l2, !g
        #  !l1, l2, g
        #  l1, l2, g
        #  !l1, !l2, !g
        self.assertEqual(ex, lf.iff(g))

        specs = parseCTLK("EX ('af.local' & 'at.local' & 'global')")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        ex = evalCTLK(fsm, spec)
        self.assertEqual(ex, lt & ~lf & ~g | ~lt & lf & g)