Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/components/tests/test_attracting.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 import pytest | |
2 import networkx as nx | |
3 from networkx import NetworkXNotImplemented | |
4 | |
5 | |
6 class TestAttractingComponents: | |
7 @classmethod | |
8 def setup_class(cls): | |
9 cls.G1 = nx.DiGraph() | |
10 cls.G1.add_edges_from( | |
11 [ | |
12 (5, 11), | |
13 (11, 2), | |
14 (11, 9), | |
15 (11, 10), | |
16 (7, 11), | |
17 (7, 8), | |
18 (8, 9), | |
19 (3, 8), | |
20 (3, 10), | |
21 ] | |
22 ) | |
23 cls.G2 = nx.DiGraph() | |
24 cls.G2.add_edges_from([(0, 1), (0, 2), (1, 1), (1, 2), (2, 1)]) | |
25 | |
26 cls.G3 = nx.DiGraph() | |
27 cls.G3.add_edges_from([(0, 1), (1, 2), (2, 1), (0, 3), (3, 4), (4, 3)]) | |
28 | |
29 cls.G4 = nx.DiGraph() | |
30 | |
31 def test_attracting_components(self): | |
32 ac = list(nx.attracting_components(self.G1)) | |
33 assert {2} in ac | |
34 assert {9} in ac | |
35 assert {10} in ac | |
36 | |
37 ac = list(nx.attracting_components(self.G2)) | |
38 ac = [tuple(sorted(x)) for x in ac] | |
39 assert ac == [(1, 2)] | |
40 | |
41 ac = list(nx.attracting_components(self.G3)) | |
42 ac = [tuple(sorted(x)) for x in ac] | |
43 assert (1, 2) in ac | |
44 assert (3, 4) in ac | |
45 assert len(ac) == 2 | |
46 | |
47 ac = list(nx.attracting_components(self.G4)) | |
48 assert ac == [] | |
49 | |
50 def test_number_attacting_components(self): | |
51 assert nx.number_attracting_components(self.G1) == 3 | |
52 assert nx.number_attracting_components(self.G2) == 1 | |
53 assert nx.number_attracting_components(self.G3) == 2 | |
54 assert nx.number_attracting_components(self.G4) == 0 | |
55 | |
56 def test_is_attracting_component(self): | |
57 assert not nx.is_attracting_component(self.G1) | |
58 assert not nx.is_attracting_component(self.G2) | |
59 assert not nx.is_attracting_component(self.G3) | |
60 g2 = self.G3.subgraph([1, 2]) | |
61 assert nx.is_attracting_component(g2) | |
62 assert not nx.is_attracting_component(self.G4) | |
63 | |
64 def test_connected_raise(self): | |
65 G = nx.Graph() | |
66 pytest.raises(NetworkXNotImplemented, nx.attracting_components, G) | |
67 pytest.raises(NetworkXNotImplemented, nx.number_attracting_components, G) | |
68 pytest.raises(NetworkXNotImplemented, nx.is_attracting_component, G) |