Skip to content

Commit c362106

Browse files
author
CindeeM
committed
TEST: add test for Louvain class, communities_without_node
1 parent 8fba2a0 commit c362106

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

brainx/tests/test_weighted_modularity.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,27 @@ def setUp(self):
142142
graph, communities = get_test_data()
143143
self.graph = graph
144144
self.communities = communities
145+
self.louvain = wm.LouvainCommunityDetection(graph)
146+
self.louvain_comm = wm.LouvainCommunityDetection(graph, communities)
145147

146148
def test_init(self):
147-
louvain = wm.LouvainCommunityDetection(self.graph)
149+
louvain = self.louvain
148150
self.assertEqual(louvain.graph, self.graph)
149151
self.assertEqual(louvain.initial_communities, None)
150152
self.assertEqual(louvain.minthr, 0.0000001)
151-
"""
152153

153-
def test_communities_without_node():
154-
graph, communities = get_test_data()
155-
part = wm.WeightedPartition(graph) # one comm per node
156-
node = 0
157-
updated_comm = wm._communities_without_node(part, node )
158-
npt.assert_equal(updated_comm[0], set([]))
159-
part = wm.WeightedPartition(graph, communities)
160-
updated_comm = wm._communities_without_node(part, node )
161-
## make sure we dont break communities from original partition
162-
npt.assert_equal(part.communities, communities)
163-
npt.assert_equal(0 not in updated_comm[0], True)
164154

155+
def test_communities_without_node(self):
156+
part = wm.WeightedPartition(self.graph) # one comm per node
157+
node = 0
158+
updated_comm = self.louvain._communities_without_node(part, node)
159+
self.assertEqual(updated_comm[0], set([]))
160+
part = wm.WeightedPartition(self.graph, self.communities)
161+
updated_comm = self.louvain_comm._communities_without_node(part, node)
162+
## make sure we dont break communities from original partition
163+
self.assertEqual(part.communities, self.communities)
164+
self.assertEqual(0 not in updated_comm[0], True)
165+
"""
165166
def test_communities_nodes_alledgesw():
166167
graph, communities = get_test_data()
167168
part = wm.WeightedPartition(graph, communities)

brainx/weighted_modularity.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ def _calc_delta_modularity(node, part):
259259
totc = np.array(totc)
260260
return dnc - totc*noded / (total_weight*2)
261261

262-
263262
@staticmethod
264263
def _communities_without_node(part, node):
265264
""" returns a version of the partition with the node
@@ -302,7 +301,6 @@ def _move_node(part, node, new_comm):
302301
new_community = [x for x in new_community if len(x) > 0]
303302
return WeightedPartition(part.graph, new_community)
304303

305-
306304
@staticmethod
307305
def partitions_from_dendogram(dendo):
308306
""" returns community partitions based on results in dendogram

0 commit comments

Comments
 (0)