def test_BreadthFirstSearchWithCycle(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1, 2]) graph.AddEdge(0, 1) graph.AddEdge(1, 1) graph.AddEdge(1, 2) result = graph.BreadthFirstSearch(0, 2) self.assertTrue(result == [graph.vertex[0], graph.vertex[1], graph.vertex[2]], result)
def test_BreadthFirstSearchWithDifferentPaths(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1, 2, 3, 4]) graph.AddEdge(0, 1) graph.AddEdge(1, 2) graph.AddEdge(2, 3) graph.AddEdge(3, 4) graph.AddEdge(4, 0) result = graph.BreadthFirstSearch(0, 2) self.assertTrue(result == [graph.vertex[0], graph.vertex[1], graph.vertex[2]], result)
def test_RemoveVertex(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1, 2]) graph.AddEdge(0, 1) graph.AddEdge(0, 2) graph.RemoveVertex(0) self.checkVertexAdjacency(graph, 0, [0] * 5)
def test_RemoveEdge(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1]) graph.AddEdge(0, 1) self.checkEdge(graph, 0, 1, 1) graph.RemoveEdge(1, 0) self.checkEdge(graph, 0, 1, 0)
def test_DepthFirstSearchThreeVertexWithTwoEdges(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1, 2]) graph.AddEdge(0, 1) graph.AddEdge(1, 2) result = graph.DepthFirstSearch(0, 2) self.assertTrue(result == [graph.vertex[0], graph.vertex[1], graph.vertex[2]], result)
def test_AddEdge(self): graph = SimpleGraph(5) graph.AddVertex(0) graph.AddVertex(1) self.checkEdge(graph, 0, 1, 0) graph.AddEdge(0, 1) self.checkEdge(graph, 0, 1, 1)
def test_DepthFirstSearchTwoVertexWithEdge(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1]) graph.AddEdge(0, 1) result = graph.DepthFirstSearch(0, 1) self.assertTrue(result == [graph.vertex[0], graph.vertex[1]], result)
def test_DepthFirstSearchSingleVertexWithEdge(self): graph = SimpleGraph(5) graph.AddVertex(0) graph.AddEdge(0, 0) result = graph.DepthFirstSearch(0, 0) self.assertTrue(result == [graph.vertex[0], graph.vertex[0]], result)
def test_BreadthFirstSearchThreeVertexWithoutEdge(self): graph = SimpleGraph(5) self.addVertexes(graph, [0, 1, 2]) graph.AddEdge(0, 1) result = graph.BreadthFirstSearch(0, 2) self.assertTrue(result == [], result)