@@ -47,6 +47,26 @@ 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
+ assert gpart ._node_set == set ([0 ,1 ,2 ,3 ])
59
+
60
+ def test_index_as_node_names ():
61
+ graph = nx .Graph ()
62
+ graph .add_edge ('a' ,'b' )
63
+ graph .add_edge ('c' ,'d' )
64
+ ## NOTE network x does not store names as added
65
+ ## for this graph ['a', 'c', 'b', 'd']
66
+ index = {0 :set ([0 ,2 ]), 1 :set ([1 ,3 ])}
67
+ gpart = mod .GraphPartition (graph , index )
68
+ named_index = gpart .index_as_node_names ()
69
+ assert ['a' ,'b' ] in named_index
50
70
51
71
def test_random_modular_graph_between_fraction ():
52
72
"""Test for graphs with non-zero between_fraction"""
@@ -428,16 +448,20 @@ def test_mutual_information():
428
448
n1 = set (list (graph_partition3 .index [0 ])[::2 ])
429
449
n2 = set (list (graph_partition3 .index [0 ])[1 ::2 ])
430
450
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 )
451
+ (split_modules , e_new ,
452
+ a_new , d , t , m ,
453
+ n1 ,n2 ) = graph_partition3 .compute_module_split (0 ,n1 ,n2 )
454
+ graph_partition3 .apply_module_split (m , n1 , n2 ,
455
+ split_modules ,
456
+ e_new , a_new )
457
+ mi3 = mod .mutual_information (ppart , graph_partition3 .index )
434
458
npt .assert_array_less (mi3 ,mi_orig )
435
459
## NOTE: CORRECTNESS NOT TESTED YET
436
460
437
461
438
462
def test_random_mod ():
439
- """ Test the GraphPartition operation that selects random modules to merge
440
- and split
463
+ """ Test the GraphPartition operation that selects random modules
464
+ to merge and split
441
465
XXX not working yet"""
442
466
443
467
#nnod_mod, av_degrees, nmods
@@ -767,7 +791,8 @@ def test_badindex_graphpartition():
767
791
gp = mod .GraphPartition (g , index )
768
792
nt .assert_true (gp .index == index )
769
793
npt .assert_raises (TypeError , mod .GraphPartition , g , {0 : g .nodes ()})
770
- npt .assert_raises (ValueError , mod .GraphPartition , g , {0 :set (g .nodes ()[:- 1 ])})
794
+ npt .assert_raises (ValueError , mod .GraphPartition , g ,
795
+ {0 :set (g .nodes ()[:- 1 ])})
771
796
npt .assert_raises (TypeError , mod .GraphPartition , g , g .nodes ())
772
797
773
798
0 commit comments