Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.42 KB)

1
from nose.tools import assert_equal
2

    
3
import networkx as nx
4

    
5

    
6
class TestClosenessVitality(object):
7

    
8
    def test_unweighted(self):
9
        G = nx.cycle_graph(3)
10
        vitality = nx.closeness_vitality(G)
11
        assert_equal(vitality, {0: 2, 1: 2, 2: 2})
12

    
13
    def test_weighted(self):
14
        G = nx.Graph()
15
        nx.add_cycle(G, [0, 1, 2], weight=2)
16
        vitality = nx.closeness_vitality(G, weight='weight')
17
        assert_equal(vitality, {0: 4, 1: 4, 2: 4})
18

    
19
    def test_unweighted_digraph(self):
20
        G = nx.DiGraph(nx.cycle_graph(3))
21
        vitality = nx.closeness_vitality(G)
22
        assert_equal(vitality, {0: 4, 1: 4, 2: 4})
23

    
24
    def test_weighted_digraph(self):
25
        G = nx.DiGraph()
26
        nx.add_cycle(G, [0, 1, 2], weight=2)
27
        nx.add_cycle(G, [2, 1, 0], weight=2)
28
        vitality = nx.closeness_vitality(G, weight='weight')
29
        assert_equal(vitality, {0: 8, 1: 8, 2: 8})
30

    
31
    def test_weighted_multidigraph(self):
32
        G = nx.MultiDiGraph()
33
        nx.add_cycle(G, [0, 1, 2], weight=2)
34
        nx.add_cycle(G, [2, 1, 0], weight=2)
35
        vitality = nx.closeness_vitality(G, weight='weight')
36
        assert_equal(vitality, {0: 8, 1: 8, 2: 8})
37

    
38
    def test_disconnecting_graph(self):
39
        """Tests that the closeness vitality of a node whose removal
40
        disconnects the graph is negative infinity.
41

42
        """
43
        G = nx.path_graph(3)
44
        assert_equal(nx.closeness_vitality(G, node=1), -float('inf'))