comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_graph_hashing.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import networkx as nx
2
3
4 def test_empty_graph_hash():
5 G1 = nx.empty_graph()
6 G2 = nx.empty_graph()
7
8 h1 = nx.weisfeiler_lehman_graph_hash(G1)
9 h2 = nx.weisfeiler_lehman_graph_hash(G2)
10
11 assert h1 == h2
12
13
14 def test_relabel():
15 G1 = nx.Graph()
16 G1.add_edges_from(
17 [
18 (1, 2, {"label": "A"}),
19 (2, 3, {"label": "A"}),
20 (3, 1, {"label": "A"}),
21 (1, 4, {"label": "B"}),
22 ]
23 )
24 h_before = nx.weisfeiler_lehman_graph_hash(G1, edge_attr="label")
25
26 G2 = nx.relabel_nodes(G1, {u: -1 * u for u in G1.nodes()})
27
28 h_after = nx.weisfeiler_lehman_graph_hash(G2, edge_attr="label")
29
30 assert h_after == h_before
31
32
33 def test_directed():
34 G1 = nx.DiGraph()
35 G1.add_edges_from([(1, 2), (2, 3), (3, 1), (1, 5)])
36
37 h_directed = nx.weisfeiler_lehman_graph_hash(G1)
38
39 G2 = G1.to_undirected()
40 h_undirected = nx.weisfeiler_lehman_graph_hash(G2)
41
42 assert h_directed != h_undirected