# test_boundary.py - unit tests for the boundary module # # Copyright 2015 NetworkX developers. # # This file is part of NetworkX. # # NetworkX is distributed under a BSD license; see LICENSE.txt for more # information. """Unit tests for the :mod:`networkx.algorithms.boundary` module.""" from itertools import combinations import networkx as nx from networkx.testing import almost_equal, assert_edges_equal from networkx import convert_node_labels_to_integers as cnlti class TestNodeBoundary(object): """Unit tests for the :func:`~networkx.node_boundary` function.""" def test_null_graph(self): """Tests that the null graph has empty node boundaries.""" null = nx.null_graph() assert nx.node_boundary(null, []) == set() assert nx.node_boundary(null, [], []) == set() assert nx.node_boundary(null, [1, 2, 3]) == set() assert nx.node_boundary(null, [1, 2, 3], [4, 5, 6]) == set() assert nx.node_boundary(null, [1, 2, 3], [3, 4, 5]) == set() def test_path_graph(self): P10 = cnlti(nx.path_graph(10), first_label=1) assert nx.node_boundary(P10, []) == set() assert nx.node_boundary(P10, [], []) == set() assert nx.node_boundary(P10, [1, 2, 3]) == {4} assert nx.node_boundary(P10, [4, 5, 6]) == {3, 7} assert nx.node_boundary(P10, [3, 4, 5, 6, 7]) == {2, 8} assert nx.node_boundary(P10, [8, 9, 10]) == {7} assert nx.node_boundary(P10, [4, 5, 6], [9, 10]) == set() def test_complete_graph(self): K10 = cnlti(nx.complete_graph(10), first_label=1) assert nx.node_boundary(K10, []) == set() assert nx.node_boundary(K10, [], []) == set() assert nx.node_boundary(K10, [1, 2, 3]) == {4, 5, 6, 7, 8, 9, 10} assert nx.node_boundary(K10, [4, 5, 6]) == {1, 2, 3, 7, 8, 9, 10} assert nx.node_boundary(K10, [3, 4, 5, 6, 7]) == {1, 2, 8, 9, 10} assert nx.node_boundary(K10, [4, 5, 6], []) == set() assert nx.node_boundary(K10, K10) == set() assert nx.node_boundary(K10, [1, 2, 3], [3, 4, 5]) == {4, 5} def test_petersen(self): """Check boundaries in the petersen graph cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0