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/algorithms/components/tests/test_semiconnected.py
from itertools import chain
import networkx as nx
import pytest

class TestIsSemiconnected(object):

    def test_undirected(self):
        pytest.raises(nx.NetworkXNotImplemented, nx.is_semiconnected,
                      nx.Graph())
        pytest.raises(nx.NetworkXNotImplemented, nx.is_semiconnected,
                      nx.MultiGraph())

    def test_empty(self):
        pytest.raises(nx.NetworkXPointlessConcept, nx.is_semiconnected,
                      nx.DiGraph())
        pytest.raises(nx.NetworkXPointlessConcept, nx.is_semiconnected,
                      nx.MultiDiGraph())

    def test_single_node_graph(self):
        G = nx.DiGraph()
        G.add_node(0)
        assert nx.is_semiconnected(G)

    def test_path(self):
        G = nx.path_graph(100, create_using=nx.DiGraph())
        assert nx.is_semiconnected(G)
        G.add_edge(100, 99)
        assert not nx.is_semiconnected(G)

    def test_cycle(self):
        G = nx.cycle_graph(100, create_using=nx.DiGraph())
        assert nx.is_semiconnected(G)
        G = nx.path_graph(100, create_using=nx.DiGraph())
        G.add_edge(0, 99)
        assert nx.is_semiconnected(G)

    def test_tree(self):
        G = nx.DiGraph()
        G.add_edges_from(chain.from_iterable([(i, 2 * i + 1), (i, 2 * i + 2)]
                                             for i in range(100)))
        assert not nx.is_semiconnected(G)

    def test_dumbbell(self):
        G = nx.cycle_graph(100, create_using=nx.DiGraph())
        G.add_edges_from((i + 100, (i + 1) % 100 + 100) for i in range(100))
        assert not nx.is_semiconnected(G)  # G is disconnected.
        G.add_edge(100, 99)
        assert nx.is_semiconnected(G)

    def test_alternating_path(self):
        G = nx.DiGraph(chain.from_iterable([(i, i - 1), (i, i + 1)]
                                           for i in range(0, 100, 2)))
        assert not nx.is_semiconnected(G)