Skip to content

Commit

Permalink
Expand test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Oct 12, 2023
1 parent 4c85c9b commit 0b94c19
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/rustworkx_tests/digraph/test_bipartite.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,20 @@ def test_not_biparite(self):
def test_two_color_not_biparite(self):
graph = rustworkx.generators.directed_complete_graph(5)
self.assertIsNone(rustworkx.two_color(graph))

def test_grid_graph(self):
for i in range(10):
for j in range(10):
with self.subTest((i, j)):
graph = rustworkx.generators.directed_grid_graph(i, j)
self.assertTrue(rustworkx.is_bipartite(graph))

def test_cycle_graph(self):
for i in range(20):
with self.subTest(i):
graph = rustworkx.generators.directed_cycle_graph(i)
res = rustworkx.is_bipartite(graph)
if i % 2:
self.assertFalse(res)
else:
self.assertTrue(res)
34 changes: 34 additions & 0 deletions tests/rustworkx_tests/graph/test_bipartite.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,37 @@ def test_not_biparite(self):
def test_two_color_not_biparite(self):
graph = rustworkx.generators.complete_graph(5)
self.assertIsNone(rustworkx.two_color(graph))

def test_bipartite_petersen_graph(self):
# Per Lemma 3 of https://arxiv.org/pdf/1008.3208.pdf A petersen graph is bipartite
# for any even value of n and odd value of k
for i in range(3, 30):
for j in range(30):
n = 2 * i
k = 2 * j + 1
if n <= k * 2:
continue

with self.subTest((n, k)):
graph = rustworkx.generators.generalized_petersen_graph(n, k)
self.assertTrue(rustworkx.is_bipartite(graph))

def test_not_bipartite_petersen_graph(self):
# Per Lemma 3 of https://arxiv.org/pdf/1008.3208.pdf A petersen graph is bipartite
# for any even value of n and odd value of k
for n in range(3, 30):
for k in range(1, 31):
with self.subTest((2 * n, 2 * k)):
if 2 * n > k * 4:
graph = rustworkx.generators.generalized_petersen_graph(2 * n, 2 * k)
self.assertFalse(rustworkx.is_bipartite(graph))
with self.subTest((2 * n + 1, 2 * k)):
if 2 * n + 1 > k * 4:
graph = rustworkx.generators.generalized_petersen_graph(2 * n + 1, 2 * k)
self.assertFalse(rustworkx.is_bipartite(graph))
with self.subTest((2 * n + 1, 2 * k + 1)):
if 2 * n + 1 > k * 4 + 2:
graph = rustworkx.generators.generalized_petersen_graph(
2 * n + 1, 2 * k + 1
)
self.assertFalse(rustworkx.is_bipartite(graph))

0 comments on commit 0b94c19

Please sign in to comment.