Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / utils / tests / test_unionfind.py @ 5cef0f13

History | View | Annotate | Download (791 Bytes)

1
from nose.tools import *
2

    
3
import networkx as nx
4

    
5

    
6
def test_unionfind():
7
    # Fixed by: 2cddd5958689bdecdcd89b91ac9aaf6ce0e4f6b8
8
    # Previously (in 2.x), the UnionFind class could handle mixed types.
9
    # But in Python 3.x, this causes a TypeError such as:
10
    #   TypeError: unorderable types: str() > int()
11
    #
12
    # Now we just make sure that no exception is raised.
13
    x = nx.utils.UnionFind()
14
    x.union(0, 'a')
15

    
16
def test_subtree_union():
17
    # See https://github.com/networkx/networkx/pull/3224
18
    # (35db1b551ee65780794a357794f521d8768d5049).
19
    # Test if subtree unions hare handled correctly by to_sets().
20
    uf = nx.utils.UnionFind()
21
    uf.union(1, 2)
22
    uf.union(3, 4)
23
    uf.union(4, 5)
24
    uf.union(1, 5)
25
    assert_equal(list(uf.to_sets()), [set([1, 2, 3, 4, 5])])