forked from networkx/networkx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request networkx#1829 from SanketDG/reciprocity
add tests for networkx.algorithms.reciprocity
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from nose.tools import * | ||
import networkx as nx | ||
|
||
|
||
class TestReciprocity(object): | ||
|
||
# test overall reicprocity by passing whole graph | ||
def test_reciprocity_digraph(self): | ||
DG = nx.DiGraph([(1, 2), (2, 1)]) | ||
reciprocity = nx.reciprocity(DG) | ||
assert reciprocity == 1.0 | ||
|
||
# test empty graph's overall reciprocity which will throw an error | ||
@raises(nx.NetworkXError) | ||
def test_overall_reciprocity_empty_graph(self): | ||
DG = nx.DiGraph() | ||
nx.overall_reciprocity(DG) | ||
|
||
# test for reciprocity for a list of nodes | ||
def test_reciprocity_graph_nodes(self): | ||
DG = nx.DiGraph([(1, 2), (2, 3), (3, 2)]) | ||
reciprocity = nx.reciprocity(DG, [1, 2]) | ||
expected_reciprocity = {1: 0.0, 2: 0.6666666666666666} | ||
assert reciprocity == expected_reciprocity | ||
|
||
# test for reciprocity for a single node | ||
def test_reciprocity_graph_node(self): | ||
DG = nx.DiGraph([(1, 2), (2, 3), (3, 2)]) | ||
reciprocity = nx.reciprocity(DG, 2) | ||
assert reciprocity == 0.6666666666666666 | ||
|
||
# test for reciprocity for an isolated node | ||
@raises(nx.NetworkXError) | ||
def test_reciprocity_graph_isolated_nodes(self): | ||
DG = nx.DiGraph([(1, 2)]) | ||
DG.add_node(4) | ||
nx.reciprocity(DG, 4) |