Esempio n. 1
0
    def fill_dead_ends(self):
        collectables = []

        def visit_method(node, visited_nodes):
            if len(node.child_s) == 0 and isinstance(node, Lock):
                collectable = self.add_collectable(node)
                collectables.append(collectable)

        Node.traverse_nodes_breadth_first(self.start, visit_method)
        return collectables
Esempio n. 2
0
    def test_traverse_breadth_first(self):
        node, all_nodes = TestGraphs.get_man_graph()
        visited_expected = ["Start", "b", "c", "d", "e", "End", "g", "h", "i"]

        def visit_method(node, visited_nodes):
            visited.append(node)

        def will_traverse_method(node, visited_nodes):
            return True

        # Traverse with no will_traverse_method specified
        visited = []
        Node.traverse_nodes_breadth_first(node, visit_method)
        visited_names = [x.name for x in visited]
        self.assertTrue(
            self.assert_ordered(
                visited_names,
                [("Start", ["b", "c", "d", "e", "End", "g", "h", "i"]),
                 ("b", ["e", "End", "g", "h", "i"]),
                 ("c", ["e", "End", "g", "h", "i"]),
                 ("d", ["e", "End", "g", "h", "i"]), ("h", []), ("g", []),
                 ("e", []), ("End", [])]))

        # Traverse with will_traverse_method that allows all nodes
        visited = []
        Node.traverse_nodes_breadth_first(node, visit_method,
                                          will_traverse_method)
        visited_names = [x.name for x in visited]
        self.assertTrue(
            self.assert_ordered(
                visited_names,
                [("Start", ["b", "c", "d", "e", "End", "g", "h", "i"]),
                 ("b", ["e", "End", "g", "h", "i"]),
                 ("c", ["e", "End", "g", "h", "i"]),
                 ("d", ["e", "End", "g", "h", "i"]), ("h", []), ("g", []),
                 ("e", []), ("End", [])]))

        # Traverse with will_traverse_method that ignores node "c"
        def will_traverse_method2(node, visited_nodes):
            return node.name != "c"

        visited = []
        Node.traverse_nodes_breadth_first(node, visit_method,
                                          will_traverse_method2)
        visited_names = [x.name for x in visited]
        visited_expected = ["Start", "b", "d", "e"]
        self.assertTrue(
            self.assert_ordered(visited_names, [("Start", ["b", "d", "e"]),
                                                ("b", ["e"]), ("d", []),
                                                ("e", [])]))

        self.assertFalse(
            self.are_values_in_list(visited_names, ["c", "g", "h", "i"]))