|
10 | 10 | from algorithms.graph import bellman_ford |
11 | 11 | from algorithms.graph import bellman_ford |
12 | 12 | from algorithms.graph import count_connected_number_of_component |
| 13 | +from algorithms.graph import prims_minimum_spanning |
13 | 14 |
|
14 | 15 | import unittest |
15 | 16 |
|
@@ -264,3 +265,23 @@ def test_connected_components_without_edges_graph(self): |
264 | 265 | expected_result = 4 |
265 | 266 | result = count_connected_number_of_component.count_components(l,size) |
266 | 267 | self.assertEqual(result,expected_result) |
| 268 | + |
| 269 | + |
| 270 | +class PrimsMinimumSpanning(unittest.TestCase): |
| 271 | + def test_prim_spanning(self): |
| 272 | + graph1 = { |
| 273 | + 1 : [ [3, 2], [8, 3] ], |
| 274 | + 2 : [ [3, 1], [5, 4] ], |
| 275 | + 3 : [ [8, 1], [2, 4], [4, 5] ], |
| 276 | + 4 : [ [5, 2], [2, 3], [6, 5] ], |
| 277 | + 5 : [ [4, 3], [6, 4] ] |
| 278 | + } |
| 279 | + self.assertEqual(14, prims_minimum_spanning(graph1)) |
| 280 | + |
| 281 | + graph2 = { |
| 282 | + 1 : [ [7, 2], [6, 4] ], |
| 283 | + 2 : [ [7, 1], [9, 4], [6, 3] ], |
| 284 | + 3 : [ [8, 4], [6, 2] ], |
| 285 | + 4 : [ [6, 1], [9, 2], [8, 3] ] |
| 286 | + } |
| 287 | + self.assertEqual(19, prims_minimum_spanning(graph2)) |
0 commit comments