Skip to content

Commit 31467fb

Browse files
author
CindeeM
committed
NF: add test that GraphPartition handles graph with nodes that are not contiguous integers 0->nnodes, cleanup
1 parent c5fb727 commit 31467fb

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

brainx/tests/test_modularity.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ def betweenness_to_modularity(g,ppart):
4747
#-----------------------------------------------------------------------------
4848
# Tests
4949
#-----------------------------------------------------------------------------
50+
def test_graphpartition():
51+
""" test GraphPartition correctly handles graph whose
52+
nodes are strings"""
53+
graph = nx.Graph()
54+
graph.add_edge('a','b')
55+
graph.add_edge('c','d')
56+
index = {0:set([0,1]), 1:set([2,3])}
57+
gpart = mod.GraphPartition(graph, index)
58+
5059

5160
def test_random_modular_graph_between_fraction():
5261
"""Test for graphs with non-zero between_fraction"""
@@ -428,16 +437,20 @@ def test_mutual_information():
428437
n1 = set(list(graph_partition3.index[0])[::2])
429438
n2 = set(list(graph_partition3.index[0])[1::2])
430439

431-
split_modules,e_new,a_new,d,t,m,n1,n2 = graph_partition3.compute_module_split(0,n1,n2)
432-
graph_partition3.apply_module_split(m,n1,n2,split_modules,e_new,a_new)
433-
mi3 = mod.mutual_information(ppart,graph_partition3.index)
440+
(split_modules, e_new,
441+
a_new, d, t, m,
442+
n1,n2) = graph_partition3.compute_module_split(0,n1,n2)
443+
graph_partition3.apply_module_split(m, n1, n2,
444+
split_modules,
445+
e_new, a_new)
446+
mi3 = mod.mutual_information(ppart, graph_partition3.index)
434447
npt.assert_array_less(mi3,mi_orig)
435448
## NOTE: CORRECTNESS NOT TESTED YET
436449

437450

438451
def test_random_mod():
439-
""" Test the GraphPartition operation that selects random modules to merge
440-
and split
452+
""" Test the GraphPartition operation that selects random modules
453+
to merge and split
441454
XXX not working yet"""
442455

443456
#nnod_mod, av_degrees, nmods
@@ -767,7 +780,8 @@ def test_badindex_graphpartition():
767780
gp = mod.GraphPartition(g, index)
768781
nt.assert_true(gp.index == index)
769782
npt.assert_raises(TypeError, mod.GraphPartition, g, {0: g.nodes()})
770-
npt.assert_raises(ValueError, mod.GraphPartition, g, {0:set(g.nodes()[:-1])})
783+
npt.assert_raises(ValueError, mod.GraphPartition, g,
784+
{0:set(g.nodes()[:-1])})
771785
npt.assert_raises(TypeError, mod.GraphPartition, g, g.nodes())
772786

773787

0 commit comments

Comments
 (0)