### comparison env/lib/python3.9/site-packages/networkx/algorithms/centrality/tests/test_second_order_centrality.py @ 0:4f3585e2f14bdraftdefaulttip

author shellac Mon, 22 Mar 2021 18:12:50 +0000
comparison
equal inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """
2 Tests for second order centrality.
3 """
4
5 import pytest
6
7 np = pytest.importorskip("numpy")
8 scipy = pytest.importorskip("scipy")
9
10 import networkx as nx
11 from networkx.testing import almost_equal
12
13
14 class TestSecondOrderCentrality:
15 def test_empty(self):
16 with pytest.raises(nx.NetworkXException):
17 G = nx.empty_graph()
18 nx.second_order_centrality(G)
19
20 def test_non_connected(self):
21 with pytest.raises(nx.NetworkXException):
22 G = nx.Graph()
25 nx.second_order_centrality(G)
26
27 def test_non_negative_edge_weights(self):
28 with pytest.raises(nx.NetworkXException):
29 G = nx.path_graph(2)
31 nx.second_order_centrality(G)
32
33 def test_one_node_graph(self):
34 """Second order centrality: single node"""
35 G = nx.Graph()
38 assert nx.second_order_centrality(G)[0] == 0
39
40 def test_P3(self):
41 """Second order centrality: line graph, as defined in paper"""
42 G = nx.path_graph(3)
43 b_answer = {0: 3.741, 1: 1.414, 2: 3.741}
44
45 b = nx.second_order_centrality(G)
46
47 for n in sorted(G):
49
50 def test_K3(self):
51 """Second order centrality: complete graph, as defined in paper"""
52 G = nx.complete_graph(3)
53 b_answer = {0: 1.414, 1: 1.414, 2: 1.414}
54
55 b = nx.second_order_centrality(G)
56
57 for n in sorted(G):