Skip to content

Commit 9034015

Browse files
author
Hardik dadhich
committed
adding more unit-tests
1 parent e5c4699 commit 9034015

File tree

2 files changed

+54
-42
lines changed

2 files changed

+54
-42
lines changed

tests/test_count_connected_components.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/test_graph.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from algorithms.graph import all_pairs_shortest_path
1010
from algorithms.graph import bellman_ford
1111
from algorithms.graph import bellman_ford
12-
12+
from algorithms.graph import count_connected_number_of_component
1313

1414
import unittest
1515

@@ -208,4 +208,56 @@ def test_bellman_ford(self):
208208
'e': {'a': 7, 'b': 5, 'd': 1}
209209
}
210210

211-
self.assertEqual(True, bellman_ford(graph2, 'a'))
211+
class TestConnectedComponentInGraph(unittest.TestCase):
212+
"""
213+
Class for testing different cases for connected components in graph
214+
"""
215+
def test_count_connected_components(self):
216+
"""
217+
Test Function that test the different cases of count connected components
218+
219+
0----------2 1--------5 3
220+
|
221+
|
222+
4
223+
224+
output = 3
225+
"""
226+
expected_result = 3
227+
228+
# adjacency list representation of graph
229+
l = [[2],
230+
[5],
231+
[0,4],
232+
[],
233+
[2],
234+
[1]
235+
]
236+
237+
size = 5
238+
result = count_connected_number_of_component.count_components(l,size)
239+
self.assertEqual(result,expected_result)
240+
241+
def test_connected_components_with_empty_graph(self):
242+
243+
"""
244+
input :
245+
output : 0
246+
"""
247+
248+
l = [[]]
249+
expected_result = 0
250+
size = 0
251+
result = count_connected_number_of_component.count_components(l,size)
252+
self.assertEqual(result,expected_result)
253+
254+
def test_connected_components_without_edges_graph(self):
255+
"""
256+
input : 0 2 3 4
257+
output : 4
258+
"""
259+
l = [[0],[],[2],[3],[4]]
260+
size = 4
261+
expected_result = 4
262+
result = count_connected_number_of_component.count_components(l,size)
263+
self.assertEqual(result,expected_result)

0 commit comments

Comments
 (0)