Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add doctest for add_vertex in GraphAdjacencyList. Contributes to TheA…
…lgorithms#9943 (TheAlgorithms#13143)

* Add doctest for add_vertex in GraphAdjacencyList. Contributes to TheAlgorithms#9943

* Update graph_adjacency_list.py

---------

Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
  • Loading branch information
michaelmccamy and MaximSmolskiy authored Oct 20, 2025
commit 1b0bd167290bbdd5cb56972f1c6fb8d18698c839
9 changes: 9 additions & 0 deletions graphs/graph_adjacency_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ def add_vertex(self, vertex: T) -> None:
"""
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."
Expand Down