def test_remove_connected_vertex(self): """Tests the remove_vertex method for a connected vertex. """ data = { 'A' : ['B'], 'B' : ['A'] } graph = Graph(graph=data) self.assertTrue('B' in graph.connected_vertex('A'), 'There is an edge between A and B.') self.assertTrue('A' in graph.connected_vertex('B'), 'There is an edge between A and B.') graph.remove_vertex('A') self.assertFalse('A' in graph.connected_vertex('B'), 'No more edge between A and 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.')