def test_all_simple_paths(self): graph = retworkx.PyGraph() for i in range(6): graph.add_node(i) graph.add_edges_from_no_data(self.edges) paths = retworkx.graph_all_simple_paths(graph, 0, 5) expected = [ [0, 3, 4, 5], [0, 3, 4, 2, 5], [0, 3, 4, 2, 5], [0, 3, 2, 4, 5], [0, 3, 2, 5], [0, 3, 2, 4, 5], [0, 3, 5], [0, 3, 2, 4, 5], [0, 3, 2, 5], [0, 3, 2, 4, 5], [0, 3, 1, 2, 4, 5], [0, 3, 1, 2, 5], [0, 3, 1, 2, 4, 5], [0, 2, 4, 5], [0, 2, 4, 3, 5], [0, 2, 3, 4, 5], [0, 2, 3, 5], [0, 2, 5], [0, 2, 4, 5], [0, 2, 4, 3, 5], [0, 2, 3, 4, 5], [0, 2, 3, 5], [0, 2, 1, 3, 4, 5], [0, 2, 1, 3, 5], [0, 1, 3, 4, 5], [0, 1, 3, 4, 2, 5], [0, 1, 3, 4, 2, 5], [0, 1, 3, 2, 4, 5], [0, 1, 3, 2, 5], [0, 1, 3, 2, 4, 5], [0, 1, 3, 5], [0, 1, 3, 2, 4, 5], [0, 1, 3, 2, 5], [0, 1, 3, 2, 4, 5], [0, 1, 2, 4, 5], [0, 1, 2, 4, 3, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 5], [0, 1, 2, 5], [0, 1, 2, 4, 5], [0, 1, 2, 4, 3, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 5], ] self.assertEqual(len(expected), len(paths)) for i in expected: self.assertIn(i, paths)
def test_all_simple_paths_with_min_depth_and_cutoff(self): graph = retworkx.PyGraph() for i in range(6): graph.add_node(i) graph.add_edges_from_no_data(self.edges) paths = retworkx.graph_all_simple_paths(graph, 0, 5, min_depth=4, cutoff=4) expected = [[0, 3, 4, 5], [0, 3, 2, 5], [0, 3, 2, 5], [0, 2, 4, 5], [0, 2, 3, 5], [0, 2, 4, 5], [0, 2, 3, 5], [0, 1, 3, 5], [0, 1, 2, 5]] self.assertEqual(len(expected), len(paths)) for i in expected: self.assertIn(i, paths)
def test_all_simple_path_invalid_node_index(self): dag = retworkx.PyGraph() dag.add_node(0) dag.add_node(1) with self.assertRaises(retworkx.InvalidNode): retworkx.graph_all_simple_paths(dag, 0, 5)
def test_all_simple_path_no_path(self): dag = retworkx.PyGraph() dag.add_node(0) dag.add_node(1) self.assertEqual([], retworkx.graph_all_simple_paths(dag, 0, 1))