Skip to content

Add to doctests #12790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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 coverage to Graph.remove_pair
  • Loading branch information
tioBlachi committed Jun 9, 2025
commit 5835a46c716760e77397ab7e0085abb870e61093
29 changes: 29 additions & 0 deletions graphs/directed_and_undirected_weighted_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,35 @@ def add_pair(self, u, v, w=1) -> None:

# handles if the input does not exist
def remove_pair(self, u, v):
"""
Removes the edge between u and v in an unidirected graph, if it exists

>>> g = Graph()
>>> g.add_pair(1,2)
>>> g.add_pair(1,3,5)
>>> g.graph[1]
[[1, 2], [5, 3]]
>>> g.remove_pair(1, 2)
>>> g.graph[1]
[[5, 3]]
>>> g.graph[2]
[]
>>> g.remove_pair(1,4) # node 4 does not exist
>>> g.remove_pair(10, 11) # neither exists
>>> g.add_pair(5,5)
>>> g.graph[5]
[[1, 5]]
>>> g.remove_pair(5,5)
>>> g.graph[5]
[]
>>> g.add_pair(6,7,2)
>>> g.add_pair(6,7,3)
>>> g.graph[6]
[[2, 7], [3, 7]]
>>> g.remove_pair(6,7)
>>> g.graph[6]
[[3, 7]]
"""
if self.graph.get(u):
for _ in self.graph[u]:
if _[1] == v:
Expand Down