from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

from compas.topology import breadth_first_traverse


def network_is_connected(network):
    """Verify that the network is connected.

    Parameters
    ----------
    network : :class:`~compas.datastructures.Network`
        A network data structure.

    Returns
    -------
    bool
        True, if the network is connected.
        False, otherwise.

    Notes
    -----
    A network is connected if for every two vertices a path exists connecting them.

    Examples
    --------
    >>> import compas
    >>> from compas.datastructures import Network
    >>> from compas.datastructures import network_is_connected
    >>> network = Network.from_obj(compas.get('lines.obj'))
    >>> network_is_connected(network)
    True

    """
    if network.number_of_nodes() == 0:
        return False
    nodes = breadth_first_traverse(network.adjacency, network.node_sample(size=1)[0])
    return len(nodes) == network.number_of_nodes()
