From f3bfc4f5a719022142c5050ca9bfbb1c3284f1f3 Mon Sep 17 00:00:00 2001 From: zirtidik Date: Tue, 3 Dec 2024 18:22:07 -0500 Subject: [PATCH] added tests to 10 - 138 --- graphs/directed_and_undirected_weighted_graph.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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)