~ubuntu-branches/ubuntu/wily/python-networkx/wily

« back to all changes in this revision

Viewing changes to networkx/tests/readwrite/adjlist.txt

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-03-02 01:06:32 UTC
  • mfrom: (1.2.1 upstream) (3.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080302010632-1lp6qe1orf59jl8b
* debian/control:
   + Replace python-setuptools with python-pkg-resources in the
     “Recommends:” since pkg_resources is now available in this
     separate package, thanks Matthias Klose (Closes: #468721).
* debian/copyright:
   + Use “© $years $name” instead of invalid “$name, $years” and
     “(C) $years, $name”, thanks to lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
adjlist
 
2
=======
 
3
 
 
4
>>> from networkx import *
 
5
>>> from networkx.operators import *
 
6
>>> import os,tempfile
 
7
 
 
8
 
 
9
ASCII Adjacency List
 
10
--------------------
 
11
 
 
12
set up some test networks
 
13
 
 
14
>>> G=Graph(name="test")
 
15
>>> e=[('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
 
16
>>> G.add_edges_from(e)
 
17
>>> G.add_node('g')
 
18
>>> DG=G.to_directed()
 
19
>>> XG=XGraph(multiedges=True,selfloops=True)
 
20
>>> XG.add_edges_from([(1,2,5),(1,2,5),(1,2),(3,3,42)])
 
21
 
 
22
>>> (fd,fname)=tempfile.mkstemp()
 
23
 
 
24
strings
 
25
 
 
26
>>> write_adjlist(G,fname);  
 
27
>>> H=read_adjlist(fname);
 
28
>>> H2=read_adjlist(fname)
 
29
>>> H is not H2  # they should be different graphs
 
30
True
 
31
>>> sorted(H.nodes())==sorted(G.nodes())
 
32
True
 
33
>>> sorted(H.edges())==sorted(G.edges())
 
34
True
 
35
 
 
36
digraph
 
37
 
 
38
>>> write_adjlist(DG,fname);  
 
39
>>> H=read_adjlist(fname,create_using=DiGraph());
 
40
>>> H2=read_adjlist(fname,create_using=DiGraph());
 
41
>>> H is not H2  # they should be different graphs
 
42
True
 
43
>>> sorted(H.nodes())==sorted(DG.nodes())
 
44
True
 
45
>>> sorted(H.edges())==sorted(DG.edges())
 
46
True
 
47
 
 
48
integers
 
49
 
 
50
>>> Gint=convert_node_labels_to_integers(G)
 
51
>>> write_adjlist(Gint,fname);  
 
52
>>> H=read_adjlist(fname,nodetype=int);
 
53
>>> H2=read_adjlist(fname,nodetype=int);
 
54
>>> H is not H2  # they should be different graphs
 
55
True
 
56
>>> sorted(H.nodes())==sorted(Gint.nodes())
 
57
True
 
58
>>> sorted(H.edges())==sorted(Gint.edges())
 
59
True
 
60
>>> os.close(fd)
 
61
>>> os.unlink(fname)
 
62
 
 
63
 
 
64
ASCII Multiline Adjacency List
 
65
------------------------------
 
66
 
 
67
set up some test networks
 
68
 
 
69
>>> G=Graph(name="test")
 
70
>>> e=[('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
 
71
>>> G.add_edges_from(e)
 
72
>>> G.add_node('g')
 
73
>>> DG=G.to_directed()
 
74
>>> DG.delete_edge(('b','a'))
 
75
>>> DG.delete_edge(('b','c'))
 
76
>>> XG=XGraph(multiedges=True,selfloops=True)
 
77
>>> XG.add_edges_from([(1,2,5),(1,2,5),(1,2),(3,3,42)])
 
78
 
 
79
>>> (fd,fname)=tempfile.mkstemp()
 
80
 
 
81
strings
 
82
 
 
83
>>> write_multiline_adjlist(G,fname);  
 
84
>>> H=read_multiline_adjlist(fname);
 
85
>>> H2=read_multiline_adjlist(fname)
 
86
>>> H is not H2  # they should be different graphs
 
87
True
 
88
>>> sorted(H.nodes())==sorted(G.nodes())
 
89
True
 
90
>>> sorted(H.edges())==sorted(G.edges())
 
91
True
 
92
 
 
93
digraph
 
94
 
 
95
>>> write_multiline_adjlist(DG,fname);  
 
96
>>> H=read_multiline_adjlist(fname,create_using=DiGraph());
 
97
>>> H2=read_multiline_adjlist(fname,create_using=DiGraph());
 
98
>>> H is not H2  # they should be different graphs
 
99
True
 
100
>>> sorted(H.nodes())==sorted(DG.nodes())
 
101
True
 
102
>>> sorted(H.edges())==sorted(DG.edges())
 
103
True
 
104
 
 
105
integers
 
106
 
 
107
>>> write_multiline_adjlist(Gint,fname);  
 
108
>>> H=read_multiline_adjlist(fname,nodetype=int);
 
109
>>> H2=read_multiline_adjlist(fname,nodetype=int);
 
110
>>> H is not H2  # they should be different graphs
 
111
True
 
112
>>> sorted(H.nodes())==sorted(Gint.nodes())
 
113
True
 
114
>>> sorted(H.edges())==sorted(Gint.edges())
 
115
True
 
116
 
 
117
xgraph
 
118
 
 
119
>>> write_multiline_adjlist(XG,fname)  
 
120
>>> H=read_multiline_adjlist(fname,nodetype=int,edgetype=int,create_using=XGraph(selfloops=True,multiedges=True));
 
121
>>> H2=read_multiline_adjlist(fname,nodetype=int,edgetype=int,create_using=XGraph(selfloops=True,multiedges=True));
 
122
>>> H is not H2  # they should be different graphs
 
123
True
 
124
>>> sorted(H.nodes())==sorted(XG.nodes())
 
125
True
 
126
>>> sorted(H.edges())==sorted(XG.edges())
 
127
True
 
128
>>> os.close(fd)
 
129
>>> os.unlink(fname)
 
130
 
 
131
 
 
132
Filehandling/Compression/Uncompression
 
133
-------------------------
 
134
 
 
135
>>> (fd,fname)=tempfile.mkstemp()
 
136
>>> fh=open(fname,'w')
 
137
>>> write_adjlist(G,fh)
 
138
>>> fh.close()
 
139
>>> fh=open(fname,'r')
 
140
>>> H=read_adjlist(fh)
 
141
>>> sorted(G.nodes())==sorted(H.nodes())
 
142
True
 
143
>>> sorted(G.edges())==sorted(H.edges())
 
144
True
 
145
>>> fh.close()
 
146
>>> os.close(fd)
 
147
>>> os.unlink(fname)
 
148
 
 
149
gz
 
150
 
 
151
>>> (fd,fname)=tempfile.mkstemp(suffix='.gz')
 
152
>>> write_adjlist(G,fname)
 
153
>>> H=read_adjlist(fname)
 
154
>>> sorted(G.nodes())==sorted(H.nodes())
 
155
True
 
156
>>> sorted(G.edges())==sorted(H.edges())
 
157
True
 
158
>>> os.close(fd)
 
159
>>> os.unlink(fname)
 
160
 
 
161
bz2 (not in standard distribution? so not included here) 
 
162
 
 
163
(fd,fname)=tempfile.mkstemp(suffix='.bz2')
 
164
write_adjlist(G,fname)
 
165
H=read_adjlist(fname)
 
166
sorted(G.nodes())==sorted(H.nodes())
 
167
True
 
168
sorted(G.edges())==sorted(H.edges())
 
169
True
 
170
os.unlink(fname)
 
171