Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (999 Bytes)

1
#!/usr/bin/env python
2
from nose.tools import *
3
import networkx as nx
4

    
5

    
6
def test_hierarchy_exception():
7
    G = nx.cycle_graph(5)
8
    assert_raises(nx.NetworkXError, nx.flow_hierarchy, G)
9

    
10

    
11
def test_hierarchy_cycle():
12
    G = nx.cycle_graph(5, create_using=nx.DiGraph())
13
    assert_equal(nx.flow_hierarchy(G), 0.0)
14

    
15

    
16
def test_hierarchy_tree():
17
    G = nx.full_rary_tree(2, 16, create_using=nx.DiGraph())
18
    assert_equal(nx.flow_hierarchy(G), 1.0)
19

    
20

    
21
def test_hierarchy_1():
22
    G = nx.DiGraph()
23
    G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 1), (3, 4), (0, 4)])
24
    assert_equal(nx.flow_hierarchy(G), 0.5)
25

    
26

    
27
def test_hierarchy_weight():
28
    G = nx.DiGraph()
29
    G.add_edges_from([(0, 1, {'weight': .3}),
30
                      (1, 2, {'weight': .1}),
31
                      (2, 3, {'weight': .1}),
32
                      (3, 1, {'weight': .1}),
33
                      (3, 4, {'weight': .3}),
34
                      (0, 4, {'weight': .3})])
35
    assert_equal(nx.flow_hierarchy(G, weight='weight'), .75)