* Add doctest for add_vertex in GraphAdjacencyList. Contributes to #9943 * Update graph_adjacency_list.py --------- Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
@@ -61,6 +61,15 @@ class GraphAdjacencyList[T]:
|
||||
"""
|
||||
Adds a vertex to the graph. If the given vertex already exists,
|
||||
a ValueError will be thrown.
|
||||
|
||||
>>> g = GraphAdjacencyList(vertices=[], edges=[], directed=False)
|
||||
>>> g.add_vertex("A")
|
||||
>>> g.adj_list
|
||||
{'A': []}
|
||||
>>> g.add_vertex("A")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Incorrect input: A is already in the graph.
|
||||
"""
|
||||
if self.contains_vertex(vertex):
|
||||
msg = f"Incorrect input: {vertex} is already in the graph."
|
||||
|
||||
Reference in New Issue
Block a user