### diff env/lib/python3.9/site-packages/networkx/algorithms/tests/test_swap.py @ 0:4f3585e2f14bdraftdefaulttip

author shellac Mon, 22 Mar 2021 18:12:50 +0000
line wrap: on
line diff
```--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.9/site-packages/networkx/algorithms/tests/test_swap.py	Mon Mar 22 18:12:50 2021 +0000
@@ -0,0 +1,56 @@
+import pytest
+import networkx as nx
+
+# import random
+# random.seed(0)
+
+
+def test_double_edge_swap():
+    graph = nx.barabasi_albert_graph(200, 1)
+    degrees = sorted(d for n, d in graph.degree())
+    G = nx.double_edge_swap(graph, 40)
+    assert degrees == sorted(d for n, d in graph.degree())
+
+
+def test_double_edge_swap_seed():
+    graph = nx.barabasi_albert_graph(200, 1)
+    degrees = sorted(d for n, d in graph.degree())
+    G = nx.double_edge_swap(graph, 40, seed=1)
+    assert degrees == sorted(d for n, d in graph.degree())
+
+
+def test_connected_double_edge_swap():
+    graph = nx.barabasi_albert_graph(200, 1)
+    degrees = sorted(d for n, d in graph.degree())
+    G = nx.connected_double_edge_swap(graph, 40, seed=1)
+    assert nx.is_connected(graph)
+    assert degrees == sorted(d for n, d in graph.degree())
+
+
+def test_double_edge_swap_small():
+    with pytest.raises(nx.NetworkXError):
+        G = nx.double_edge_swap(nx.path_graph(3))
+
+
+def test_double_edge_swap_tries():
+    with pytest.raises(nx.NetworkXError):
+        G = nx.double_edge_swap(nx.path_graph(10), nswap=1, max_tries=0)
+
+
+def test_connected_double_edge_swap_small():
+    with pytest.raises(nx.NetworkXError):
+        G = nx.connected_double_edge_swap(nx.path_graph(3))
+
+
+def test_connected_double_edge_swap_not_connected():
+    with pytest.raises(nx.NetworkXError):
+        G = nx.path_graph(3)
+        nx.add_path(G, [10, 11, 12])
+        G = nx.connected_double_edge_swap(G)
+
+
+def test_degree_seq_c4():
+    G = nx.cycle_graph(4)
+    degrees = sorted(d for n, d in G.degree())
+    G = nx.double_edge_swap(G, 1, 100)
+    assert degrees == sorted(d for n, d in G.degree())```