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

author shellac Mon, 22 Mar 2021 18:12:50 +0000
comparison
equal inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import pytest
2 import networkx as nx
3
4 # import random
5 # random.seed(0)
6
7
8 def test_double_edge_swap():
9 graph = nx.barabasi_albert_graph(200, 1)
10 degrees = sorted(d for n, d in graph.degree())
11 G = nx.double_edge_swap(graph, 40)
12 assert degrees == sorted(d for n, d in graph.degree())
13
14
15 def test_double_edge_swap_seed():
16 graph = nx.barabasi_albert_graph(200, 1)
17 degrees = sorted(d for n, d in graph.degree())
18 G = nx.double_edge_swap(graph, 40, seed=1)
19 assert degrees == sorted(d for n, d in graph.degree())
20
21
22 def test_connected_double_edge_swap():
23 graph = nx.barabasi_albert_graph(200, 1)
24 degrees = sorted(d for n, d in graph.degree())
25 G = nx.connected_double_edge_swap(graph, 40, seed=1)
26 assert nx.is_connected(graph)
27 assert degrees == sorted(d for n, d in graph.degree())
28
29
30 def test_double_edge_swap_small():
31 with pytest.raises(nx.NetworkXError):
32 G = nx.double_edge_swap(nx.path_graph(3))
33
34
35 def test_double_edge_swap_tries():
36 with pytest.raises(nx.NetworkXError):
37 G = nx.double_edge_swap(nx.path_graph(10), nswap=1, max_tries=0)
38
39
40 def test_connected_double_edge_swap_small():
41 with pytest.raises(nx.NetworkXError):
42 G = nx.connected_double_edge_swap(nx.path_graph(3))
43
44
45 def test_connected_double_edge_swap_not_connected():
46 with pytest.raises(nx.NetworkXError):
47 G = nx.path_graph(3)