Skip to content

Commit 1b0bd16

Browse files
Add doctest for add_vertex in GraphAdjacencyList. Contributes to #9943 (#13143)
* Add doctest for add_vertex in GraphAdjacencyList. Contributes to #9943 * Update graph_adjacency_list.py --------- Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 154cd3e commit 1b0bd16

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

graphs/graph_adjacency_list.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ 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+
>>> g = GraphAdjacencyList(vertices=[], edges=[], directed=False)
66+
>>> g.add_vertex("A")
67+
>>> g.adj_list
68+
{'A': []}
69+
>>> g.add_vertex("A")
70+
Traceback (most recent call last):
71+
...
72+
ValueError: Incorrect input: A is already in the graph.
6473
"""
6574
if self.contains_vertex(vertex):
6675
msg = f"Incorrect input: {vertex} is already in the graph."

0 commit comments

Comments
 (0)