Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_vitality.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 import networkx as nx | |
2 | |
3 | |
4 class TestClosenessVitality: | |
5 def test_unweighted(self): | |
6 G = nx.cycle_graph(3) | |
7 vitality = nx.closeness_vitality(G) | |
8 assert vitality == {0: 2, 1: 2, 2: 2} | |
9 | |
10 def test_weighted(self): | |
11 G = nx.Graph() | |
12 nx.add_cycle(G, [0, 1, 2], weight=2) | |
13 vitality = nx.closeness_vitality(G, weight="weight") | |
14 assert vitality == {0: 4, 1: 4, 2: 4} | |
15 | |
16 def test_unweighted_digraph(self): | |
17 G = nx.DiGraph(nx.cycle_graph(3)) | |
18 vitality = nx.closeness_vitality(G) | |
19 assert vitality == {0: 4, 1: 4, 2: 4} | |
20 | |
21 def test_weighted_digraph(self): | |
22 G = nx.DiGraph() | |
23 nx.add_cycle(G, [0, 1, 2], weight=2) | |
24 nx.add_cycle(G, [2, 1, 0], weight=2) | |
25 vitality = nx.closeness_vitality(G, weight="weight") | |
26 assert vitality == {0: 8, 1: 8, 2: 8} | |
27 | |
28 def test_weighted_multidigraph(self): | |
29 G = nx.MultiDiGraph() | |
30 nx.add_cycle(G, [0, 1, 2], weight=2) | |
31 nx.add_cycle(G, [2, 1, 0], weight=2) | |
32 vitality = nx.closeness_vitality(G, weight="weight") | |
33 assert vitality == {0: 8, 1: 8, 2: 8} | |
34 | |
35 def test_disconnecting_graph(self): | |
36 """Tests that the closeness vitality of a node whose removal | |
37 disconnects the graph is negative infinity. | |
38 | |
39 """ | |
40 G = nx.path_graph(3) | |
41 assert nx.closeness_vitality(G, node=1) == -float("inf") |