Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.46 KB)

1
# test_operations.py - unit tests for the operations module
2
#
3
# Copyright 2015 NetworkX developers.
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.tree.operations` module.
10

11
"""
12
from nose.tools import assert_equal
13
from nose.tools import assert_true
14

    
15
import networkx as nx
16
from networkx.testing import assert_nodes_equal
17
from networkx.testing import assert_edges_equal
18

    
19

    
20
class TestJoin(object):
21
    """Unit tests for the :func:`networkx.tree.join` function."""
22

    
23
    def test_empty_sequence(self):
24
        """Tests that joining the empty sequence results in the tree
25
        with one node.
26

27
        """
28
        T = nx.join([])
29
        assert_equal(len(T), 1)
30
        assert_equal(T.number_of_edges(), 0)
31

    
32
    def test_single(self):
33
        """Tests that joining just one tree yields a tree with one more
34
        node.
35

36
        """
37
        T = nx.empty_graph(1)
38
        actual = nx.join([(T, 0)])
39
        expected = nx.path_graph(2)
40
        assert_nodes_equal(list(expected), list(actual))
41
        assert_edges_equal(list(expected.edges()), list(actual.edges()))
42

    
43
    def test_basic(self):
44
        """Tests for joining multiple subtrees at a root node."""
45
        trees = [(nx.full_rary_tree(2, 2 ** 2 - 1), 0) for i in range(2)]
46
        actual = nx.join(trees)
47
        expected = nx.full_rary_tree(2, 2 ** 3 - 1)
48
        assert_true(nx.is_isomorphic(actual, expected))