diff --git a/tests/rustworkx_tests/digraph/test_bipartite.py b/tests/rustworkx_tests/digraph/test_bipartite.py index 0fe1111139..f3e29bdde3 100644 --- a/tests/rustworkx_tests/digraph/test_bipartite.py +++ b/tests/rustworkx_tests/digraph/test_bipartite.py @@ -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) diff --git a/tests/rustworkx_tests/graph/test_bipartite.py b/tests/rustworkx_tests/graph/test_bipartite.py index 6965d1daa1..59c2eb9da5 100644 --- a/tests/rustworkx_tests/graph/test_bipartite.py +++ b/tests/rustworkx_tests/graph/test_bipartite.py @@ -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))