Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_bridges.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 """Unit tests for bridge-finding algorithms.""" | |
2 | |
3 import networkx as nx | |
4 | |
5 | |
6 class TestBridges: | |
7 """Unit tests for the bridge-finding function.""" | |
8 | |
9 def test_single_bridge(self): | |
10 edges = [ | |
11 # DFS tree edges. | |
12 (1, 2), | |
13 (2, 3), | |
14 (3, 4), | |
15 (3, 5), | |
16 (5, 6), | |
17 (6, 7), | |
18 (7, 8), | |
19 (5, 9), | |
20 (9, 10), | |
21 # Nontree edges. | |
22 (1, 3), | |
23 (1, 4), | |
24 (2, 5), | |
25 (5, 10), | |
26 (6, 8), | |
27 ] | |
28 G = nx.Graph(edges) | |
29 source = 1 | |
30 bridges = list(nx.bridges(G, source)) | |
31 assert bridges == [(5, 6)] | |
32 | |
33 def test_barbell_graph(self): | |
34 # The (3, 0) barbell graph has two triangles joined by a single edge. | |
35 G = nx.barbell_graph(3, 0) | |
36 source = 0 | |
37 bridges = list(nx.bridges(G, source)) | |
38 assert bridges == [(2, 3)] | |
39 | |
40 | |
41 class TestLocalBridges: | |
42 """Unit tests for the local_bridge function.""" | |
43 | |
44 @classmethod | |
45 def setup_class(cls): | |
46 cls.BB = nx.barbell_graph(4, 0) | |
47 cls.square = nx.cycle_graph(4) | |
48 cls.tri = nx.cycle_graph(3) | |
49 | |
50 def test_nospan(self): | |
51 expected = {(3, 4), (4, 3)} | |
52 assert next(nx.local_bridges(self.BB, with_span=False)) in expected | |
53 assert set(nx.local_bridges(self.square, with_span=False)) == self.square.edges | |
54 assert list(nx.local_bridges(self.tri, with_span=False)) == [] | |
55 | |
56 def test_no_weight(self): | |
57 inf = float("inf") | |
58 expected = {(3, 4, inf), (4, 3, inf)} | |
59 assert next(nx.local_bridges(self.BB)) in expected | |
60 expected = {(u, v, 3) for u, v, in self.square.edges} | |
61 assert set(nx.local_bridges(self.square)) == expected | |
62 assert list(nx.local_bridges(self.tri)) == [] | |
63 | |
64 def test_weight(self): | |
65 inf = float("inf") | |
66 G = self.square.copy() | |
67 | |
68 G.edges[1, 2]["weight"] = 2 | |
69 expected = {(u, v, 5 - wt) for u, v, wt in G.edges(data="weight", default=1)} | |
70 assert set(nx.local_bridges(G, weight="weight")) == expected | |
71 | |
72 expected = {(u, v, 6) for u, v in G.edges} | |
73 lb = nx.local_bridges(G, weight=lambda u, v, d: 2) | |
74 assert set(lb) == expected |