@@ -162,56 +162,46 @@ def test_communities_without_node(self):
162
162
## make sure we dont break communities from original partition
163
163
self .assertEqual (part .communities , self .communities )
164
164
self .assertEqual (0 not in updated_comm [0 ], True )
165
- """
166
- def test_communities_nodes_alledgesw():
167
- graph, communities = get_test_data()
168
- part = wm.WeightedPartition(graph, communities)
169
- node = 0
170
- weights = wm._communities_nodes_alledgesw(part, node)
171
- npt.assert_almost_equal(weights[0], 1424.0220362)
172
- ## test with possible empty node set
173
- part = wm.WeightedPartition(graph)
174
- weights = wm._communities_nodes_alledgesw(part, node)
175
- npt.assert_equal(weights[0], 0)
176
- # other communities are made up of just one node
177
- npt.assert_equal(weights[1], graph.degree(weight='weight')[1])
178
-
179
-
180
-
181
165
166
+ def test_communities_nodes_alledgesw (self ):
167
+ part = wm .WeightedPartition (self .graph , self .communities )
168
+ node = 0
169
+ weights = self .louvain_comm ._communities_nodes_alledgesw (part , node )
170
+ npt .assert_almost_equal (weights [0 ], 1424.0220362 )
171
+ ## test with possible empty node set
172
+ part = wm .WeightedPartition (self .graph )
173
+ weights = self .louvain ._communities_nodes_alledgesw (part , node )
174
+ self .assertEqual (weights [0 ], 0 )
175
+ # other communities are made up of just one node
176
+ self .assertEqual (weights [1 ], self .graph .degree (weight = 'weight' )[1 ])
182
177
183
178
179
+ def test_calc_delta_modularity (self ):
180
+ part = wm .WeightedPartition (self .graph ) # one comm per node
181
+ node = 0
182
+ change = self .louvain ._calc_delta_modularity (node , part )
183
+ self .assertEqual (len (change ), len (part .communities ))
184
+ # change is an array
185
+ self .assertEqual (change .shape [0 ], len (part .communities ))
186
+ self .assertEqual (change [0 ] < change [1 ], True )
187
+ # this is one comm per node, so once removed from own
188
+ # comm, this delta_weight will be zero
189
+ self .assertEqual (change [node ] , 0 )
190
+
191
+ def test_move_node (self ):
192
+ part = wm .WeightedPartition (self .graph ) # one comm per node
193
+ #move first node to second community
194
+ node = 0
195
+ comm = 1
196
+ newpart = self .louvain ._move_node (part , node , comm )
197
+ self .assertEqual (set ([0 ,1 ]) in newpart .communities , True )
198
+ ## what happens if node or comm missing
199
+ with self .assertRaises (ValueError ):
200
+ newpart = self .louvain ._move_node (part , - 1 , comm )
201
+ invalid_communities = len (part .communities ) + 1
202
+ with self .assertRaises (IndexError ):
203
+ newpart = self .louvain ._move_node (part , node , invalid_communities )
184
204
185
- def test_calc_delta_modularity():
186
- graph, communities = get_test_data()
187
- part = wm.WeightedPartition(graph) # one comm per node
188
- node = 0
189
- change = wm._calc_delta_modularity(node, part)
190
- npt.assert_equal(len(change), len(part.communities))
191
- # change is an array
192
- npt.assert_equal(change.shape[0], len(part.communities))
193
- npt.assert_equal(change[0] < change[1], True)
194
- # this is one comm per node, so once removed from own
195
- # comm, this delta_weight will be zero
196
- npt.assert_equal(change[node] , 0)
197
-
198
-
199
- def test_move_node():
200
- graph, communities = get_test_data()
201
- part = wm.WeightedPartition(graph) # one comm per node
202
- #move first node to second community
203
- node = 0
204
- comm = 1
205
- newpart = wm._move_node(part, node, comm )
206
- npt.assert_equal(set([0,1]) in newpart.communities, True)
207
- ## what happens if node or comm missing
208
- with npt.assert_raises(ValueError):
209
- newpart = wm._move_node(part, -1, comm)
210
- invalid_communities = len(part.communities) + 1
211
- with npt.assert_raises(IndexError):
212
- newpart = wm._move_node(part, node, invalid_communities)
213
-
214
- """
215
205
def test_combine ():
216
206
first = [set ([0 ,1 ,2 ]), set ([3 ,4 ,5 ]), set ([6 ,7 ])]
217
207
second = [set ([0 ,2 ]), set ([1 ])]
0 commit comments