Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/utils/tests/test_unionfind.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 networkx as nx | |
2 | |
3 | |
4 def test_unionfind(): | |
5 # Fixed by: 2cddd5958689bdecdcd89b91ac9aaf6ce0e4f6b8 | |
6 # Previously (in 2.x), the UnionFind class could handle mixed types. | |
7 # But in Python 3.x, this causes a TypeError such as: | |
8 # TypeError: unorderable types: str() > int() | |
9 # | |
10 # Now we just make sure that no exception is raised. | |
11 x = nx.utils.UnionFind() | |
12 x.union(0, "a") | |
13 | |
14 | |
15 def test_subtree_union(): | |
16 # See https://github.com/networkx/networkx/pull/3224 | |
17 # (35db1b551ee65780794a357794f521d8768d5049). | |
18 # Test if subtree unions hare handled correctly by to_sets(). | |
19 uf = nx.utils.UnionFind() | |
20 uf.union(1, 2) | |
21 uf.union(3, 4) | |
22 uf.union(4, 5) | |
23 uf.union(1, 5) | |
24 assert list(uf.to_sets()) == [{1, 2, 3, 4, 5}] | |
25 | |
26 | |
27 def test_unionfind_weights(): | |
28 # Tests if weights are computed correctly with unions of many elements | |
29 uf = nx.utils.UnionFind() | |
30 uf.union(1, 4, 7) | |
31 uf.union(2, 5, 8) | |
32 uf.union(3, 6, 9) | |
33 uf.union(1, 2, 3, 4, 5, 6, 7, 8, 9) | |
34 assert uf.weights[uf[1]] == 9 | |
35 | |
36 | |
37 def test_empty_union(): | |
38 # Tests if a null-union does nothing. | |
39 uf = nx.utils.UnionFind((0, 1)) | |
40 uf.union() | |
41 assert uf[0] == 0 | |
42 assert uf[1] == 1 |