test_operations.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Unit tests for the :mod:`networkx.algorithms.tree.operations` module.
  2. """
  3. import networkx as nx
  4. from networkx.utils import edges_equal, nodes_equal
  5. class TestJoin:
  6. """Unit tests for the :func:`networkx.tree.join` function."""
  7. def test_empty_sequence(self):
  8. """Tests that joining the empty sequence results in the tree
  9. with one node.
  10. """
  11. T = nx.join([])
  12. assert len(T) == 1
  13. assert T.number_of_edges() == 0
  14. def test_single(self):
  15. """Tests that joining just one tree yields a tree with one more
  16. node.
  17. """
  18. T = nx.empty_graph(1)
  19. actual = nx.join([(T, 0)])
  20. expected = nx.path_graph(2)
  21. assert nodes_equal(list(expected), list(actual))
  22. assert edges_equal(list(expected.edges()), list(actual.edges()))
  23. def test_basic(self):
  24. """Tests for joining multiple subtrees at a root node."""
  25. trees = [(nx.full_rary_tree(2, 2**2 - 1), 0) for i in range(2)]
  26. actual = nx.join(trees)
  27. expected = nx.full_rary_tree(2, 2**3 - 1)
  28. assert nx.is_isomorphic(actual, expected)