From ca53ba4922dca4632df967a67555c0b2cd64c1e0 Mon Sep 17 00:00:00 2001 From: Michael McCamy Date: Fri, 3 Oct 2025 11:46:03 -0400 Subject: [PATCH] Add doctest for add_vertex in GraphAdjacencyList. Contributes to #9943 --- graphs/graph_adjacency_list.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/graphs/graph_adjacency_list.py b/graphs/graph_adjacency_list.py index c901e2cf3dac..8a3eb8a6e306 100644 --- a/graphs/graph_adjacency_list.py +++ b/graphs/graph_adjacency_list.py @@ -61,6 +61,16 @@ def add_vertex(self, vertex: T) -> None: """ Adds a vertex to the graph. If the given vertex already exists, a ValueError will be thrown. + + Example: + >>> 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."