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

author shellac Mon, 22 Mar 2021 18:12:50 +0000
line wrap: on
line source
```
import networkx as nx
from networkx.testing import almost_equal

def example1a_G():
G = nx.Graph()
G.add_edges_from([(1, 4), (2, 4), (3, 4), (4, 5), (5, 6), (6, 7), (6, 8)])
return G

def example1b_G():
G = nx.Graph()
G.add_edges_from([(1, 4), (2, 4), (3, 4), (4, 5), (5, 6), (6, 7), (6, 8)])
return G

class TestPercolationCentrality:
def test_percolation_example1a(self):
"""percolation centrality: example 1a"""
G = example1a_G()
p = nx.percolation_centrality(G)
p_answer = {4: 0.625, 6: 0.667}

def test_percolation_example1b(self):
"""percolation centrality: example 1a"""
G = example1b_G()
p = nx.percolation_centrality(G)
p_answer = {4: 0.825, 6: 0.4}

def test_converge_to_betweenness(self):
"""percolation centrality: should converge to betweenness
centrality when all nodes are percolated the same"""
# taken from betweenness test test_florentine_families_graph
G = nx.florentine_families_graph()
"Acciaiuoli": 0.000,
"Albizzi": 0.212,
"Bischeri": 0.104,
"Castellani": 0.055,
"Ginori": 0.000,
"Lamberteschi": 0.000,
"Medici": 0.522,
"Pazzi": 0.000,
"Peruzzi": 0.022,
"Ridolfi": 0.114,
"Salviati": 0.143,
"Strozzi": 0.103,
"Tornabuoni": 0.092,
}

p_states = {k: 1.0 for k, v in b_answer.items()}