comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_reciprocity.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 pytest
2 import networkx as nx
3
4
5 class TestReciprocity:
6
7 # test overall reicprocity by passing whole graph
8 def test_reciprocity_digraph(self):
9 DG = nx.DiGraph([(1, 2), (2, 1)])
10 reciprocity = nx.reciprocity(DG)
11 assert reciprocity == 1.0
12
13 # test empty graph's overall reciprocity which will throw an error
14 def test_overall_reciprocity_empty_graph(self):
15 with pytest.raises(nx.NetworkXError):
16 DG = nx.DiGraph()
17 nx.overall_reciprocity(DG)
18
19 # test for reciprocity for a list of nodes
20 def test_reciprocity_graph_nodes(self):
21 DG = nx.DiGraph([(1, 2), (2, 3), (3, 2)])
22 reciprocity = nx.reciprocity(DG, [1, 2])
23 expected_reciprocity = {1: 0.0, 2: 0.6666666666666666}
24 assert reciprocity == expected_reciprocity
25
26 # test for reciprocity for a single node
27 def test_reciprocity_graph_node(self):
28 DG = nx.DiGraph([(1, 2), (2, 3), (3, 2)])
29 reciprocity = nx.reciprocity(DG, 2)
30 assert reciprocity == 0.6666666666666666
31
32 # test for reciprocity for an isolated node
33 def test_reciprocity_graph_isolated_nodes(self):
34 with pytest.raises(nx.NetworkXError):
35 DG = nx.DiGraph([(1, 2)])
36 DG.add_node(4)
37 nx.reciprocity(DG, 4)