@@ -47,6 +47,15 @@ def betweenness_to_modularity(g,ppart):
47
47
#-----------------------------------------------------------------------------
48
48
# Tests
49
49
#-----------------------------------------------------------------------------
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
+
50
59
51
60
def test_random_modular_graph_between_fraction ():
52
61
"""Test for graphs with non-zero between_fraction"""
@@ -428,16 +437,20 @@ def test_mutual_information():
428
437
n1 = set (list (graph_partition3 .index [0 ])[::2 ])
429
438
n2 = set (list (graph_partition3 .index [0 ])[1 ::2 ])
430
439
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 )
434
447
npt .assert_array_less (mi3 ,mi_orig )
435
448
## NOTE: CORRECTNESS NOT TESTED YET
436
449
437
450
438
451
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
441
454
XXX not working yet"""
442
455
443
456
#nnod_mod, av_degrees, nmods
@@ -767,7 +780,8 @@ def test_badindex_graphpartition():
767
780
gp = mod .GraphPartition (g , index )
768
781
nt .assert_true (gp .index == index )
769
782
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 ])})
771
785
npt .assert_raises (TypeError , mod .GraphPartition , g , g .nodes ())
772
786
773
787
0 commit comments