Ejemplo n.º 1
0
    def test_dining_crypto(self):
        glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")
        fsm = glob.mas()
        self.assertIsNotNone(fsm)

        agents = fsm._epistemic.keys()
        self.assertSetEqual(set(agents), {"c1", "c2", "c3"})
Ejemplo n.º 2
0
    def test_reachable_states_for_simple_model(self):
        glob.load_from_file("tests/tools/ctlk/agents.smv")
        fsm = glob.mas()
        self.assertIsNotNone(fsm)

        true = eval_simple_expression(fsm, "TRUE")
        self.assertEqual(fsm.reachable_states, true)
Ejemplo n.º 3
0
 def test_constraints_post(self):
     glob.load_from_file("tests/tools/ctlk/constraints.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     
     false = eval_simple_expression(fsm, "FALSE")
     false = eval_simple_expression(fsm, "TRUE")
     p = eval_simple_expression(fsm, "p")
     q = eval_simple_expression(fsm, "q")
     a = eval_simple_expression(fsm, "a")
     
     self.assertEqual(1, fsm.count_states(fsm.init))
     self.assertEqual(2, fsm.count_states(fsm.post(fsm.init)))
     self.assertEqual(1, fsm.count_states(p & q))
     self.assertEqual(1, fsm.count_states(p & ~q))
     self.assertEqual(1, fsm.count_states(~p & q))
     self.assertEqual(1, fsm.count_states(~p & ~q))
     
     self.assertEqual(2, fsm.count_states(fsm.post(p & q)))
     self.assertEqual(1, fsm.count_states(fsm.post(p & ~q)))
     self.assertEqual(1, fsm.count_states(fsm.post(~p & q)))
     self.assertEqual(1, fsm.count_states(fsm.post(p & q, a)))
     self.assertEqual(0, fsm.count_states(fsm.post(p & ~q, ~a)))
     self.assertEqual(0, fsm.count_states(fsm.post(~p & q, a)))
     self.assertEqual(1, fsm.count_states(fsm.post(~p & q, ~a)))
Ejemplo n.º 4
0
 def test_reachable_states_for_simple_model(self):
     glob.load_from_file("tests/tools/ctlk/agents.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     
     true = eval_simple_expression(fsm, "TRUE")
     self.assertEqual(fsm.reachable_states, true)
Ejemplo n.º 5
0
    def test_constraints_post(self):
        glob.load_from_file("tests/tools/ctlk/constraints.smv")
        fsm = glob.mas()
        self.assertIsNotNone(fsm)

        false = eval_simple_expression(fsm, "FALSE")
        false = eval_simple_expression(fsm, "TRUE")
        p = eval_simple_expression(fsm, "p")
        q = eval_simple_expression(fsm, "q")
        a = eval_simple_expression(fsm, "a")

        self.assertEqual(1, fsm.count_states(fsm.init))
        self.assertEqual(2, fsm.count_states(fsm.post(fsm.init)))
        self.assertEqual(1, fsm.count_states(p & q))
        self.assertEqual(1, fsm.count_states(p & ~q))
        self.assertEqual(1, fsm.count_states(~p & q))
        self.assertEqual(1, fsm.count_states(~p & ~q))

        self.assertEqual(2, fsm.count_states(fsm.post(p & q)))
        self.assertEqual(1, fsm.count_states(fsm.post(p & ~q)))
        self.assertEqual(1, fsm.count_states(fsm.post(~p & q)))
        self.assertEqual(1, fsm.count_states(fsm.post(p & q, a)))
        self.assertEqual(0, fsm.count_states(fsm.post(p & ~q, ~a)))
        self.assertEqual(0, fsm.count_states(fsm.post(~p & q, a)))
        self.assertEqual(1, fsm.count_states(fsm.post(~p & q, ~a)))
Ejemplo n.º 6
0
 def test_dining_crypto(self):
     glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     
     agents = fsm._epistemic.keys()
     self.assertSetEqual(set(agents), {"c1", "c2", "c3"})
Ejemplo n.º 7
0
 def test_cardgame_with_agents(self):
     glob.load_from_file("tests/tools/mas/cardgame.smv")
     agents = (Agent("player", {"step", "pcard", "ddcard"},
                     {"player.action"}),
               Agent("dealer", {"step", "pcard", "dcard"},
                     {"dealer.action"}))
     fsm = glob.mas(agents=agents)
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 8
0
 def test_cardgame_with_agents(self):
     glob.load_from_file("tests/tools/mas/cardgame.smv")
     agents = (Agent("player", {"step", "pcard", "ddcard"},
                     {"player.action"}),
               Agent("dealer", {"step", "pcard", "dcard"},
                     {"dealer.action"}))
     fsm = glob.mas(agents=agents)
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 9
0
 def test_simple_pre(self):
     glob.load_from_file("tests/tools/ctlk/agents.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     
     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")
     
     self.assertEqual(fsm.pre(lt & ~lf & ~g),
                      (lt & lf & ~g) | (~lt & ~lf & g))
     self.assertEqual(fsm.pre(g), true)
     self.assertEqual(fsm.pre(lf), lf.iff(g))
Ejemplo n.º 10
0
    def test_simple_pre(self):
        glob.load_from_file("tests/tools/ctlk/agents.smv")
        fsm = glob.mas()
        self.assertIsNotNone(fsm)

        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")

        self.assertEqual(fsm.pre(lt & ~lf & ~g),
                         (lt & lf & ~g) | (~lt & ~lf & g))
        self.assertEqual(fsm.pre(g), true)
        self.assertEqual(fsm.pre(lf), lf.iff(g))
Ejemplo n.º 11
0
    def test_d_distributedmodel(self):
        glob.load_from_file("tests/tools/ctlk/distributed_knowledge.smv")
        fsm = glob.mas()
        self.assertIsNotNone(fsm)

        l1 = eval_simple_expression(fsm, "a1.local")
        l2 = eval_simple_expression(fsm, "a2.local")
        l3 = eval_simple_expression(fsm, "a3.local")
        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        specs = parseCTLK("'a1.local' -> D<'a1','a2'> 'a1.local'")
        self.assertEqual(len(specs), 1)
        spec = specs[0]
        a1da1 = evalCTLK(fsm, spec)
        self.assertEqual(true, a1da1)
Ejemplo n.º 12
0
 def test_d_distributedmodel(self):  
     glob.load_from_file("tests/tools/ctlk/distributed_knowledge.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     
     l1 = eval_simple_expression(fsm, "a1.local")
     l2 = eval_simple_expression(fsm, "a2.local")
     l3 = eval_simple_expression(fsm, "a3.local")
     true = eval_simple_expression(fsm, "TRUE")
     false = eval_simple_expression(fsm, "FALSE")
     
     specs = parseCTLK("'a1.local' -> D<'a1','a2'> 'a1.local'")
     self.assertEqual(len(specs), 1)
     spec = specs[0]
     a1da1 = evalCTLK(fsm, spec)        
     self.assertEqual(true, a1da1)
Ejemplo n.º 13
0
 def test_next_state_without_inputs(self):
     glob.load_from_file("tests/pynusmv/models/modules.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     c2p = eval_simple_expression(fsm, "top")
     (inputs, state) = choose_next_state(fsm, fsm.pick_one_state(fsm.init))
     
     print()
     if state is None:
         print("No chosen state.")
     else:
         if inputs is not None:
             values = inputs.get_str_values()
             for var in values:
                 print(var, "=", values[var])
             print("-" * 40)
         values = state.get_str_values()
         for var in values:
             print(var, "=", values[var])
Ejemplo n.º 14
0
    def test_next_state_without_inputs(self):
        glob.load_from_file("tests/pynusmv/models/modules.smv")
        fsm = glob.mas()
        self.assertIsNotNone(fsm)
        c2p = eval_simple_expression(fsm, "top")
        (inputs, state) = choose_next_state(fsm, fsm.pick_one_state(fsm.init))

        print()
        if state is None:
            print("No chosen state.")
        else:
            if inputs is not None:
                values = inputs.get_str_values()
                for var in values:
                    print(var, "=", values[var])
                print("-" * 40)
            values = state.get_str_values()
            for var in values:
                print(var, "=", values[var])
Ejemplo n.º 15
0
 def do_model(self, arg):
     if "model" not in self.argparsers:
         self.parse_model()
     
     # Handle arguments parsing errors
     try:
         args = self.argparsers["model"].parse_args(self._split_escaped(arg))
     except ArgumentParsingError as err:
         print(err, end="")
         return False
     
     # Error if
     #   showing path or content when nothing is read
     #   reading a file when one is already read
     
     if (args.content or args.path is None) and self.model is None:
         print("No read model.")
         return False
     
     if args.path is not None and self.model is not None:
         print("model: error: a model is already read from", self.model.path)
         return False
         
     if args.path is None:
         print("read model:", self.model.path)
         
     if args.content:
         print(self.model.content)
         
     if args.path is not None:
         try:
             f = open(args.path, 'r')
             content = f.read()
             f.close()
             glob.load_from_file(args.path)
             self.fsm = glob.mas()
             self.model = Model(args.path, content)
         except PyNuSMVError as err:
             print("model: error:", err)
         except IOError as err:
             print("model: error:", err)
Ejemplo n.º 16
0
 def collapsed_tree(self):
     glob.load_from_file("tests/tools/atlkPO/models/collapsed-tree.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 17
0
 def nfair_model(self):
     glob.load_from_file("tests/tools/atlkPO/models/nfair.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 18
0
 def premod(self):
     glob.load_from_file("tests/tools/mas/pre.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 19
0
 def cardgame(self):
     glob.load_from_file("tests/tools/mas/cardgame.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 20
0
 def cardgame(self):
     glob.load_from_file("tests/tools/mas/cardgame.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 21
0
 def collapsed_tree(self):
     glob.load_from_file("tests/tools/atlkPO/models/collapsed-tree.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 22
0
 def small(self):
     glob.load_from_file("tests/tools/atl/models/small-game.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 23
0
 def model(self):
     glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 24
0
 def transmission_fair(self):
     glob.load_from_file("tests/tools/atlkFO/models/transmission-fair.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 25
0
 def transmission_with_knowledge(self):
     glob.load_from_file(
         "tests/tools/atlkPO/models/transmission-knowledge.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 26
0
 def little(self):
     glob.load_from_file("tests/tools/atlkPO/models/little.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
 def little(self):
     glob.load_from_file("tests/tools/atlkPO/models/little.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 28
0
 def premod(self):
     glob.load_from_file("tests/tools/mas/pre.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 29
0
 def transmission(self):
     glob.load_from_file("tests/tools/atlkFO/models/transmission.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 30
0
 def nfair_model(self):
     glob.load_from_file("tests/tools/atlkPO/models/nfair.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
 def transmission_with_knowledge(self):
     glob.load_from_file(
                     "tests/tools/atlkPO/models/transmission-knowledge.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 32
0
 def tictactoe(self):
     glob.load_from_file("tests/tools/atlkFO/models/tictactoe.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 33
0
 def cardgame_post_fair(self):
     glob.load_from_file("tests/tools/atlkPO/models/cardgame-post-fair.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 34
0
 def small(self):
     glob.load_from_file("tests/tools/atl/models/small-game.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 35
0
 def transmission_post_fair(self):
     glob.load_from_file("tests/tools/atlkPO/models/"
                         "transmission-post-fair.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 36
0
 def cardgamenew(self):
     glob.load_from_file("tests/tools/atl/models/card-game3.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 37
0
 def cardgame_fair(self):
     glob.load_from_file("tests/tools/atlkFO/models/cardgame-fair.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 38
0
 def tictactoe(self):
     glob.load_from_file("tests/tools/atl/models/tictactoe.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 39
0
 def simplemodel(self):
     glob.load_from_file("tests/tools/ctlk/agents.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm
Ejemplo n.º 40
0
 def cardgamenew(self):
     glob.load_from_file("tests/tools/atl/models/card-game3.smv")
     fsm = glob.mas()
     self.assertIsNotNone(fsm)
     return fsm