Closed Sappique closed 6 months ago
Excellent catch. Let me fix that immediately.
I just tested it again and figured out that has_cycles
returns false if any of the disconnected parts of the graph have no cycles.
If all disconnected parts have cycles it returns true (as expected):
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
>>> from graph import Graph
>>> g = Graph(from_list=[(1,2),(2,3),(3,1)])
>>> g.has_cycles()
True
>>> g.add_edge(4,5)
>>> g.has_cycles()
False
>>> g.add_edge(5,4)
>>> g.has_cycles()
True
Good catch. It's due to the same bug.
I'm running the test suite right now. I'll release a new package in a minute or so when it finishes.
Bugfix release created as 2023.7.5. Credit assigned to your github id.
The version is available on pypi.org as https://pypi.org/project/graph-theory/2023.7.5/
To upgrade use pip install --upgrade graph-theory
Thanks again ;-)
@Sappique - feel free to close the ticket if you are satisfied.
The function
has_cycles
allways returns false if the graph is disconnected, including when a cycle exists.If this is the intended behavior, the documentation should be modified to clearly convey that.
To reproduce
Additional information
I'm using version 2023.7.4 of graph-theory with Python 3.10 on windows.