Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.34 KB)

1
from nose.tools import *
2
import networkx as nx
3
from networkx import *
4

    
5

    
6
def test_complement():
7
    null = null_graph()
8
    empty1 = empty_graph(1)
9
    empty10 = empty_graph(10)
10
    K3 = complete_graph(3)
11
    K5 = complete_graph(5)
12
    K10 = complete_graph(10)
13
    P2 = path_graph(2)
14
    P3 = path_graph(3)
15
    P5 = path_graph(5)
16
    P10 = path_graph(10)
17
    # complement of the complete graph is empty
18

    
19
    G = complement(K3)
20
    assert_true(is_isomorphic(G, empty_graph(3)))
21
    G = complement(K5)
22
    assert_true(is_isomorphic(G, empty_graph(5)))
23
    # for any G, G=complement(complement(G))
24
    P3cc = complement(complement(P3))
25
    assert_true(is_isomorphic(P3, P3cc))
26
    nullcc = complement(complement(null))
27
    assert_true(is_isomorphic(null, nullcc))
28
    b = bull_graph()
29
    bcc = complement(complement(b))
30
    assert_true(is_isomorphic(b, bcc))
31

    
32

    
33
def test_complement_2():
34
    G1 = nx.DiGraph()
35
    G1.add_edge('A', 'B')
36
    G1.add_edge('A', 'C')
37
    G1.add_edge('A', 'D')
38
    G1C = complement(G1)
39
    assert_equal(sorted(G1C.edges()),
40
                 [('B', 'A'), ('B', 'C'),
41
                  ('B', 'D'), ('C', 'A'), ('C', 'B'),
42
                  ('C', 'D'), ('D', 'A'), ('D', 'B'), ('D', 'C')])
43

    
44

    
45
def test_reverse1():
46
    # Other tests for reverse are done by the DiGraph and MultiDigraph.
47
    G1 = nx.Graph()
48
    assert_raises(nx.NetworkXError, nx.reverse, G1)