Esempio n. 1
0
    def test_un_directed_graph_classify_edges_acyclic(self):
        """
        Test method "classify_edges" - acyclic graph.
        """
        # Create an undirected acyclic graph
        a_graph = graph.UnDirectedGraph(4)
        v_1 = graph_vertex.UnWeightedGraphVertex(a_graph, 'A')
        v_2 = graph_vertex.UnWeightedGraphVertex(a_graph, 'B')
        v_3 = graph_vertex.UnWeightedGraphVertex(a_graph, 'C')
        v_4 = graph_vertex.UnWeightedGraphVertex(a_graph, 'D')

        a_graph.add_vertex(v_1)
        a_graph.add_vertex(v_2)
        a_graph.add_vertex(v_3)
        a_graph.add_vertex(v_4)

        a_graph.add_edge(v_1, v_2)
        a_graph.add_edge(v_2, v_3)
        a_graph.add_edge(v_2, v_4)

        res = a_graph.classify_edges().get_edges()
        ref = dfs_edge_classification.DFSEdgeClassification(
            a_graph).get_edges()
        e12 = graph_edge.UnDirectedGraphEdge(a_graph, v_1, v_2)
        e23 = graph_edge.UnDirectedGraphEdge(a_graph, v_2, v_3)
        e24 = graph_edge.UnDirectedGraphEdge(a_graph, v_2, v_4)
        ref[e12] = graph_edge.EdgeClassification.TREE_EDGE
        ref[e23] = graph_edge.EdgeClassification.TREE_EDGE
        ref[e24] = graph_edge.EdgeClassification.TREE_EDGE
        self.assertEqual(res, ref)
 def test_dfs_edge_classification_undirected_cyclic_get_tree_edges(self):
     """
     Test method "get_tree_edges" using an undirected graph.
     """
     res = self.classification_undirected_cyclic.get_tree_edges()
     ref = dfs_edge_classification.DFSEdgeClassification(self.g_undirected_cyclic).get_tree_edges()
     e23 = graph_edge.UnDirectedGraphEdge(self.g_undirected_cyclic, self.b_g_undirected_cyclic, self.c_g_undirected_cyclic)
     e12 = graph_edge.UnDirectedGraphEdge(self.g_undirected_cyclic, self.a_g_undirected_cyclic, self.b_g_undirected_cyclic)
     ref.add(e23)
     ref.add(e12)
     self.assertEqual(ref, res)
 def test_dfs_edge_classification_undirected_cyclic_get_edges(self):
     """
     Test method "get_edges" using an undirected graph.
     """
     res = self.classification_undirected_cyclic.get_edges()
     ref = dfs_edge_classification.DFSEdgeClassification(self.g_undirected_cyclic).get_edges()
     e31 = graph_edge.UnDirectedGraphEdge(self.g_undirected_cyclic, self.c_g_undirected_cyclic, self.a_g_undirected_cyclic)
     e23 = graph_edge.UnDirectedGraphEdge(self.g_undirected_cyclic, self.b_g_undirected_cyclic, self.c_g_undirected_cyclic)
     e12 = graph_edge.UnDirectedGraphEdge(self.g_undirected_cyclic, self.a_g_undirected_cyclic, self.b_g_undirected_cyclic)
     ref[e31] = graph_edge.EdgeClassification.BACK_EDGE
     ref[e23] = graph_edge.EdgeClassification.TREE_EDGE
     ref[e12] = graph_edge.EdgeClassification.TREE_EDGE
     self.assertEqual(ref, res)
Esempio n. 4
0
    def setUp(self):
        self.g_1 = graph.UnDirectedGraph(7)

        self.v_1 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'A')
        self.v_2 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'B')
        self.v_3 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'C')
        self.v_4 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'D')
        self.v_5 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'E')
        self.v_6 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'F')
        self.v_7 = graph_vertex.UnWeightedGraphVertex(self.g_1, 'G')

        self.g_1.add_vertex(self.v_1)
        self.g_1.add_vertex(self.v_2)
        self.g_1.add_vertex(self.v_3)
        self.g_1.add_vertex(self.v_4)
        self.g_1.add_vertex(self.v_5)
        self.g_1.add_vertex(self.v_6)
        self.g_1.add_vertex(self.v_7)

        self.e12 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_1, self.v_2)
        self.e21 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_2, self.v_1)
        self.e14 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_1, self.v_4)
        self.e41 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_4, self.v_1)
        self.e23 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_2, self.v_3)
        self.e32 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_3, self.v_2)
        self.e24 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_2, self.v_4)
        self.e42 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_4, self.v_2)
        self.e25 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_2, self.v_5)
        self.e52 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_5, self.v_2)
        self.e35 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_3, self.v_5)
        self.e53 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_5, self.v_3)
        self.e45 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_4, self.v_5)
        self.e54 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_5, self.v_4)
        self.e46 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_4, self.v_6)
        self.e64 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_6, self.v_4)
        self.e56 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_5, self.v_6)
        self.e65 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_6, self.v_5)
        self.e57 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_5, self.v_7)
        self.e75 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_7, self.v_5)
        self.e67 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_6, self.v_7)
        self.e76 = graph_edge.UnDirectedGraphEdge(self.g_1, self.v_7, self.v_6)

        self.g_1.add_edge(self.v_1, self.v_2)
        self.g_1.add_edge(self.v_1, self.v_4)
        self.g_1.add_edge(self.v_2, self.v_3)
        self.g_1.add_edge(self.v_2, self.v_4)
        self.g_1.add_edge(self.v_2, self.v_5)
        self.g_1.add_edge(self.v_3, self.v_5)
        self.g_1.add_edge(self.v_4, self.v_5)
        self.g_1.add_edge(self.v_4, self.v_6)
        self.g_1.add_edge(self.v_5, self.v_6)
        self.g_1.add_edge(self.v_5, self.v_7)
        self.g_1.add_edge(self.v_6, self.v_7)