Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / isomorphism / tests / test_match_helpers.py @ 5cef0f13

History | View | Annotate | Download (2.29 KB)

1
from nose.tools import assert_true, assert_false
2
from operator import eq
3
import networkx as nx
4
from networkx.algorithms import isomorphism as iso
5

    
6

    
7
def test_categorical_node_match():
8
    nm = iso.categorical_node_match(['x', 'y', 'z'], [None] * 3)
9
    assert_true(nm(dict(x=1, y=2, z=3), dict(x=1, y=2, z=3)))
10
    assert_true(not nm(dict(x=1, y=2, z=2), dict(x=1, y=2, z=1)))
11

    
12

    
13
class TestGenericMultiEdgeMatch:
14

    
15
    def setup(self):
16
        self.G1 = nx.MultiDiGraph()
17
        self.G2 = nx.MultiDiGraph()
18
        self.G3 = nx.MultiDiGraph()
19
        self.G4 = nx.MultiDiGraph()
20
        attr_dict1 = {'id': 'edge1', 'minFlow': 0, 'maxFlow': 10}
21
        attr_dict2 = {'id': 'edge2', 'minFlow': -3, 'maxFlow': 7}
22
        attr_dict3 = {'id': 'edge3', 'minFlow': 13, 'maxFlow': 117}
23
        attr_dict4 = {'id': 'edge4', 'minFlow': 13, 'maxFlow': 117}
24
        attr_dict5 = {'id': 'edge5', 'minFlow': 8, 'maxFlow': 12}
25
        attr_dict6 = {'id': 'edge6', 'minFlow': 8, 'maxFlow': 12}
26
        for attr_dict in [attr_dict1, attr_dict2, attr_dict3, attr_dict4, attr_dict5, attr_dict6]:
27
            self.G1.add_edge(1, 2, **attr_dict)
28
        for attr_dict in [attr_dict5, attr_dict3, attr_dict6, attr_dict1, attr_dict4, attr_dict2]:
29
            self.G2.add_edge(2, 3, **attr_dict)
30
        for attr_dict in [attr_dict3, attr_dict5]:
31
            self.G3.add_edge(3, 4, **attr_dict)
32
        for attr_dict in [attr_dict6, attr_dict4]:
33
            self.G4.add_edge(4, 5, **attr_dict)
34

    
35
    def test_generic_multiedge_match(self):
36
        full_match = iso.generic_multiedge_match(['id', 'flowMin', 'flowMax'], [None] * 3, [eq] * 3)
37
        flow_match = iso.generic_multiedge_match(['flowMin', 'flowMax'], [None] * 2, [eq] * 2)
38
        min_flow_match = iso.generic_multiedge_match('flowMin', None, eq)
39
        id_match = iso.generic_multiedge_match('id', None, eq)
40
        assert_true(flow_match(self.G1[1][2], self.G2[2][3]))
41
        assert_true(min_flow_match(self.G1[1][2], self.G2[2][3]))
42
        assert_true(id_match(self.G1[1][2], self.G2[2][3]))
43
        assert_true(full_match(self.G1[1][2], self.G2[2][3]))
44
        assert_true(flow_match(self.G3[3][4], self.G4[4][5]))
45
        assert_true(min_flow_match(self.G3[3][4], self.G4[4][5]))
46
        assert_false(id_match(self.G3[3][4], self.G4[4][5]))
47
        assert_false(full_match(self.G3[3][4], self.G4[4][5]))