Skip to content

Commit 581be00

Browse files
authored
Update test_graph.py
unittest added for prims_minimum_spanning.py
1 parent 52d835e commit 581be00

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_graph.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from algorithms.graph import bellman_ford
1111
from algorithms.graph import bellman_ford
1212
from algorithms.graph import count_connected_number_of_component
13+
from algorithms.graph import prims_minimum_spanning
1314

1415
import unittest
1516

@@ -264,3 +265,23 @@ def test_connected_components_without_edges_graph(self):
264265
expected_result = 4
265266
result = count_connected_number_of_component.count_components(l,size)
266267
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

Comments
 (0)