Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.19 KB)

1
# test_redundancy.py - unit tests for the bipartite.redundancy module
2
#
3
# Copyright 2015 Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com>.
4
#
5
# This file is part of NetworkX.
6
#
7
# NetworkX is distributed under a BSD license; see LICENSE.txt for more
8
# information.
9
"""Unit tests for the :mod:`networkx.algorithms.bipartite.redundancy` module.
10

11
"""
12
from __future__ import division
13

    
14
from nose.tools import assert_equal
15
from nose.tools import assert_true
16
from nose.tools import raises
17

    
18
from networkx import cycle_graph
19
from networkx import NetworkXError
20
from networkx.algorithms.bipartite import complete_bipartite_graph
21
from networkx.algorithms.bipartite import node_redundancy
22

    
23

    
24
def test_no_redundant_nodes():
25
    G = complete_bipartite_graph(2, 2)
26
    rc = node_redundancy(G)
27
    assert_true(all(redundancy == 1 for redundancy in rc.values()))
28

    
29

    
30
def test_redundant_nodes():
31
    G = cycle_graph(6)
32
    edge = {0, 3}
33
    G.add_edge(*edge)
34
    redundancy = node_redundancy(G)
35
    for v in edge:
36
        assert_equal(redundancy[v], 2 / 3)
37
    for v in set(G) - edge:
38
        assert_equal(redundancy[v], 1)
39

    
40

    
41
@raises(NetworkXError)
42
def test_not_enough_neighbors():
43
    G = complete_bipartite_graph(1, 2)
44
    node_redundancy(G)