2
from nose.tools import *
3
from nose import SkipTest
6
class TestFlowClosenessCentrality(object):
13
raise SkipTest('NumPy not available.')
17
"""Closeness centrality: K4"""
18
G=networkx.complete_graph(4)
19
b=networkx.current_flow_closeness_centrality(G,normalized=True)
20
b_answer={0: 2.0, 1: 2.0, 2: 2.0, 3: 2.0}
22
assert_almost_equal(b[n],b_answer[n])
25
def test_P4_normalized(self):
26
"""Closeness centrality: P4 normalized"""
27
G=networkx.path_graph(4)
28
b=networkx.current_flow_closeness_centrality(G,normalized=True)
29
b_answer={0: 1./2, 1: 3./4, 2: 3./4, 3:1./2}
31
assert_almost_equal(b[n],b_answer[n])
35
"""Closeness centrality: P4"""
36
G=networkx.path_graph(4)
37
b=networkx.current_flow_closeness_centrality(G,normalized=False)
38
b_answer={0: 1.0/6, 1: 1.0/4, 2: 1.0/4, 3:1.0/6}
40
assert_almost_equal(b[n],b_answer[n])
43
"""Closeness centrality: star """
45
G.add_star(['a','b','c','d'])
46
b=networkx.current_flow_closeness_centrality(G,normalized=True)
47
b_answer={'a': 1.0, 'b': 0.6, 'c': 0.6, 'd':0.6}
49
assert_almost_equal(b[n],b_answer[n])
53
class TestWeightedFlowClosenessCentrality(object):