Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / tests / test_richclub.py @ 5cef0f13

History | View | Annotate | Download (2.46 KB)

1
import networkx as nx
2
from nose.tools import *
3

    
4

    
5
def test_richclub():
6
    G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)])
7
    rc = nx.richclub.rich_club_coefficient(G, normalized=False)
8
    assert_equal(rc, {0: 12.0 / 30, 1: 8.0 / 12})
9

    
10
    # test single value
11
    rc0 = nx.richclub.rich_club_coefficient(G, normalized=False)[0]
12
    assert_equal(rc0, 12.0 / 30.0)
13

    
14

    
15
def test_richclub_seed():
16
    G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)])
17
    rcNorm = nx.richclub.rich_club_coefficient(G, Q=2, seed=1)
18
    assert_equal(rcNorm, {0: 1.0, 1: 1.0})
19

    
20

    
21
def test_richclub_normalized():
22
    G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)])
23
    rcNorm = nx.richclub.rich_club_coefficient(G, Q=2)
24
    assert_equal(rcNorm, {0: 1.0, 1: 1.0})
25

    
26

    
27
def test_richclub2():
28
    T = nx.balanced_tree(2, 10)
29
    rc = nx.richclub.rich_club_coefficient(T, normalized=False)
30
    assert_equal(rc, {0: 4092 / (2047 * 2046.0),
31
                      1: (2044.0 / (1023 * 1022)),
32
                      2: (2040.0 / (1022 * 1021))})
33

    
34

    
35
def test_richclub3():
36
    # tests edgecase
37
    G = nx.karate_club_graph()
38
    rc = nx.rich_club_coefficient(G, normalized=False)
39
    assert_equal(rc, {0: 156.0 / 1122,
40
                      1: 154.0 / 1056,
41
                      2: 110.0 / 462,
42
                      3: 78.0 / 240,
43
                      4: 44.0 / 90,
44
                      5: 22.0 / 42,
45
                      6: 10.0 / 20,
46
                      7: 10.0 / 20,
47
                      8: 10.0 / 20,
48
                      9: 6.0 / 12,
49
                      10: 2.0 / 6,
50
                      11: 2.0 / 6,
51
                      12: 0.0,
52
                      13: 0.0,
53
                      14: 0.0,
54
                      15: 0.0, })
55

    
56

    
57
def test_richclub4():
58
    G = nx.Graph()
59
    G.add_edges_from([(0, 1), (0, 2), (0, 3), (0, 4), (4, 5), (5, 9), (6, 9), (7, 9), (8, 9)])
60
    rc = nx.rich_club_coefficient(G, normalized=False)
61
    assert_equal(rc, {0: 18 / 90.0,
62
                      1: 6 / 12.0,
63
                      2: 0.0,
64
                      3: 0.0})
65

    
66

    
67
@raises(nx.NetworkXNotImplemented)
68
def test_richclub_exception():
69
    G = nx.DiGraph()
70
    nx.rich_club_coefficient(G)
71

    
72

    
73
@raises(nx.NetworkXNotImplemented)
74
def test_rich_club_exception2():
75
    G = nx.MultiGraph()
76
    nx.rich_club_coefficient(G)
77

    
78

    
79
# def test_richclub2_normalized():
80
#    T = nx.balanced_tree(2,10)
81
#    rcNorm = nx.richclub.rich_club_coefficient(T,Q=2)
82
#    assert_true(rcNorm[0] ==1.0 and rcNorm[1] < 0.9 and rcNorm[2] < 0.9)