(N=1)
| 254 | |
| 255 | |
| 256 | def test_all_paths(N=1): |
| 257 | np.random.seed(12345) |
| 258 | i = 0 |
| 259 | while i < N: |
| 260 | p = np.random.rand() |
| 261 | directed = np.random.rand() < 0.5 |
| 262 | G = random_unweighted_graph(n_vertices=5, edge_prob=p, directed=directed) |
| 263 | |
| 264 | nodes = G._I2V.keys() |
| 265 | G_nx = to_networkx(G) |
| 266 | |
| 267 | # for each graph, test all_paths for all pairs of start and end |
| 268 | # vertices. note that graph is not guaranteed to be connected, so many |
| 269 | # paths will be empty |
| 270 | for s_i in nodes: |
| 271 | for e_i in nodes: |
| 272 | if s_i == e_i: |
| 273 | continue |
| 274 | |
| 275 | paths = G.all_paths(s_i, e_i) |
| 276 | paths_nx = nx.all_simple_paths(G_nx, source=s_i, target=e_i, cutoff=10) |
| 277 | |
| 278 | paths = sorted(paths) |
| 279 | paths_nx = sorted(list(paths_nx)) |
| 280 | |
| 281 | for p1, p2 in zip(paths, paths_nx): |
| 282 | np.testing.assert_array_equal(p1, p2) |
| 283 | |
| 284 | print("PASSED") |
| 285 | i += 1 |
| 286 | |
| 287 | |
| 288 | def test_random_DAG(N=1): |
nothing calls this directly
no test coverage detected