diff --git a/graphs/directed_and_undirected_weighted_graph.py b/graphs/directed_and_undirected_weighted_graph.py index e65c500a1..a0f0c9a56 100644 --- a/graphs/directed_and_undirected_weighted_graph.py +++ b/graphs/directed_and_undirected_weighted_graph.py @@ -114,6 +114,20 @@ class DirectedGraph: # c is the count of nodes you want and if you leave it or pass -1 to the function # the count will be random from 10 to 10000 def fill_graph_randomly(self, c=-1): + """ + Fill the graph with random nodes and edges. + + Args: + c: Number of nodes to generate. If -1, a random number of nodes between 10 and 10000 is used. + + Example: + >>> g = DirectedGraph() + >>> g.fill_graph_randomly(5) # Fill graph with 5 nodes and random edges. + >>> len(g.graph) # Check the number of nodes added. + 5 + >>> all(isinstance(node, int) and isinstance(edges, list) for node, edges in g.graph.items()) + True # All nodes should be integers, and edges should be lists. + """ if c == -1: c = floor(random() * 10000) + 10 for i in range(c): @@ -531,4 +545,4 @@ class Graph: if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod(verbose=True)