Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / tests / test_swap.py @ 5cef0f13

History | View | Annotate | Download (1.55 KB)

1
#!/usr/bin/env python
2
from nose.tools import *
3
from networkx import *
4

    
5
#import random
6
#random.seed(0)
7

    
8

    
9
def test_double_edge_swap():
10
    graph = barabasi_albert_graph(200, 1)
11
    degrees = sorted(d for n, d in graph.degree())
12
    G = double_edge_swap(graph, 40)
13
    assert_equal(degrees, sorted(d for n, d in graph.degree()))
14

    
15

    
16
def test_double_edge_swap_seed():
17
    graph = barabasi_albert_graph(200, 1)
18
    degrees = sorted(d for n, d in graph.degree())
19
    G = double_edge_swap(graph, 40, seed=1)
20
    assert_equal(degrees, sorted(d for n, d in graph.degree()))
21

    
22

    
23
def test_connected_double_edge_swap():
24
    graph = barabasi_albert_graph(200, 1)
25
    degrees = sorted(d for n, d in graph.degree())
26
    G = connected_double_edge_swap(graph, 40, seed=1)
27
    assert_true(is_connected(graph))
28
    assert_equal(degrees, sorted(d for n, d in graph.degree()))
29

    
30

    
31
@raises(NetworkXError)
32
def test_double_edge_swap_small():
33
    G = nx.double_edge_swap(nx.path_graph(3))
34

    
35

    
36
@raises(NetworkXError)
37
def test_double_edge_swap_tries():
38
    G = nx.double_edge_swap(nx.path_graph(10), nswap=1, max_tries=0)
39

    
40

    
41
@raises(NetworkXError)
42
def test_connected_double_edge_swap_small():
43
    G = nx.connected_double_edge_swap(nx.path_graph(3))
44

    
45

    
46
@raises(NetworkXError)
47
def test_connected_double_edge_swap_not_connected():
48
    G = nx.path_graph(3)
49
    nx.add_path(G, [10, 11, 12])
50
    G = nx.connected_double_edge_swap(G)
51

    
52

    
53
def test_degree_seq_c4():
54
    G = cycle_graph(4)
55
    degrees = sorted(d for n, d in G.degree())
56
    G = double_edge_swap(G, 1, 100)
57
    assert_equal(degrees, sorted(d for n, d in G.degree()))