HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //lib/python3/dist-packages/networkx/generators/tests/test_nonisomorphic_trees.py
#!/usr/bin/env python
"""
====================
Generators - Non Isomorphic Trees
====================

Unit tests for WROM algorithm generator in generators/nonisomorphic_trees.py
"""
import networkx as nx
from networkx.testing import assert_edges_equal


class TestGeneratorNonIsomorphicTrees():

    def test_tree_structure(self):
        # test for tree structure for nx.nonisomorphic_trees()
        def f(x): return list(nx.nonisomorphic_trees(x))
        for i in f(6):
            assert nx.is_tree(i)
        for i in f(8):
            assert nx.is_tree(i)

    def test_nonisomorphism(self):
        # test for nonisomorphism of trees for nx.nonisomorphic_trees()
        def f(x): return list(nx.nonisomorphic_trees(x))
        trees = f(6)
        for i in range(len(trees)):
            for j in range(i + 1, len(trees)):
                assert not nx.is_isomorphic(trees[i], trees[j])
        trees = f(8)
        for i in range(len(trees)):
            for j in range(i + 1, len(trees)):
                assert not nx.is_isomorphic(trees[i], trees[j])

    def test_number_of_nonisomorphic_trees(self):
        # http://oeis.org/A000055
        assert nx.number_of_nonisomorphic_trees(2) == 1
        assert nx.number_of_nonisomorphic_trees(3) == 1
        assert nx.number_of_nonisomorphic_trees(4) == 2
        assert nx.number_of_nonisomorphic_trees(5) == 3
        assert nx.number_of_nonisomorphic_trees(6) == 6
        assert nx.number_of_nonisomorphic_trees(7) == 11
        assert nx.number_of_nonisomorphic_trees(8) == 23

    def test_nonisomorphic_trees(self):
        def f(x): return list(nx.nonisomorphic_trees(x))
        assert_edges_equal(f(3)[0].edges(), [(0, 1), (0, 2)])
        assert_edges_equal(f(4)[0].edges(), [(0, 1), (0, 3), (1, 2)])
        assert_edges_equal(f(4)[1].edges(), [(0, 1), (0, 2), (0, 3)])

    def test_nonisomorphic_trees_matrix(self):
        trees_2 = [[[0, 1], [1, 0]]]
        assert list(nx.nonisomorphic_trees(2, create="matrix")) == trees_2
        trees_3 = [[[0, 1, 1], [1, 0, 0], [1, 0, 0]]]
        assert list(nx.nonisomorphic_trees(3, create="matrix")) == trees_3
        trees_4 = [[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]],
                   [[0, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]]]
        assert list(nx.nonisomorphic_trees(4, create="matrix")) == trees_4