def test_graph_edge_not_equal(self): """ Test operator "inequal". """ a_graph = graph.UnDirectedUnWeightedGraph(3) vertex1 = graph_vertex.GraphVertex(a_graph, "AA") vertex2 = graph_vertex.GraphVertex(a_graph, "BB") vertex3 = graph_vertex.GraphVertex(a_graph, "CC") a_graph.add_vertex(vertex1) a_graph.add_vertex(vertex2) a_graph.add_vertex(vertex3) a_graph.add_edge(vertex1, vertex2) a_graph.add_edge(vertex2, vertex3) a_graph.add_edge(vertex1, vertex3) e12_g = a_graph.get_edge(vertex1, vertex2) e21_g = a_graph.get_edge(vertex2, vertex1) e23_g = a_graph.get_edge(vertex2, vertex3) e32_g = a_graph.get_edge(vertex3, vertex2) e13_g = a_graph.get_edge(vertex1, vertex3) e31_g = a_graph.get_edge(vertex3, vertex1) test1 = e12_g == self.e12_g1 test2 = e21_g == self.e21_g1 test3 = e23_g == self.e23_g1 test4 = e32_g == self.e32_g1 test5 = e13_g == self.e13_g1 test6 = e31_g == self.e31_g1 test = test1 and test2 and test3 and test4 and test5 and test6 self.assertFalse(test)
def test_graph_vertex_equal(self): """ Test operator "equal". """ a_graph = graph.DirectedGraph(5) vertex1 = graph_vertex.GraphVertex(a_graph, 'S') vertex2 = graph_vertex.GraphVertex(a_graph, 'T') vertex3 = graph_vertex.GraphVertex(a_graph, 'X') vertex4 = graph_vertex.GraphVertex(a_graph, 'Y') vertex5 = graph_vertex.GraphVertex(a_graph, 'Z') a_graph.add_vertex(vertex1) a_graph.add_vertex(vertex2) a_graph.add_vertex(vertex3) a_graph.add_vertex(vertex4) a_graph.add_vertex(vertex5) self.assertTrue(vertex3 == self.v3_g1)
def setUp(self): # Create directed unweighted graph Cormen page 596. self.graph1 = graph.DirectedGraph(5) self.v1_g1 = graph_vertex.GraphVertex(self.graph1, 'S') self.v2_g1 = graph_vertex.GraphVertex(self.graph1, 'T') self.v3_g1 = graph_vertex.GraphVertex(self.graph1, 'X') self.v4_g1 = graph_vertex.GraphVertex(self.graph1, 'Y') self.v5_g1 = graph_vertex.GraphVertex(self.graph1, 'Z') self.graph1.add_vertex(self.v1_g1) self.graph1.add_vertex(self.v2_g1) self.graph1.add_vertex(self.v3_g1) self.graph1.add_vertex(self.v4_g1) self.graph1.add_vertex(self.v5_g1) self.e12 = graph_edge.DirectedGraphEdge(self.graph1, self.v1_g1, self.v2_g1) # S -> T self.e14 = graph_edge.DirectedGraphEdge(self.graph1, self.v1_g1, self.v4_g1) # S -> Y self.e23 = graph_edge.DirectedGraphEdge(self.graph1, self.v2_g1, self.v3_g1) # T -> X self.e24 = graph_edge.DirectedGraphEdge(self.graph1, self.v2_g1, self.v4_g1) # T -> Y self.e35 = graph_edge.DirectedGraphEdge(self.graph1, self.v3_g1, self.v5_g1) # X -> Z self.e42 = graph_edge.DirectedGraphEdge(self.graph1, self.v4_g1, self.v2_g1) # Y -> T self.e43 = graph_edge.DirectedGraphEdge(self.graph1, self.v4_g1, self.v3_g1) # Y -> X self.e45 = graph_edge.DirectedGraphEdge(self.graph1, self.v4_g1, self.v5_g1) # Y -> Z self.e53 = graph_edge.DirectedGraphEdge(self.graph1, self.v5_g1, self.v3_g1) # Z -> X self.e51 = graph_edge.DirectedGraphEdge(self.graph1, self.v5_g1, self.v1_g1) # Z -> S self.graph1.add_edge(self.v1_g1, self.v2_g1) self.graph1.add_edge(self.v1_g1, self.v4_g1) self.graph1.add_edge(self.v2_g1, self.v3_g1) self.graph1.add_edge(self.v2_g1, self.v4_g1) self.graph1.add_edge(self.v3_g1, self.v5_g1) self.graph1.add_edge(self.v4_g1, self.v2_g1) self.graph1.add_edge(self.v4_g1, self.v3_g1) self.graph1.add_edge(self.v4_g1, self.v5_g1) self.graph1.add_edge(self.v5_g1, self.v3_g1) self.graph1.add_edge(self.v5_g1, self.v1_g1)
def setUp(self): # Create an empty undirected unweighted graph. self.graph1 = graph.UnDirectedUnWeightedGraph(3) # Create graph vertices and add them to the graph. self.vertex1 = graph_vertex.GraphVertex(self.graph1, "A") self.vertex2 = graph_vertex.GraphVertex(self.graph1, "B") self.vertex3 = graph_vertex.GraphVertex(self.graph1, "C") self.graph1.add_vertex(self.vertex1) self.graph1.add_vertex(self.vertex2) self.graph1.add_vertex(self.vertex3) # Create graph edges and add them to the graph. self.graph1.add_edge(self.vertex1, self.vertex2) self.graph1.add_edge(self.vertex2, self.vertex3) self.graph1.add_edge(self.vertex1, self.vertex3) # Extract the edges. self.e12_g1 = self.graph1.get_edge(self.vertex1, self.vertex2) self.e21_g1 = self.graph1.get_edge(self.vertex2, self.vertex1) self.e23_g1 = self.graph1.get_edge(self.vertex2, self.vertex3) self.e32_g1 = self.graph1.get_edge(self.vertex3, self.vertex2) self.e13_g1 = self.graph1.get_edge(self.vertex1, self.vertex3) self.e31_g1 = self.graph1.get_edge(self.vertex3, self.vertex1)