def test_AddVertex(self): graph = SimpleGraph(5) graph.AddVertex(0) result = graph.AddVertex(1) self.assertTrue(result) self.assertTrue(isinstance(graph.vertex[1], Vertex)) self.assertTrue(graph.vertex[1].Value == 1) self.checkVertexAdjacency(graph, 1, [0] * 5)
def test_RemoveVertex(self): graph = SimpleGraph(5) graph.AddVertex(0) graph.AddVertex(1) graph.AddVertex(2) graph.AddEdge(0, 1) graph.AddEdge(0, 2) graph.RemoveVertex(0) self.checkVertexAdjacency(graph, 0, [0] * 5)
def test_AddVertexEmpty(self): graph = SimpleGraph(5) result = graph.AddVertex(0) self.assertTrue(result) self.assertTrue(isinstance(graph.vertex[0], Vertex)) self.assertTrue(graph.vertex[0].Value == 0) self.checkVertexAdjacency(graph, 0, [0] * 5)
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_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_AddVertexFull(self): graph = SimpleGraph(2) graph.AddVertex(0) graph.AddVertex(1) result = graph.AddVertex(2) self.assertFalse(result)
def test_BreadthFirstSearchSingleVertexWithoutEdge(self): graph = SimpleGraph(5) graph.AddVertex(0) result = graph.BreadthFirstSearch(0, 0) self.assertTrue(result == [], result)