Skip to content

Commit ca53ba4

Browse files
committed
Add doctest for add_vertex in GraphAdjacencyList. Contributes to #9943
1 parent a71618f commit ca53ba4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

graphs/graph_adjacency_list.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def add_vertex(self, vertex: T) -> None:
6161
"""
6262
Adds a vertex to the graph. If the given vertex already exists,
6363
a ValueError will be thrown.
64+
65+
Example:
66+
>>> g = GraphAdjacencyList(vertices=[], edges=[], directed=False)
67+
>>> g.add_vertex("A")
68+
>>> g.adj_list
69+
{'A': []}
70+
>>> g.add_vertex("A")
71+
Traceback (most recent call last):
72+
...
73+
ValueError: Incorrect input: A is already in the graph.
6474
"""
6575
if self.contains_vertex(vertex):
6676
msg = f"Incorrect input: {vertex} is already in the graph."

0 commit comments

Comments
 (0)