mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-08 02:20:55 +00:00
added tests to 10 - 138
This commit is contained in:
parent
4a414699eb
commit
f3bfc4f5a7
|
@ -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
|
# 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
|
# the count will be random from 10 to 10000
|
||||||
def fill_graph_randomly(self, c=-1):
|
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:
|
if c == -1:
|
||||||
c = floor(random() * 10000) + 10
|
c = floor(random() * 10000) + 10
|
||||||
for i in range(c):
|
for i in range(c):
|
||||||
|
@ -531,4 +545,4 @@ class Graph:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
doctest.testmod(verbose=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user