def test_contains_vertex(self): """Tests the contains_vertex method with a single vertex. """ data = { 'A' : [] } graph = Graph(graph=data) self.assertTrue(graph.contains_vertex('A'), 'The graph contains A.') self.assertFalse(graph.contains_vertex('B'), 'The graph does not contain B.')
def test_add_vertex(self): """Tests the add_vertex method with an empty graph. """ graph = Graph() self.assertFalse(graph.contains_vertex('A'), 'The graph does not contain A yet.') graph.add_vertex('A') self.assertTrue(graph.contains_vertex('A'), 'The graph now contains A.')
def test_remove_isolated_vertex(self): """Tests the remove_vertex method for an isolated vertex. """ data = { 'A' : [], 'B' : [] } graph = Graph(graph=data) self.assertTrue(graph.contains_vertex('A'), 'A is a vertex of the graph.') self.assertTrue(graph.contains_vertex('B'), 'B is a vertex of the graph.') graph.remove_vertex('A') self.assertFalse(graph.contains_vertex('A'), 'The graph does not contain a vertex A.') self.assertTrue(graph.contains_vertex('B'), 'The graph contains a vertex B.')
def test_add_vertex_existing_one(self): """Tests the add_vertex method in a graph where the vertex to add already exists. """ data = { 'A' : ['B'] } graph = Graph(graph=data) connected = graph.connected_vertex('A') self.assertTrue(graph.contains_vertex('A'), 'Graph contains the vertex A.') self.assertEqual(connected[0], 'B', 'A has an edge to vertex B.') graph.add_vertex('A') connected = graph.connected_vertex('A') self.assertTrue(graph.contains_vertex('A'), 'Graph still contains vertex A.') self.assertEqual(connected[0], 'B', 'A still has an edge to vertex B.')