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>
This commit is contained in:
michaelmccamy
2025-10-19 20:29:59 -04:00
committed by GitHub
parent 154cd3e400
commit 1b0bd16729

View File

@@ -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."