Example #1
0
 def test_dfs_trace_filter(self):
     pta = PTA(["IDLE"])
     pta.add_transition("UNINITIALIZED", "IDLE", "init")
     pta.add_transition("IDLE", "IDLE", "set1")
     pta.add_transition("IDLE", "IDLE", "set2")
     self.assertEqual(
         sorted(
             dfs_tran_to_name(
                 pta.dfs(
                     2,
                     trace_filter=[
                         ["init", "set1", "set2"],
                         ["init", "set2", "set1"],
                     ],
                 ),
                 False,
             )),
         [["init", "set1", "set2"], ["init", "set2", "set1"]],
     )
     self.assertEqual(
         sorted(
             dfs_tran_to_name(
                 pta.dfs(2,
                         trace_filter=[["init", "set1", "$"],
                                       ["init", "set2", "$"]]),
                 False,
             )),
         [["init", "set1"], ["init", "set2"]],
     )
Example #2
0
 def test_dfs_accepting(self):
     pta = PTA(["IDLE", "TX"], accepting_states=["IDLE"])
     pta.add_transition("UNINITIALIZED", "IDLE", "init")
     pta.add_transition("IDLE", "TX", "send")
     pta.add_transition("TX", "IDLE", "txComplete")
     self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [["init"]])
     self.assertEqual(dfs_tran_to_name(pta.dfs(1), False), [])
     self.assertEqual(dfs_tran_to_name(pta.dfs(2), False),
                      [["init", "send", "txComplete"]])
     self.assertEqual(dfs_tran_to_name(pta.dfs(3), False), [])
Example #3
0
    def test_dfs(self):
        pta = PTA(["IDLE", "TX"])
        pta.add_transition("UNINITIALIZED", "IDLE", "init")
        pta.add_transition("IDLE", "TX", "send")
        pta.add_transition("TX", "IDLE", "txComplete")
        self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [["init"]])
        self.assertEqual(dfs_tran_to_name(pta.dfs(1), False),
                         [["init", "send"]])
        self.assertEqual(dfs_tran_to_name(pta.dfs(2), False),
                         [["init", "send", "txComplete"]])
        self.assertEqual(
            dfs_tran_to_name(pta.dfs(3), False),
            [["init", "send", "txComplete", "send"]],
        )

        pta = PTA(["IDLE"])
        pta.add_transition("UNINITIALIZED", "IDLE", "init")
        pta.add_transition("IDLE", "IDLE", "set1")
        pta.add_transition("IDLE", "IDLE", "set2")
        self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [["init"]])
        self.assertEqual(
            sorted(dfs_tran_to_name(pta.dfs(1), False)),
            [["init", "set1"], ["init", "set2"]],
        )
        self.assertEqual(
            sorted(dfs_tran_to_name(pta.dfs(2), False)),
            [
                ["init", "set1", "set1"],
                ["init", "set1", "set2"],
                ["init", "set2", "set1"],
                ["init", "set2", "set2"],
            ],
        )
Example #4
0
 def test_dfs_objects(self):
     pta = PTA(["IDLE", "TX"])
     pta.add_transition("UNINITIALIZED", "IDLE", "init")
     pta.add_transition("IDLE", "TX", "send")
     pta.add_transition("TX", "IDLE", "txComplete")
     traces = list(pta.dfs(2))
     self.assertEqual(len(traces), 1)
     trace = traces[0]
     self.assertEqual(len(trace), 3)
     self.assertEqual(trace[0][0].name, "init")
     self.assertEqual(trace[1][0].name, "send")
     self.assertEqual(trace[2][0].name, "txComplete")
     self.assertEqual(pta.get_transition_id(trace[0][0]), 0)
     self.assertEqual(pta.get_transition_id(trace[1][0]), 1)
     self.assertEqual(pta.get_transition_id(trace[2][0]), 2)
Example #5
0
 def test_dfs_with_sleep(self):
     pta = PTA(["IDLE", "TX"])
     pta.add_transition("UNINITIALIZED", "IDLE", "init")
     pta.add_transition("IDLE", "TX", "send")
     pta.add_transition("TX", "IDLE", "txComplete")
     traces = list(pta.dfs(2, sleep=10))
     self.assertEqual(len(traces), 1)
     trace = traces[0]
     self.assertEqual(len(trace), 6)
     self.assertIsNone(trace[0][0])
     self.assertEqual(trace[1][0].name, "init")
     self.assertIsNone(trace[2][0])
     self.assertEqual(trace[3][0].name, "send")
     self.assertIsNone(trace[4][0])
     self.assertEqual(trace[5][0].name, "txComplete")
     self.assertEqual(pta.get_transition_id(trace[1][0]), 0)
     self.assertEqual(pta.get_transition_id(trace[3][0]), 1)
     self.assertEqual(pta.get_transition_id(trace[5][0]), 2)