MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / test_all_paths

Function test_all_paths

numpy_ml/tests/test_utils.py:256–285  ·  view source on GitHub ↗
(N=1)

Source from the content-addressed store, hash-verified

254
255
256def 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
288def test_random_DAG(N=1):

Callers

nothing calls this directly

Calls 3

random_unweighted_graphFunction · 0.90
to_networkxFunction · 0.85
all_pathsMethod · 0.80

Tested by

no test coverage detected