Skip to content

Commit 937d99e

Browse files
author
mb3152
committed
speed up tests, made explicit communities
1 parent cde0ed2 commit 937d99e

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

brainx/tests/test_nodal_roles.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,36 @@
11
#test nodal roles
22
import unittest
33
import networkx as nx
4-
from .. import nodal_roles as nr
5-
from .. import weighted_modularity as wm
4+
import nodal_roles as nr
5+
import weighted_modularity as wm
66

77
class TestNodalRoles(unittest.TestCase):
88
def test_participation_coefficient_edgeless(self):
99
graph = nx.Graph([(0,1)])
1010
graph.add_node(2)
11-
louvain = wm.LouvainCommunityDetection(graph)
12-
weighted_partitions = louvain.run()
13-
weighted_partition = weighted_partitions[0]
11+
partition = wm.WeightedPartition(graph, communities=[ set([0,1]), set([2])])
1412
with self.assertRaises(ValueError):
15-
nr.participation_coefficient(weighted_partition)
16-
graph = nx.Graph([(0,1),(1,2),(2,0),(3,4),(3,5),(4,5)])
17-
louvain = wm.LouvainCommunityDetection(graph)
18-
partition = louvain.run()[0]
13+
nr.participation_coefficient(partition)
1914
def test_within_community_degree_edgeless(self):
2015
graph = nx.Graph([(0,1)])
2116
graph.add_node(2)
22-
louvain = wm.LouvainCommunityDetection(graph)
23-
weighted_partitions = louvain.run()
24-
weighted_partition = weighted_partitions[0]
17+
partition = wm.WeightedPartition(graph, communities=[ set([0,1]), set([2])])
2518
with self.assertRaises(ValueError):
26-
nr.within_community_degree(weighted_partition)
19+
nr.within_community_degree(partition)
2720
def test_disconnected_communites(self):
2821
graph = nx.Graph([(0,1),(1,2),(2,0),(3,4),(3,5),(4,5)])
29-
louvain = wm.LouvainCommunityDetection(graph)
30-
partition = louvain.run()[0]
22+
partition = wm.WeightedPartition(graph, communities=[set([0, 1, 2]), set([3, 4, 5])])
3123
wcd = nr.within_community_degree(partition)
32-
self.assertEqual(wcd, {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0})
24+
self.assertAlmostEqual(wcd, {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0})
3325
pc = nr.participation_coefficient(partition)
3426
self.assertEqual(pc, {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0})
3527
def test_high_low_pc(self):
3628
graph = nx.Graph([(0,1),(1,2),(2,0),(0,3),(3,4),(3,5),(4,5)])
37-
louvain = wm.LouvainCommunityDetection(graph)
38-
partition = louvain.run()[0]
29+
partition = wm.WeightedPartition(graph, communities=[set([0, 1, 2]), set([3, 4, 5])])
3930
pc = nr.participation_coefficient(partition)
40-
self.assertEqual(pc,{0: 0.8888888888888888, 1: 0.0, 2: 0.0, 3: 0.8888888888888888, 4: 0.0, 5: 0.0})
31+
self.assertAlmostEqual(pc,{0: 0.8888888888888888, 1: 0.0, 2: 0.0, 3: 0.8888888888888888, 4: 0.0, 5: 0.0})
4132
def test_high_low_wcd(self):
4233
graph = nx.Graph([(0,1),(0,2),(0,3),(0,4),(0,5),(6,7),(7,8),(8,6)])
43-
louvain = wm.LouvainCommunityDetection(graph)
44-
partition = louvain.run()[0]
34+
partition = wm.WeightedPartition(graph, communities=[set([0, 1, 2, 3, 4, 5]), set([8, 6, 7])])
4535
wcd = nr.within_community_degree(partition)
46-
self.assertEqual(wcd, {0: 3.8819660112501051, 1: -0.11803398874989512, 2: -0.11803398874989512, 3: -0.11803398874989512,4: -0.11803398874989512, 5: -0.11803398874989512, 6: 0.0, 7: 0.0, 8: 0.0})
47-
48-
36+
self.assertAlmostEqual(wcd, {0: 3.8819660112501051, 1: -0.11803398874989512, 2: -0.11803398874989512, 3: -0.11803398874989512,4: -0.11803398874989512, 5: -0.11803398874989512, 6: 0.0, 7: 0.0, 8: 0.0})

0 commit comments

Comments
 (0)