def test_get_all_vertices(self): graph = Graph() self.assertSequenceEqual([], graph.get_all_vertices()) graph.add_vertex(1) graph.add_vertex(2) graph.add_vertex(3) graph.add_edge(4, 5) self.assertSetEqual(set([1, 2, 3, 4, 5]), set(graph.get_all_vertices()))
def test_add_edge(self): graph = Graph() graph.add_vertex(5) graph.add_vertex(1) graph.add_vertex(2) graph.add_edge(5, 1) graph.add_edge(5, 2) graph.add_edge(3, 4) self.assertSequenceEqual([1, 2], graph.adjacency_list[5]) self.assertSequenceEqual([5], graph.adjacency_list[1]) self.assertSequenceEqual([5], graph.adjacency_list[2]) self.assertSequenceEqual([3], graph.adjacency_list[4]) self.assertSequenceEqual([4], graph.adjacency_list[3])
def test_add_vertex(self): graph = Graph() graph.add_vertex(5) graph.add_vertex(1) graph.add_vertex(2) self.assertSequenceEqual([], graph.adjacency_list[5]) self.assertSequenceEqual([], graph.adjacency_list[1]) self.assertSequenceEqual([], graph.adjacency_list[2]) with self.assertRaises(Exception): graph.add_vertex(5)