Skip to content

Commit f3bfc4f

Browse files
committed
added tests to 10 - 138
1 parent 4a41469 commit f3bfc4f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

graphs/directed_and_undirected_weighted_graph.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ def dfs(self, s=-2, d=-1):
114114
# c is the count of nodes you want and if you leave it or pass -1 to the function
115115
# the count will be random from 10 to 10000
116116
def fill_graph_randomly(self, c=-1):
117+
"""
118+
Fill the graph with random nodes and edges.
119+
120+
Args:
121+
c: Number of nodes to generate. If -1, a random number of nodes between 10 and 10000 is used.
122+
123+
Example:
124+
>>> g = DirectedGraph()
125+
>>> g.fill_graph_randomly(5) # Fill graph with 5 nodes and random edges.
126+
>>> len(g.graph) # Check the number of nodes added.
127+
5
128+
>>> all(isinstance(node, int) and isinstance(edges, list) for node, edges in g.graph.items())
129+
True # All nodes should be integers, and edges should be lists.
130+
"""
117131
if c == -1:
118132
c = floor(random() * 10000) + 10
119133
for i in range(c):
@@ -531,4 +545,4 @@ def bfs_time(self, s=-2):
531545

532546
if __name__ == "__main__":
533547
import doctest
534-
doctest.testmod()
548+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)