def test_get_links_tiny(self): graph = WeightedGraph() graph.add_direct_link(0, 1, 50) graph.add_direct_link(1, 2, 34) graph.add_direct_link(1, 3, 42) graph.add_direct_link(4, 1, 24) links = sorted(graph.get_links(1)) self.assertEqual(links, [0, 2, 3, 4])
def test_MST_tiny(self): graph = WeightedGraph() graph.add_direct_link(1, 3, 15) graph.add_direct_link(1, 2, 1) graph.add_direct_link(1, 4, 10) graph.add_direct_link(2, 4, 15) graph.add_direct_link(2, 3, 16) graph.add_direct_link(2, 0, 4) graph.add_direct_link(3, 0, 2) graph.add_direct_link(4, 0, 3) mst = graph.min_tree() self.assertEqual(sorted(mst.get_links(0)), [2, 3, 4]) self.assertEqual(sorted(mst.get_links(1)), [2]) self.assertEqual(sorted(mst.get_links(2)), [0, 1]) self.assertEqual(sorted(mst.get_links(3)), [0]) self.assertEqual(sorted(mst.get_links(4)), [0])
def test_MST_small(self): graph = WeightedGraph() graph.add_direct_link(0, 1, 2) graph.add_direct_link(2, 1, 3) graph.add_direct_link(2, 5, 4) graph.add_direct_link(2, 4, 1) graph.add_direct_link(2, 6, 5) graph.add_direct_link(3, 7, 13) graph.add_direct_link(4, 7, 6) graph.add_direct_link(5, 8, 7) graph.add_direct_link(8, 9, 8) graph.add_direct_link(8, 10, 9) graph.add_direct_link(10, 11, 10) graph.add_direct_link(12, 11, 11) graph.add_direct_link(13, 11, 12) graph.add_direct_link(0, 11, 54) graph.add_direct_link(0, 12, 64) graph.add_direct_link(0, 7, 42) graph.add_direct_link(0, 2, 6) graph.add_direct_link(1, 3, 63) graph.add_direct_link(1, 9, 99) graph.add_direct_link(5, 6, 42) graph.add_direct_link(5, 9, 87) graph.add_direct_link(8, 12, 46) mst = graph.min_tree() self.assertEqual(sorted(mst.get_links(0)), [1]) self.assertEqual(sorted(mst.get_links(1)), [0, 2]) self.assertEqual(sorted(mst.get_links(2)), [1, 4, 5, 6]) self.assertEqual(sorted(mst.get_links(3)), [7]) self.assertEqual(sorted(mst.get_links(4)), [2, 7]) self.assertEqual(sorted(mst.get_links(5)), [2, 8]) self.assertEqual(sorted(mst.get_links(6)), [2]) self.assertEqual(sorted(mst.get_links(7)), [3, 4]) self.assertEqual(sorted(mst.get_links(8)), [5, 9, 10]) self.assertEqual(sorted(mst.get_links(9)), [8]) self.assertEqual(sorted(mst.get_links(10)), [8, 11]) self.assertEqual(sorted(mst.get_links(11)), [10, 12, 13]) self.assertEqual(sorted(mst.get_links(12)), [11]) self.assertEqual(sorted(mst.get_links(13)), [11])
def test_get_links_small(self): graph = WeightedGraph() graph.add_direct_link(0, 5, 1) graph.add_direct_link(0, 1, 1) graph.add_direct_link(0, 2, 1) graph.add_direct_link(1, 5, 1) graph.add_direct_link(2, 5, 1) graph.add_direct_link(2, 3, 1) graph.add_direct_link(3, 4, 1) graph.add_direct_link(3, 5, 1) graph.add_direct_link(5, 6, 1) graph.add_direct_link(5, 7, 1) graph.add_direct_link(6, 9, 1) graph.add_direct_link(7, 11, 1) graph.add_direct_link(8, 9, 1) graph.add_direct_link(9, 10, 1) graph.add_direct_link(9, 11, 1) links = sorted(graph.get_links(1)) self.assertEqual(links, [0, 5]) links = sorted(graph.get_links(3)) self.assertEqual(links, [2, 4, 5]) links = sorted(graph.get_links(5)) self.assertEqual(links, [0, 1, 2, 3, 6, 7]) links = sorted(graph.get_links(11)) self.assertEqual(links, [7, 9])