Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/approximation/tests/test_ramsey.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 import networkx.algorithms.approximation as apxa | |
| 3 | |
| 4 | |
| 5 def test_ramsey(): | |
| 6 # this should only find the complete graph | |
| 7 graph = nx.complete_graph(10) | |
| 8 c, i = apxa.ramsey_R2(graph) | |
| 9 cdens = nx.density(graph.subgraph(c)) | |
| 10 assert cdens == 1.0, "clique not correctly found by ramsey!" | |
| 11 idens = nx.density(graph.subgraph(i)) | |
| 12 assert idens == 0.0, "i-set not correctly found by ramsey!" | |
| 13 | |
| 14 # this trival graph has no cliques. should just find i-sets | |
| 15 graph = nx.trivial_graph() | |
| 16 c, i = apxa.ramsey_R2(graph) | |
| 17 assert c == {0}, "clique not correctly found by ramsey!" | |
| 18 assert i == {0}, "i-set not correctly found by ramsey!" | |
| 19 | |
| 20 graph = nx.barbell_graph(10, 5, nx.Graph()) | |
| 21 c, i = apxa.ramsey_R2(graph) | |
| 22 cdens = nx.density(graph.subgraph(c)) | |
| 23 assert cdens == 1.0, "clique not correctly found by ramsey!" | |
| 24 idens = nx.density(graph.subgraph(i)) | |
| 25 assert idens == 0.0, "i-set not correctly found by ramsey!" | |
| 26 | |
| 27 # add self-loops and test again | |
| 28 graph.add_edges_from([(n, n) for n in range(0, len(graph), 2)]) | |
| 29 cc, ii = apxa.ramsey_R2(graph) | |
| 30 assert cc == c | |
| 31 assert ii == i |
