Skip to content

Commit 75c5c41

Browse files
#9943 : Adding coverage test for basic_graphs.py (#12354)
* #9943 : Adding coverage test for basic_graphs.py * #9943 : Adding coverage test for basic_graphs.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Solve problem of line too long --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7742536 commit 75c5c41

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

graphs/basic_graphs.py

+32
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ def initialize_weighted_undirected_graph(
7777

7878

7979
def dfs(g, s):
80+
"""
81+
>>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1)
82+
1
83+
2
84+
4
85+
5
86+
3
87+
"""
8088
vis, _s = {s}, [s]
8189
print(s)
8290
while _s:
@@ -104,6 +112,17 @@ def dfs(g, s):
104112

105113

106114
def bfs(g, s):
115+
"""
116+
>>> bfs({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [], 5: [8], 6: [], 7: [], 8: []}, 1)
117+
1
118+
2
119+
3
120+
4
121+
5
122+
6
123+
7
124+
8
125+
"""
107126
vis, q = {s}, deque([s])
108127
print(s)
109128
while q:
@@ -128,6 +147,19 @@ def bfs(g, s):
128147

129148

130149
def dijk(g, s):
150+
"""
151+
dijk({1: [(2, 7), (3, 9), (6, 14)],
152+
2: [(1, 7), (3, 10), (4, 15)],
153+
3: [(1, 9), (2, 10), (4, 11), (6, 2)],
154+
4: [(2, 15), (3, 11), (5, 6)],
155+
5: [(4, 6), (6, 9)],
156+
6: [(1, 14), (3, 2), (5, 9)]}, 1)
157+
7
158+
9
159+
11
160+
20
161+
20
162+
"""
131163
dist, known, path = {s: 0}, set(), {s: 0}
132164
while True:
133165
if len(known) == len(g) - 1:

0 commit comments

Comments
 (0)