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

author shellac Mon, 22 Mar 2021 18:12:50 +0000
line wrap: on
line source
```
"""
Tests for Group Centrality Measures
"""

import pytest
import networkx as nx

class TestGroupBetweennessCentrality:
def test_group_betweenness_single_node(self):
"""
Group betweenness centrality for single node group
"""
G = nx.path_graph(5)
C = 
b = nx.group_betweenness_centrality(G, C, weight=None, normalized=False)

def test_group_betweenness_normalized(self):
"""
Group betweenness centrality for group with more than
1 node and normalized
"""
G = nx.path_graph(5)
C = [1, 3]
b = nx.group_betweenness_centrality(G, C, weight=None, normalized=True)

def test_group_betweenness_value_zero(self):
"""
Group betweenness centrality value of 0
"""
G = nx.cycle_graph(6)
C = [0, 1, 5]
b = nx.group_betweenness_centrality(G, C, weight=None)

def test_group_betweenness_disconnected_graph(self):
"""
Group betweenness centrality in a disconnected graph
"""
G = nx.path_graph(5)
G.remove_edge(0, 1)
C = 
b = nx.group_betweenness_centrality(G, C, weight=None)

def test_group_betweenness_node_not_in_graph(self):
"""
Node(s) in C not in graph, raises NodeNotFound exception
"""
with pytest.raises(nx.NodeNotFound):
b = nx.group_betweenness_centrality(nx.path_graph(5), [6, 7, 8])

class TestGroupClosenessCentrality:
def test_group_closeness_single_node(self):
"""
Group closeness centrality for a single node group
"""
G = nx.path_graph(5)
c = nx.group_closeness_centrality(G, )

def test_group_closeness_disconnected(self):
"""
Group closeness centrality for a disconnected graph
"""
G = nx.Graph()
c = nx.group_closeness_centrality(G, [1, 2])

def test_group_closeness_multiple_node(self):
"""
Group closeness centrality for a group with more than
1 node
"""
G = nx.path_graph(4)
c = nx.group_closeness_centrality(G, [1, 2])

def test_group_closeness_node_not_in_graph(self):
"""
Node(s) in S not in graph, raises NodeNotFound exception
"""
with pytest.raises(nx.NodeNotFound):
c = nx.group_closeness_centrality(nx.path_graph(5), [6, 7, 8])

class TestGroupDegreeCentrality:
def test_group_degree_centrality_single_node(self):
"""
Group degree centrality for a single node group
"""
G = nx.path_graph(4)
d = nx.group_degree_centrality(G, )

def test_group_degree_centrality_multiple_node(self):
"""
Group degree centrality for group with more than
1 node
"""
G = nx.Graph()
G.add_nodes_from([1, 2, 3, 4, 5, 6, 7, 8])
[(1, 2), (1, 3), (1, 6), (1, 7), (1, 8), (2, 3), (2, 4), (2, 5)]
)
d = nx.group_degree_centrality(G, [1, 2])

def test_group_in_degree_centrality(self):
"""
Group in-degree centrality in a DiGraph
"""
G = nx.DiGraph()
G.add_nodes_from([1, 2, 3, 4, 5, 6, 7, 8])
[(1, 2), (1, 3), (1, 6), (1, 7), (1, 8), (2, 3), (2, 4), (2, 5)]
)
d = nx.group_in_degree_centrality(G, [1, 2])

def test_group_out_degree_centrality(self):
"""
Group out-degree centrality in a DiGraph
"""
G = nx.DiGraph()
G.add_nodes_from([1, 2, 3, 4, 5, 6, 7, 8])