Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/components/tests/test_semiconnected.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from itertools import chain | |
2 import networkx as nx | |
3 import pytest | |
4 | |
5 | |
6 class TestIsSemiconnected: | |
7 def test_undirected(self): | |
8 pytest.raises(nx.NetworkXNotImplemented, nx.is_semiconnected, nx.Graph()) | |
9 pytest.raises(nx.NetworkXNotImplemented, nx.is_semiconnected, nx.MultiGraph()) | |
10 | |
11 def test_empty(self): | |
12 pytest.raises(nx.NetworkXPointlessConcept, nx.is_semiconnected, nx.DiGraph()) | |
13 pytest.raises( | |
14 nx.NetworkXPointlessConcept, nx.is_semiconnected, nx.MultiDiGraph() | |
15 ) | |
16 | |
17 def test_single_node_graph(self): | |
18 G = nx.DiGraph() | |
19 G.add_node(0) | |
20 assert nx.is_semiconnected(G) | |
21 | |
22 def test_path(self): | |
23 G = nx.path_graph(100, create_using=nx.DiGraph()) | |
24 assert nx.is_semiconnected(G) | |
25 G.add_edge(100, 99) | |
26 assert not nx.is_semiconnected(G) | |
27 | |
28 def test_cycle(self): | |
29 G = nx.cycle_graph(100, create_using=nx.DiGraph()) | |
30 assert nx.is_semiconnected(G) | |
31 G = nx.path_graph(100, create_using=nx.DiGraph()) | |
32 G.add_edge(0, 99) | |
33 assert nx.is_semiconnected(G) | |
34 | |
35 def test_tree(self): | |
36 G = nx.DiGraph() | |
37 G.add_edges_from( | |
38 chain.from_iterable([(i, 2 * i + 1), (i, 2 * i + 2)] for i in range(100)) | |
39 ) | |
40 assert not nx.is_semiconnected(G) | |
41 | |
42 def test_dumbbell(self): | |
43 G = nx.cycle_graph(100, create_using=nx.DiGraph()) | |
44 G.add_edges_from((i + 100, (i + 1) % 100 + 100) for i in range(100)) | |
45 assert not nx.is_semiconnected(G) # G is disconnected. | |
46 G.add_edge(100, 99) | |
47 assert nx.is_semiconnected(G) | |
48 | |
49 def test_alternating_path(self): | |
50 G = nx.DiGraph( | |
51 chain.from_iterable([(i, i - 1), (i, i + 1)] for i in range(0, 100, 2)) | |
52 ) | |
53 assert not nx.is_semiconnected(G) |