Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / classes / tests / test_filters.py @ 5cef0f13

History | View | Annotate | Download (6.12 KB)

1
from nose.tools import assert_true, assert_false, assert_raises
2
import networkx as nx
3

    
4

    
5
class TestFilterFactory(object):
6
    def test_no_filter(self):
7
        nf = nx.filters.no_filter
8
        assert_true(nf())
9
        assert_true(nf(1))
10
        assert_true(nf(2, 1))
11

    
12
    def test_hide_nodes(self):
13
        f = nx.classes.filters.hide_nodes([1, 2, 3])
14
        assert_false(f(1))
15
        assert_false(f(2))
16
        assert_false(f(3))
17
        assert_true(f(4))
18
        assert_true(f(0))
19
        assert_true(f('a'))
20
        assert_raises(TypeError, f, 1, 2)
21
        assert_raises(TypeError, f)
22

    
23
    def test_show_nodes(self):
24
        f = nx.classes.filters.show_nodes([1, 2, 3])
25
        assert_true(f(1))
26
        assert_true(f(2))
27
        assert_true(f(3))
28
        assert_false(f(4))
29
        assert_false(f(0))
30
        assert_false(f('a'))
31
        assert_raises(TypeError, f, 1, 2)
32
        assert_raises(TypeError, f)
33

    
34
    def test_hide_edges(self):
35
        factory = nx.classes.filters.hide_edges
36
        f = factory([(1, 2), (3, 4)])
37
        assert_false(f(1, 2))
38
        assert_false(f(3, 4))
39
        assert_false(f(4, 3))
40
        assert_true(f(2, 3))
41
        assert_true(f(0, -1))
42
        assert_true(f('a', 'b'))
43
        assert_raises(TypeError, f, 1, 2, 3)
44
        assert_raises(TypeError, f, 1)
45
        assert_raises(TypeError, f)
46
        assert_raises(TypeError, factory, [1, 2, 3])
47
        assert_raises(ValueError, factory, [(1, 2, 3)])
48

    
49
    def test_show_edges(self):
50
        factory = nx.classes.filters.show_edges
51
        f = factory([(1, 2), (3, 4)])
52
        assert_true(f(1, 2))
53
        assert_true(f(3, 4))
54
        assert_true(f(4, 3))
55
        assert_false(f(2, 3))
56
        assert_false(f(0, -1))
57
        assert_false(f('a', 'b'))
58
        assert_raises(TypeError, f, 1, 2, 3)
59
        assert_raises(TypeError, f, 1)
60
        assert_raises(TypeError, f)
61
        assert_raises(TypeError, factory, [1, 2, 3])
62
        assert_raises(ValueError, factory, [(1, 2, 3)])
63

    
64
    def test_hide_diedges(self):
65
        factory = nx.classes.filters.hide_diedges
66
        f = factory([(1, 2), (3, 4)])
67
        assert_false(f(1, 2))
68
        assert_false(f(3, 4))
69
        assert_true(f(4, 3))
70
        assert_true(f(2, 3))
71
        assert_true(f(0, -1))
72
        assert_true(f('a', 'b'))
73
        assert_raises(TypeError, f, 1, 2, 3)
74
        assert_raises(TypeError, f, 1)
75
        assert_raises(TypeError, f)
76
        assert_raises(TypeError, factory, [1, 2, 3])
77
        assert_raises(ValueError, factory, [(1, 2, 3)])
78

    
79
    def test_show_diedges(self):
80
        factory = nx.classes.filters.show_diedges
81
        f = factory([(1, 2), (3, 4)])
82
        assert_true(f(1, 2))
83
        assert_true(f(3, 4))
84
        assert_false(f(4, 3))
85
        assert_false(f(2, 3))
86
        assert_false(f(0, -1))
87
        assert_false(f('a', 'b'))
88
        assert_raises(TypeError, f, 1, 2, 3)
89
        assert_raises(TypeError, f, 1)
90
        assert_raises(TypeError, f)
91
        assert_raises(TypeError, factory, [1, 2, 3])
92
        assert_raises(ValueError, factory, [(1, 2, 3)])
93

    
94
    def test_hide_multiedges(self):
95
        factory = nx.classes.filters.hide_multiedges
96
        f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])
97
        assert_false(f(1, 2, 0))
98
        assert_false(f(1, 2, 1))
99
        assert_true(f(1, 2, 2))
100
        assert_true(f(3, 4, 0))
101
        assert_false(f(3, 4, 1))
102
        assert_false(f(4, 3, 1))
103
        assert_true(f(4, 3, 0))
104
        assert_true(f(2, 3, 0))
105
        assert_true(f(0, -1, 0))
106
        assert_true(f('a', 'b', 0))
107
        assert_raises(TypeError, f, 1, 2, 3, 4)
108
        assert_raises(TypeError, f, 1, 2)
109
        assert_raises(TypeError, f, 1)
110
        assert_raises(TypeError, f)
111
        assert_raises(TypeError, factory, [1, 2, 3])
112
        assert_raises(ValueError, factory, [(1, 2)])
113
        assert_raises(ValueError, factory, [(1, 2, 3, 4)])
114

    
115
    def test_show_multiedges(self):
116
        factory = nx.classes.filters.show_multiedges
117
        f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])
118
        assert_true(f(1, 2, 0))
119
        assert_true(f(1, 2, 1))
120
        assert_false(f(1, 2, 2))
121
        assert_false(f(3, 4, 0))
122
        assert_true(f(3, 4, 1))
123
        assert_true(f(4, 3, 1))
124
        assert_false(f(4, 3, 0))
125
        assert_false(f(2, 3, 0))
126
        assert_false(f(0, -1, 0))
127
        assert_false(f('a', 'b', 0))
128
        assert_raises(TypeError, f, 1, 2, 3, 4)
129
        assert_raises(TypeError, f, 1, 2)
130
        assert_raises(TypeError, f, 1)
131
        assert_raises(TypeError, f)
132
        assert_raises(TypeError, factory, [1, 2, 3])
133
        assert_raises(ValueError, factory, [(1, 2)])
134
        assert_raises(ValueError, factory, [(1, 2, 3, 4)])
135

    
136
    def test_hide_multidiedges(self):
137
        factory = nx.classes.filters.hide_multidiedges
138
        f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])
139
        assert_false(f(1, 2, 0))
140
        assert_false(f(1, 2, 1))
141
        assert_true(f(1, 2, 2))
142
        assert_true(f(3, 4, 0))
143
        assert_false(f(3, 4, 1))
144
        assert_true(f(4, 3, 1))
145
        assert_true(f(4, 3, 0))
146
        assert_true(f(2, 3, 0))
147
        assert_true(f(0, -1, 0))
148
        assert_true(f('a', 'b', 0))
149
        assert_raises(TypeError, f, 1, 2, 3, 4)
150
        assert_raises(TypeError, f, 1, 2)
151
        assert_raises(TypeError, f, 1)
152
        assert_raises(TypeError, f)
153
        assert_raises(TypeError, factory, [1, 2, 3])
154
        assert_raises(ValueError, factory, [(1, 2)])
155
        assert_raises(ValueError, factory, [(1, 2, 3, 4)])
156

    
157
    def test_show_multidiedges(self):
158
        factory = nx.classes.filters.show_multidiedges
159
        f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])
160
        assert_true(f(1, 2, 0))
161
        assert_true(f(1, 2, 1))
162
        assert_false(f(1, 2, 2))
163
        assert_false(f(3, 4, 0))
164
        assert_true(f(3, 4, 1))
165
        assert_false(f(4, 3, 1))
166
        assert_false(f(4, 3, 0))
167
        assert_false(f(2, 3, 0))
168
        assert_false(f(0, -1, 0))
169
        assert_false(f('a', 'b', 0))
170
        assert_raises(TypeError, f, 1, 2, 3, 4)
171
        assert_raises(TypeError, f, 1, 2)
172
        assert_raises(TypeError, f, 1)
173
        assert_raises(TypeError, f)
174
        assert_raises(TypeError, factory, [1, 2, 3])
175
        assert_raises(ValueError, factory, [(1, 2)])
176
        assert_raises(ValueError, factory, [(1, 2, 3, 4)])