@@ -35,7 +35,7 @@ def get_test_data():
35
35
communities = [set (range (42 )), set (range (42 ,86 ))]
36
36
return graph , communities
37
37
38
- class TestPartition (unittest .TestCase ):
38
+ class TestWeightedPartition (unittest .TestCase ):
39
39
40
40
def setUp (self ):
41
41
## generate a default graph and communities
@@ -134,23 +134,21 @@ def test_dnodecom(self):
134
134
node2comm_weights = part .dnodecom (node )
135
135
npt .assert_equal (len (node2comm_weights ), 2 )
136
136
137
- def test_meta_graph ():
138
- graph , communities = get_test_data ()
139
- part = wm .WeightedPartition (graph )
140
- metagraph ,_ = wm .meta_graph (part )
141
- ## each node is a comm, so no change to metagraph
142
- npt .assert_equal (metagraph .nodes (), graph .nodes ())
143
- ## two communitties
144
- part = wm .WeightedPartition (graph , communities )
145
- metagraph ,mapping = wm .meta_graph (part )
146
- npt .assert_equal (metagraph .nodes (), [0 ,1 ])
147
- npt .assert_equal (metagraph .edges (), [(0 ,0 ),(0 ,1 ), (1 ,1 )])
148
- # mapping should map new node 0 to communities[0]
149
- npt .assert_equal (mapping [0 ], communities [0 ])
150
- ## weight should not be lost between graphs
151
- npt .assert_almost_equal (metagraph .size (weight = 'weight' ),
152
- graph .size (weight = 'weight' ))
153
137
138
+ class TestLouvainCommunityDetection (unittest .TestCase ):
139
+
140
+ def setUp (self ):
141
+ ## generate a default graph and communities
142
+ graph , communities = get_test_data ()
143
+ self .graph = graph
144
+ self .communities = communities
145
+
146
+ def test_init (self ):
147
+ louvain = wm .LouvainCommunityDetection (self .graph )
148
+ self .assertEqual (louvain .graph , self .graph )
149
+ self .assertEqual (louvain .initial_communities , None )
150
+ self .assertEqual (louvain .minthr , 0.0000001 )
151
+ """
154
152
155
153
def test_communities_without_node():
156
154
graph, communities = get_test_data()
@@ -181,12 +179,6 @@ def test_communities_nodes_alledgesw():
181
179
182
180
183
181
184
- def test_combine ():
185
- first = [set ([0 ,1 ,2 ]), set ([3 ,4 ,5 ]), set ([6 ,7 ])]
186
- second = [set ([0 ,2 ]), set ([1 ])]
187
- npt .assert_raises (ValueError , wm ._combine , second , first )
188
- res = wm ._combine (first , second )
189
- npt .assert_equal (res , [set ([0 ,1 ,2 ,6 ,7 ]), set ([3 ,4 ,5 ])])
190
182
191
183
192
184
def test_calc_delta_modularity():
@@ -216,4 +208,29 @@ def test_move_node():
216
208
newpart = wm._move_node(part, -1, comm)
217
209
invalid_communities = len(part.communities) + 1
218
210
with npt.assert_raises(IndexError):
219
- newpart = wm ._move_node (part , node , invalid_communities )
211
+ newpart = wm._move_node(part, node, invalid_communities)
212
+
213
+ """
214
+ def test_combine ():
215
+ first = [set ([0 ,1 ,2 ]), set ([3 ,4 ,5 ]), set ([6 ,7 ])]
216
+ second = [set ([0 ,2 ]), set ([1 ])]
217
+ npt .assert_raises (ValueError , wm ._combine , second , first )
218
+ res = wm ._combine (first , second )
219
+ npt .assert_equal (res , [set ([0 ,1 ,2 ,6 ,7 ]), set ([3 ,4 ,5 ])])
220
+
221
+ def test_meta_graph ():
222
+ graph , communities = get_test_data ()
223
+ part = wm .WeightedPartition (graph )
224
+ metagraph ,_ = wm .meta_graph (part )
225
+ ## each node is a comm, so no change to metagraph
226
+ npt .assert_equal (metagraph .nodes (), graph .nodes ())
227
+ ## two communitties
228
+ part = wm .WeightedPartition (graph , communities )
229
+ metagraph ,mapping = wm .meta_graph (part )
230
+ npt .assert_equal (metagraph .nodes (), [0 ,1 ])
231
+ npt .assert_equal (metagraph .edges (), [(0 ,0 ),(0 ,1 ), (1 ,1 )])
232
+ # mapping should map new node 0 to communities[0]
233
+ npt .assert_equal (mapping [0 ], communities [0 ])
234
+ ## weight should not be lost between graphs
235
+ npt .assert_almost_equal (metagraph .size (weight = 'weight' ),
236
+ graph .size (weight = 'weight' ))
0 commit comments