Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.42 KB)

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

    
4

    
5
def small_ego_G():
6
    """The sample network from https://arxiv.org/pdf/1310.6753v1.pdf"""
7
    edges = [('a', 'b'), ('a', 'c'), ('b', 'c'), ('b', 'd'),
8
             ('b', 'e'), ('b', 'f'), ('c', 'd'), ('c', 'f'), ('c', 'h'), ('d', 'f'), ('e', 'f'),
9
             ('f', 'h'), ('h', 'j'), ('h', 'k'), ('i', 'j'), ('i', 'k'), ('j', 'k'), ('u', 'a'),
10
             ('u', 'b'), ('u', 'c'), ('u', 'd'), ('u', 'e'), ('u', 'f'), ('u', 'g'), ('u', 'h'),
11
             ('u', 'i'), ('u', 'j'), ('u', 'k')]
12
    G = nx.Graph()
13
    G.add_edges_from(edges)
14

    
15
    return G
16

    
17

    
18
class TestDispersion(object):
19

    
20
    def test_article(self):
21
        """our algorithm matches article's"""
22
        G = small_ego_G()
23
        disp_uh = nx.dispersion(G, 'u', 'h', normalized=False)
24
        disp_ub = nx.dispersion(G, 'u', 'b', normalized=False)
25
        assert disp_uh == 4
26
        assert disp_ub == 1
27

    
28
    def test_results_length(self):
29
        """there is a result for every node"""
30
        G = small_ego_G()
31
        disp = nx.dispersion(G)
32
        disp_Gu = nx.dispersion(G, 'u')
33
        disp_uv = nx.dispersion(G, 'u', 'h')
34
        assert len(disp) == len(G)
35
        assert len(disp_Gu) == len(G) - 1
36
        assert type(disp_uv) is float
37

    
38
    def test_impossible_things(self):
39
        G = nx.karate_club_graph()
40
        disp = nx.dispersion(G)
41
        for u in disp:
42
            for v in disp[u]:
43
                assert disp[u][v] >= 0