Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / tests / test_reciprocity.py @ 5cef0f13

History | View | Annotate | Download (1.23 KB)

1
from nose.tools import *
2
import networkx as nx
3

    
4

    
5
class TestReciprocity(object):
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
    @raises(nx.NetworkXError)
15
    def test_overall_reciprocity_empty_graph(self):
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
    @raises(nx.NetworkXError)
34
    def test_reciprocity_graph_isolated_nodes(self):
35
        DG = nx.DiGraph([(1, 2)])
36
        DG.add_node(4)
37
        nx.reciprocity(DG, 4)