comparison env/lib/python3.9/site-packages/networkx/algorithms/isomorphism/tests/test_match_helpers.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 from operator import eq
2 import networkx as nx
3 from networkx.algorithms import isomorphism as iso
4
5
6 def test_categorical_node_match():
7 nm = iso.categorical_node_match(["x", "y", "z"], [None] * 3)
8 assert nm(dict(x=1, y=2, z=3), dict(x=1, y=2, z=3))
9 assert not nm(dict(x=1, y=2, z=2), dict(x=1, y=2, z=1))
10
11
12 class TestGenericMultiEdgeMatch:
13 def setup(self):
14 self.G1 = nx.MultiDiGraph()
15 self.G2 = nx.MultiDiGraph()
16 self.G3 = nx.MultiDiGraph()
17 self.G4 = nx.MultiDiGraph()
18 attr_dict1 = {"id": "edge1", "minFlow": 0, "maxFlow": 10}
19 attr_dict2 = {"id": "edge2", "minFlow": -3, "maxFlow": 7}
20 attr_dict3 = {"id": "edge3", "minFlow": 13, "maxFlow": 117}
21 attr_dict4 = {"id": "edge4", "minFlow": 13, "maxFlow": 117}
22 attr_dict5 = {"id": "edge5", "minFlow": 8, "maxFlow": 12}
23 attr_dict6 = {"id": "edge6", "minFlow": 8, "maxFlow": 12}
24 for attr_dict in [
25 attr_dict1,
26 attr_dict2,
27 attr_dict3,
28 attr_dict4,
29 attr_dict5,
30 attr_dict6,
31 ]:
32 self.G1.add_edge(1, 2, **attr_dict)
33 for attr_dict in [
34 attr_dict5,
35 attr_dict3,
36 attr_dict6,
37 attr_dict1,
38 attr_dict4,
39 attr_dict2,
40 ]:
41 self.G2.add_edge(2, 3, **attr_dict)
42 for attr_dict in [attr_dict3, attr_dict5]:
43 self.G3.add_edge(3, 4, **attr_dict)
44 for attr_dict in [attr_dict6, attr_dict4]:
45 self.G4.add_edge(4, 5, **attr_dict)
46
47 def test_generic_multiedge_match(self):
48 full_match = iso.generic_multiedge_match(
49 ["id", "flowMin", "flowMax"], [None] * 3, [eq] * 3
50 )
51 flow_match = iso.generic_multiedge_match(
52 ["flowMin", "flowMax"], [None] * 2, [eq] * 2
53 )
54 min_flow_match = iso.generic_multiedge_match("flowMin", None, eq)
55 id_match = iso.generic_multiedge_match("id", None, eq)
56 assert flow_match(self.G1[1][2], self.G2[2][3])
57 assert min_flow_match(self.G1[1][2], self.G2[2][3])
58 assert id_match(self.G1[1][2], self.G2[2][3])
59 assert full_match(self.G1[1][2], self.G2[2][3])
60 assert flow_match(self.G3[3][4], self.G4[4][5])
61 assert min_flow_match(self.G3[3][4], self.G4[4][5])
62 assert not id_match(self.G3[3][4], self.G4[4][5])
63 assert not full_match(self.G3[3][4], self.G4[4][5])