Skip to content
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

adding test coverage for isomorphism when using digraphs #6417

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions networkx/algorithms/isomorphism/tests/test_isomorphism.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

import networkx as nx
from networkx.algorithms import isomorphism as iso
from networkx.exception import NetworkXError
ImHereForTheCookies marked this conversation as resolved.
Show resolved Hide resolved


class TestIsomorph:
Expand All @@ -11,12 +14,18 @@ def setup_class(cls):
cls.G4 = nx.Graph()
cls.G5 = nx.Graph()
cls.G6 = nx.Graph()
cls.DG1 = nx.DiGraph()
cls.DG2 = nx.DiGraph()
cls.DG3 = nx.DiGraph()
cls.G1.add_edges_from([[1, 2], [1, 3], [1, 5], [2, 3]])
cls.G2.add_edges_from([[10, 20], [20, 30], [10, 30], [10, 50]])
cls.G3.add_edges_from([[1, 2], [1, 3], [1, 5], [2, 5]])
cls.G4.add_edges_from([[1, 2], [1, 3], [1, 5], [2, 4]])
cls.G5.add_edges_from([[1, 2], [1, 3]])
cls.G6.add_edges_from([[10, 20], [20, 30], [10, 30], [10, 50], [20, 50]])
cls.DG1.add_edges_from([[1, 2], [1, 3], [1, 5], [2, 3]])
cls.DG2.add_edges_from([[10, 20], [20, 30], [10, 30], [10, 50]])
cls.DG3.add_edges_from([[1, 2], [1, 3], [1, 5], [2, 4]])

def test_could_be_isomorphic(self):
assert iso.could_be_isomorphic(self.G1, self.G2)
Expand All @@ -38,3 +47,9 @@ def test_faster_could_be_isomorphic(self):
def test_is_isomorphic(self):
assert iso.is_isomorphic(self.G1, self.G2)
assert not iso.is_isomorphic(self.G1, self.G4)
assert iso.is_isomorphic(self.DG1, self.DG2)
assert not iso.is_isomorphic(self.DG1, self.DG3)
with pytest.raises(
nx.NetworkXError, match="Graphs G1 and G2 are not of the same type."
):
iso.is_isomorphic(self.DG1, self.G1)
ImHereForTheCookies marked this conversation as resolved.
Show resolved Hide resolved