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

author shellac Mon, 22 Mar 2021 18:12:50 +0000
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
shellac
parents:
diff changeset
1 import pytest
shellac
parents:
diff changeset
2 import networkx as nx
shellac
parents:
diff changeset
3
shellac
parents:
diff changeset
4 # import random
shellac
parents:
diff changeset
5 # random.seed(0)
shellac
parents:
diff changeset
6
shellac
parents:
diff changeset
7
shellac
parents:
diff changeset
8 def test_double_edge_swap():
shellac
parents:
diff changeset
9 graph = nx.barabasi_albert_graph(200, 1)
shellac
parents:
diff changeset
10 degrees = sorted(d for n, d in graph.degree())
shellac
parents:
diff changeset
11 G = nx.double_edge_swap(graph, 40)
shellac
parents:
diff changeset
12 assert degrees == sorted(d for n, d in graph.degree())
shellac
parents:
diff changeset
13
shellac
parents:
diff changeset
14
shellac
parents:
diff changeset
15 def test_double_edge_swap_seed():
shellac
parents:
diff changeset
16 graph = nx.barabasi_albert_graph(200, 1)
shellac
parents:
diff changeset
17 degrees = sorted(d for n, d in graph.degree())
shellac
parents:
diff changeset
18 G = nx.double_edge_swap(graph, 40, seed=1)
shellac
parents:
diff changeset
19 assert degrees == sorted(d for n, d in graph.degree())
shellac
parents:
diff changeset
20
shellac
parents:
diff changeset
21
shellac
parents:
diff changeset
22 def test_connected_double_edge_swap():
shellac
parents:
diff changeset
23 graph = nx.barabasi_albert_graph(200, 1)
shellac
parents:
diff changeset
24 degrees = sorted(d for n, d in graph.degree())
shellac
parents:
diff changeset
25 G = nx.connected_double_edge_swap(graph, 40, seed=1)
shellac
parents:
diff changeset
26 assert nx.is_connected(graph)
shellac
parents:
diff changeset
27 assert degrees == sorted(d for n, d in graph.degree())
shellac
parents:
diff changeset
28
shellac
parents:
diff changeset
29
shellac
parents:
diff changeset
30 def test_double_edge_swap_small():
shellac
parents:
diff changeset
31 with pytest.raises(nx.NetworkXError):
shellac
parents:
diff changeset
32 G = nx.double_edge_swap(nx.path_graph(3))
shellac
parents:
diff changeset
33
shellac
parents:
diff changeset
34
shellac
parents:
diff changeset
35 def test_double_edge_swap_tries():
shellac
parents:
diff changeset
36 with pytest.raises(nx.NetworkXError):
shellac
parents:
diff changeset
37 G = nx.double_edge_swap(nx.path_graph(10), nswap=1, max_tries=0)
shellac
parents:
diff changeset
38
shellac
parents:
diff changeset
39
shellac
parents:
diff changeset
40 def test_connected_double_edge_swap_small():
shellac
parents:
diff changeset
41 with pytest.raises(nx.NetworkXError):
shellac
parents:
diff changeset
42 G = nx.connected_double_edge_swap(nx.path_graph(3))
shellac
parents:
diff changeset
43
shellac
parents:
diff changeset
44
shellac
parents:
diff changeset
45 def test_connected_double_edge_swap_not_connected():
shellac
parents:
diff changeset
46 with pytest.raises(nx.NetworkXError):
shellac
parents:
diff changeset
47 G = nx.path_graph(3)
shellac
parents:
diff changeset
shellac
parents:
diff changeset
49 G = nx.connected_double_edge_swap(G)
shellac
parents:
diff changeset
50
shellac
parents:
diff changeset
51
shellac
parents:
diff changeset
52 def test_degree_seq_c4():
shellac
parents:
diff changeset
53 G = nx.cycle_graph(4)
shellac
parents:
diff changeset
54 degrees = sorted(d for n, d in G.degree())