~ubuntu-branches/ubuntu/utopic/python-networkx/utopic

« back to all changes in this revision

Viewing changes to networkx/algorithms/tests/test_cycles.py

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-08-11 12:41:30 UTC
  • mfrom: (1.4.1) (5.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120811124130-whr6uso7fncyg8bi
Tags: 1.7-1
* New upstream release
* debian/patches/changeset_*
  - removed, included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        G.add_cycle([0,1,6,7,8])
12
12
        G.add_edge(8,9)
13
13
        self.G=G
 
14
        
 
15
    def is_cyclic_permuatation(self,a,b):
 
16
        n=len(a)
 
17
        if len(b)!=n:
 
18
            return False
 
19
        l=a+a
 
20
        return any(l[i:i+n]==b for i in range(2*n-n+1))
14
21
 
15
22
    def test_cycle_basis(self):
16
23
        G=self.G
29
36
        sort_cy= sorted(sorted(c) for c in cy[:-1]) + [sorted(cy[-1])]
30
37
        assert_equal(sort_cy, [[0,1,2,3],[0,1,6,7,8],[0,3,4,5],['A','B','C']])
31
38
 
 
39
    @raises(nx.NetworkXNotImplemented)
 
40
    def test_cycle_basis(self):
 
41
        G=nx.DiGraph()
 
42
        cy=networkx.cycle_basis(G,0)
 
43
 
 
44
    @raises(nx.NetworkXNotImplemented)
 
45
    def test_cycle_basis(self):
 
46
        G=nx.MultiGraph()
 
47
        cy=networkx.cycle_basis(G,0)
32
48
 
33
49
    def test_simple_cycles(self):
34
50
        G = nx.DiGraph([(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1), (2, 2)])
35
51
        c=sorted(nx.simple_cycles(G))
36
 
        assert_equal(c,[[0, 0], [0, 1, 2, 0], [0, 2, 0], [1, 2, 1], [2, 2]])
 
52
        ca=[[0, 0], [0, 1, 2, 0], [0, 2, 0], [1, 2, 1], [2, 2]]
 
53
        for (a,b) in zip(c,ca):
 
54
            assert_true(self.is_cyclic_permuatation(a[:-1],b[:-1]))
37
55
 
 
56
    @raises(nx.NetworkXNotImplemented)
38
57
    def test_simple_cycles_graph(self):
39
58
        G = nx.Graph()
40
 
        assert_raises(nx.NetworkXError,nx.simple_cycles,G)
 
59
        c = sorted(nx.simple_cycles(G))
41
60
 
42
61
    def test_unsortable(self):
43
62
        G=nx.DiGraph()
51
70
        assert_equal(c,[[1,2,3,1]])
52
71
        G.add_path([10,20,30,10])
53
72
        c=sorted(nx.simple_cycles(G))
54
 
        assert_equal(c,[[1,2,3,1],[10,20,30,10]])
 
73
        ca=[[1,2,3,1],[10,20,30,10]]
 
74
        for (a,b) in zip(c,ca):
 
75
            assert_true(self.is_cyclic_permuatation(a[:-1],b[:-1]))
55
76
 
56
77
    def test_simple_cycles_empty(self):
57
78
        G = nx.DiGraph()