def test_VizSccTracing_nontrivial(self):
        """ Functions more as a demonstration than as a test. It will create
        the animation for an acyclic graph"""

        self.directed_graph = \
            DirectedGraph(self.vertices,
                          algorithm_ordering=AlgorithmOrdering.ASC)
        dir = TestVizSccsKosarajuTracing.RESOURCES_PATH + "/" + \
            inspect.currentframe().f_code.co_name
        viz_sccs_kosaraju_tracing: VizSccsKosarajuTracing =\
            VizSccsKosarajuTracing(
                path=pt.get_dir_in_user_home(dir),
                directed_graph=self.directed_graph,
                vertex_states={
                    VizTracing.ACTIVATED:
                        {"fillcolor": "red", "style": "filled"},
                    VizTracing.VISITED:
                        {"fillcolor": "gray", "style": "filled"},
                    VizTracing.DEFAULT:
                        {"fillcolor": "white", "style": "filled"}
                    },
                edge_states={})
        viz_sccs_kosaraju_tracing.execute(resource_path=dir,
                                          nontrivial=True)
        self.assertTrue(True)
    def test_VizCyclicTracing_cyclic(self):
        """ Functions more as a demonstration than as a test. It will create
        the animation for a cyclic graph"""

        self.vertices = {0: [1], 1: [2, 3], 2: [3],
                         3: [4, 6], 4: [5, 6], 5: [7, 8], 6: [7, 8],
                         7: [9, 10, 11], 8: [3], 9: [],
                         10: [11], 11: [12], 12: []}
        self.directed_graph = \
            DirectedGraph(self.vertices,
                          algorithm_ordering=AlgorithmOrdering.ASC)
        dir = TestVizCyclicTracing.RESOURCES_PATH + "/" + \
            inspect.currentframe().f_code.co_name
        viz_cyclic_tracing: VizCyclicTracing = VizCyclicTracing(
            path=pt.get_dir_in_user_home(dir),
            directed_graph=self.directed_graph,
            vertex_states=[
                    {VizTracing.ACTIVATED:
                        {"fillcolor": "red", "style": "filled"}},
                    {VizCyclicTracing.IN_CYCLE:
                        {"fillcolor": "blue", "style": "filled"}},
                    {VizCyclicTracing.VISITED:
                        {"fillcolor": "gray", "style": "filled"}}])
        viz_cyclic_tracing.execute(resource_path=dir)
        self.assertTrue(True)
Beispiel #3
0
 def test_VizTracingGraphviz_activate_vertex(self):
     self.vertices = {
         0: [1],
         1: [2, 3],
         2: [3],
         3: [4, 6],
         4: [5, 6],
         5: [5],
         6: [6]
     }
     self.directed_graph = DirectedGraph(self.vertices)
     vertex_1 = self.directed_graph.get_vertex(1)
     dir = TestVizTracingGraphviz.RESOURCES_PATH_RECYCLE + "/" + \
         inspect.currentframe().f_code.co_name
     viz_cyclic_tracing: VizCyclicTracing = VizCyclicTracing(
         path=pt.get_dir_in_user_home(dir),
         directed_graph=self.directed_graph,
         vertex_states=[{
             VizTracing.ACTIVATED: {
                 "fillcolor": "red",
                 "style": "filled"
             }
         }, {
             VizCyclicTracing.IN_CYCLE: {
                 "fillcolor": "blue",
                 "style": "filled"
             }
         }])
     viz_cyclic_tracing.change_activated_vertex(self.directed_graph,
                                                vertex_1)
     for vertex in self.directed_graph.get_vertices():
         if str(vertex_1.get_label()) == str(vertex.get_label()):
             self.assertTrue(vertex.get_attr(VizTracing.ACTIVATED))
         else:
             self.assertFalse(vertex.get_attr(VizTracing.ACTIVATED))
Beispiel #4
0
 def test_VizTracingGraphviz_vertex_only(self):
     self.vertices = {
         0: [1],
         1: [2, 3],
         2: [3],
         3: [4, 6],
         4: [5, 6],
         5: [5],
         6: [6]
     }
     self.directed_graph = DirectedGraph(self.vertices)
     vertex_1 = self.directed_graph.get_vertex(1)
     vertex_1.set_attr("activated", True)
     vertex_2 = self.directed_graph.get_vertex(2)
     vertex_2.set_attr("in_cycle", True)
     dir = TestVizTracingGraphviz.RESOURCES_PATH_RECYCLE + "/" + \
         inspect.currentframe().f_code.co_name
     pt.create_dir_in_user_home(dir)
     viz_cyclic_tracing: VizCyclicTracing = VizCyclicTracing(
         path=pt.get_dir_in_user_home(dir),
         directed_graph=self.directed_graph,
         vertex_states=[{
             VizTracing.ACTIVATED: {
                 "fillcolor": "red",
                 "style": "filled"
             }
         }, {
             VizCyclicTracing.IN_CYCLE: {
                 "fillcolor": "blue",
                 "style": "filled"
             }
         }])
     viz_cyclic_tracing.snapshot(self.directed_graph)
     self.assertTrue(True)
Beispiel #5
0
 def test_VizTracingGraphviz_snapshot(self):
     dir = TestVizTracingGraphviz.RESOURCES_PATH_RECYCLE + "/" + \
         inspect.currentframe().f_code.co_name
     viz_cyclic_tracing: VizCyclicTracing = VizCyclicTracing(
         path=pt.get_dir_in_user_home(dir),
         directed_graph=self.directed_graph)
     viz_cyclic_tracing.snapshot(self.directed_graph)
     self.assertTrue(
         os.path.exists(
             path.join(
                 pt.get_dir_in_user_home(dir),
                 VizCyclicTracing.IMAGE_NAME_PREFIX +
                 ("{:04d}".format(viz_cyclic_tracing.snapshot_no - 1)) +
                 "." + VizCyclicTracing.IMAGE_TYPE)))
     viz_cyclic_tracing.snapshot(self.directed_graph)
     self.assertTrue(
         os.path.exists(
             path.join(
                 pt.get_dir_in_user_home(dir),
                 VizCyclicTracing.IMAGE_NAME_PREFIX +
                 ("{:04d}".format(viz_cyclic_tracing.snapshot_no - 1)) +
                 "." + VizCyclicTracing.IMAGE_TYPE)))
Beispiel #6
0
    def execute(self, resource_path: str):
        """ Main function that takes a number of vertices
        (of a directed graph), invokes the cycle check functionality
        (which in turn creates the traced images), and converts the images
        to a video.

        Args:
            vertices(dict): a dictionar with vertices and for each vertex its
                destination vertices
            resource_path: the path that should contain the generated resources
        """

        super().execute(resource_path)
        self.get_directed_graph().is_cyclic(VizCyclicTracingAdvisor(self))
        vt.convert_images_to_video(pt.get_dir_in_user_home(resource_path))
Beispiel #7
0
 def tearDown(self):
     dir = TestVizTracingGraphviz.RESOURCES_PATH_RECYCLE
     pt.clean_dir_in_user_home(dir)
     self.assertFalse(os.path.exists(pt.get_dir_in_user_home(dir)))