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

« back to all changes in this revision

Viewing changes to networkx/tests/xbase_Graph.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
 
XGraph
2
 
======
3
 
 
4
 
Unit tests for XGraph Class in xbase.py
5
 
---------------------------------------
6
 
 
7
 
>>> from networkx import *
8
 
>>> from networkx.isomorph import graph_could_be_isomorphic
9
 
>>> is_isomorphic=graph_could_be_isomorphic
10
 
>>> from networkx.operators import convert_node_labels_to_integers as cnlti
11
 
 
12
 
Some small graphs
13
 
-----------------
14
 
 
15
 
>>> null=null_graph()
16
 
>>> P1=cnlti(path_graph(1),first_label=1)
17
 
>>> P3=cnlti(path_graph(3),first_label=1)
18
 
>>> P10=cnlti(path_graph(10),first_label=1)
19
 
>>> K1=cnlti(complete_graph(1),first_label=1)
20
 
>>> K3=cnlti(complete_graph(3),first_label=1)
21
 
>>> K4=cnlti(complete_graph(4),first_label=1)
22
 
>>> K5=cnlti(complete_graph(5),first_label=1)
23
 
>>> K10=cnlti(complete_graph(10),first_label=1)
24
 
 
25
 
Same small graphs but as XGraphs
26
 
--------------------------------
27
 
 
28
 
>>> nullX=XGraph()
29
 
>>> P1X=XGraph()
30
 
>>> P1X.add_nodes_from(P1)
31
 
>>> P1X.add_edges_from(P1.edges())
32
 
>>> P3X=XGraph()
33
 
>>> P3X.add_edges_from(P3.edges())
34
 
>>> P10X=XGraph()
35
 
>>> P10X.add_edges_from(P10.edges())
36
 
>>> K1X=XGraph()
37
 
>>> K1X.add_nodes_from(K1)
38
 
>>> K1X.add_edges_from(K1.edges())
39
 
>>> K3X=XGraph()
40
 
>>> K3X.add_edges_from(K3.edges())
41
 
>>> K4X=XGraph()
42
 
>>> K4X.add_edges_from(K4.edges())
43
 
>>> K5X=XGraph()
44
 
>>> K5X.add_edges_from(K5.edges())
45
 
 
46
 
Name
47
 
----
48
 
 
49
 
>>> G = XGraph(name="test")
50
 
>>> print G    # test of __str__
51
 
test
52
 
>>> print G.name
53
 
test
54
 
 
55
 
>>> H=XGraph()
56
 
>>> print H.name
57
 
No Name
58
 
 
59
 
Nodes
60
 
-----
61
 
 
62
 
>>> G.add_node('A')
63
 
>>> G.has_node('A')
64
 
True
65
 
 
66
 
 
67
 
Test if a non-hashable object is in the Graph.  A python dict will
68
 
raise a TypeError, but for a Graph class a simple  False should be
69
 
returned (see Graph __contains__). If it cannot be a node then it is
70
 
not a node.
71
 
 
72
 
>>> G.has_node(['A'])
73
 
False
74
 
>>> G.has_node({'A':1})
75
 
False
76
 
 
77
 
>>> G.delete_node('A')
78
 
>>> G.has_node('A')
79
 
False
80
 
>>> G.add_nodes_from(list("ABCDEFGHIJKL"))
81
 
>>> G.has_node("L")
82
 
True
83
 
>>> G.delete_nodes_from(['H','I','J','K','L'])
84
 
>>> G.add_nodes_from([1,2,3,4])
85
 
>>> sorted(G.nodes())
86
 
[1, 2, 3, 4, 'A', 'B', 'C', 'D', 'E', 'F', 'G']
87
 
>>> sorted(G)   # test __iter__
88
 
[1, 2, 3, 4, 'A', 'B', 'C', 'D', 'E', 'F', 'G']
89
 
 
90
 
 
91
 
 
92
 
test __contains__
93
 
 
94
 
>>> 'A' in G   
95
 
True
96
 
>>> [] in G  # never raise a Key or TypeError in this test
97
 
False
98
 
>>> {1:1} in G
99
 
False
100
 
 
101
 
test __len__
102
 
 
103
 
>>> len(G) 
104
 
11
105
 
 
106
 
test node portion of clear()
107
 
 
108
 
>>> G.clear()    
109
 
>>> G.nodes()
110
 
[]
111
 
 
112
 
 
113
 
Test add_node and delete_node acting for various nbunch
114
 
 
115
 
>>> G.add_node('m')
116
 
>>> G.has_node('m')
117
 
True
118
 
>>> G.add_node('m')   # no complaints
119
 
>>> G.delete_node('j') # NetworkXError
120
 
Traceback (most recent call last):
121
 
...
122
 
NetworkXError: node j not in graph
123
 
>>> G.delete_node('m')
124
 
>>> G.nodes()
125
 
[]
126
 
 
127
 
nbunch is a list.
128
 
 
129
 
>>> G.add_nodes_from(list("ABCD")) 
130
 
>>> G.add_nodes_from(P3) # add nbunch of nodes (nbunch=Graph)
131
 
>>> sorted(G.nodes())
132
 
[1, 2, 3, 'A', 'B', 'C', 'D']
133
 
>>> G.delete_nodes_from(P3) # delete nbunch of nodes (nbunch=Graph)
134
 
>>> sorted(G.nodes())
135
 
['A', 'B', 'C', 'D']
136
 
 
137
 
nbunch is a set
138
 
 
139
 
>>> nbunch=set("ABCDEFGHIJKL")
140
 
>>> G.add_nodes_from(nbunch)
141
 
>>> G.has_node("L")
142
 
True
143
 
 
144
 
nbunch is a dict with nodes as keys
145
 
 
146
 
>>> nbunch={'I':"foo",'J':2,'K':True,'L':"spam"}
147
 
>>> G.delete_nodes_from(nbunch)
148
 
>>> sorted(G.nodes())
149
 
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
150
 
 
151
 
nbunch is an iterator
152
 
 
153
 
>>> n_iter=P3.nodes_iter()
154
 
>>> G.add_nodes_from(n_iter)
155
 
>>> sorted(G.nodes())
156
 
[1, 2, 3, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
157
 
>>> n_iter=P3.nodes_iter() # rebuild same iterator
158
 
>>> G.delete_nodes_from(n_iter) # delete nbunch of nodes (nbunch=iterator)
159
 
>>> sorted(G.nodes())
160
 
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
161
 
 
162
 
nbunch is a graph
163
 
 
164
 
>>> nbunch=K3
165
 
>>> G.add_nodes_from(nbunch)
166
 
>>> sorted(G.nodes())
167
 
[1, 2, 3, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
168
 
 
169
 
nbunch is an XGraph
170
 
 
171
 
>>> nbunch=K3X
172
 
>>> G.add_nodes_from(nbunch)
173
 
>>> sorted(G.nodes())
174
 
[1, 2, 3, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
175
 
 
176
 
 
177
 
 
178
 
Edges
179
 
-----
180
 
 
181
 
>>> G.add_edge('A')
182
 
Traceback (most recent call last):
183
 
...
184
 
ValueError: need more than 1 value to unpack
185
 
 
186
 
>>> G.add_edge('A','B')     # testing add_edge()
187
 
>>> G.add_edge('A','B') # should fail silently
188
 
>>> G.has_edge('A','B')     # testing has_edge()
189
 
True
190
 
>>> G.has_edge('A','C')
191
 
False
192
 
>>> G.has_edge( ('A','B') )
193
 
True
194
 
>>> G.has_edge('B','A') # G is undirected, so B->A is an edge
195
 
True
196
 
>>> G.has_neighbor('A','C')  # same as has_edge
197
 
False
198
 
>>> G.has_neighbor('A','B')  
199
 
True
200
 
 
201
 
>>> G.add_edge('A','C')  # test directedness
202
 
>>> G.add_edge('C','A')
203
 
>>> G.delete_edge('C','A')
204
 
>>> G.has_edge('A','C') # G is undirected
205
 
False
206
 
>>> G.has_edge('C','A') 
207
 
False
208
 
 
209
 
>>> G.add_edge('A','A') # test self loops
210
 
>>> G.has_edge('A','A')
211
 
False
212
 
 
213
 
>>> G.add_edge('X','X')
214
 
>>> G.has_node('X')  # added node but not self loop
215
 
True
216
 
>>> G.delete_node('X')
217
 
 
218
 
 
219
 
>>> G.add_edge('A','Z') # test that missing node 'Z' is added silently
220
 
>>> G.has_node('Z')
221
 
True
222
 
 
223
 
>>> G.add_edges_from([('B','C')])   # test add_edges_from()
224
 
>>> G.has_edge('B','C')
225
 
True
226
 
>>> G.has_edge('C','B')  # undirected
227
 
True
228
 
>>> G.add_edges_from([('D','F'),('B','D')])
229
 
>>> G.has_edge('D','F')
230
 
True
231
 
>>> G.has_edge('B','D')
232
 
True
233
 
>>> G.has_edge('D','B')  # undirected
234
 
True
235
 
>>> G.add_edges_from([tuple('IJ'),list('KK'),tuple('JK')])  # after failing silently, should add 2nd edge
236
 
>>> G.has_edge(('I','J'))
237
 
True
238
 
>>> G.has_edge(('K','K'))
239
 
False
240
 
>>> G.has_edge(('J','K'))
241
 
True
242
 
>>> G.has_edge(('K','J'))  # undirected
243
 
True
244
 
 
245
 
>>> G.add_path(list('ACDE'))      # test add_path() and add_cycle()
246
 
>>> G.has_edge('D','E')
247
 
True
248
 
>>> G.has_edge('E','C')
249
 
False
250
 
>>> G.add_cycle(list('MNOP'))
251
 
>>> G.has_edge('O','P')
252
 
True
253
 
>>> G.has_edge('P','M')
254
 
True
255
 
>>> G.delete_node('P')    # tests delete_node()'s handling of edges.
256
 
>>> G.has_edge('P','M')
257
 
False
258
 
 
259
 
 
260
 
>>> G.delete_edge('M')       # test delete_edge()
261
 
Traceback (most recent call last):
262
 
...
263
 
ValueError: need more than 1 value to unpack
264
 
 
265
 
>>> G.add_edge('N','M')  
266
 
>>> G.has_edge('M','N')
267
 
True
268
 
>>> G.delete_edge('M','N')
269
 
>>> G.has_edge('M','N')
270
 
False
271
 
>>> G.has_edge('N','M')  # undirected
272
 
False
273
 
>>> G.delete_edges_from([list('HI'),list('DF'),tuple('KK'),tuple('JK')]) # self loop fails silently
274
 
>>> G.has_edge('H','I')
275
 
False
276
 
>>> G.has_edge('J','K')
277
 
False
278
 
>>> G.delete_edges_from([list('IJ'),list('KK'),list('JK')])
279
 
>>> G.has_edge('I','J')
280
 
False
281
 
>>> G.delete_nodes_from(set('ZEFHIMNO'))
282
 
>>> sorted(G.nodes())
283
 
[1, 2, 3, 'A', 'B', 'C', 'D', 'G', 'J', 'K']
284
 
>>> G.delete_nodes_from([1,2,3])
285
 
>>> sorted(G.nodes())
286
 
['A', 'B', 'C', 'D', 'G', 'J', 'K']
287
 
>>> sorted(G.edges())
288
 
[('A', 'B', None), ('A', 'C', None), ('B', 'D', None), ('C', 'B', None), ('C', 'D', None)]
289
 
 
290
 
Test G.edges(nbunch) with various forms of nbunch
291
 
 
292
 
node not in nbunch should be quietly ignored
293
 
 
294
 
>>> sorted(G.edges(6))    # non-iterable non-node
295
 
Traceback (most recent call last):
296
 
...
297
 
NetworkXError: nbunch is not a node or a sequence of nodes.
298
 
 
299
 
>>> sorted(G.edges('Z'))  # iterable non-node
300
 
[]
301
 
 
302
 
nbunch can be an empty list
303
 
 
304
 
>>> sorted(G.edges([])) 
305
 
[]
306
 
 
307
 
nbunch can be a list
308
 
 
309
 
>>> sorted(G.edges(['A','B']))
310
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
311
 
 
312
 
nbunch can be a set
313
 
 
314
 
>>> sorted(G.edges(set(['A','B'])))
315
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
316
 
 
317
 
nbunch can be a graph
318
 
 
319
 
>>> G1=Graph()
320
 
>>> G1.add_nodes_from('AB')
321
 
>>> sorted(G.edges(G1)) # nbunch is a graph
322
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
323
 
 
324
 
nbunch can be an XGraph
325
 
 
326
 
>>> G1=XGraph()
327
 
>>> G1.add_nodes_from('AB')
328
 
>>> sorted(G.edges(G1)) # nbunch is an XGraph
329
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
330
 
 
331
 
 
332
 
nbunch can be a dict with nodes as keys
333
 
 
334
 
>>> ndict={'A': "thing1", 'B': "thing2"}
335
 
>>> sorted(G.edges(ndict))
336
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
337
 
 
338
 
nbunch can be a single node
339
 
 
340
 
>>> sorted(G.edges('A'))
341
 
[('A', 'B', None), ('A', 'C', None)]
342
 
 
343
 
 
344
 
Test G.edges_iter(nbunch) with various forms of nbunch
345
 
 
346
 
node not in nbunch should be quietly ignored
347
 
 
348
 
>>> sorted(G.edges_iter('Z'))
349
 
[]
350
 
 
351
 
nbunch can be an empty list
352
 
 
353
 
>>> sorted(G.edges_iter([])) 
354
 
[]
355
 
 
356
 
nbunch can be a list
357
 
 
358
 
>>> sorted(G.edges_iter(['A','B']))
359
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
360
 
 
361
 
nbunch can be a set
362
 
 
363
 
>>> sorted(G.edges_iter(set(['A','B'])))
364
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
365
 
 
366
 
nbunch can be a graph
367
 
 
368
 
>>> G1=Graph()
369
 
>>> G1.add_nodes_from(['A','B'])
370
 
>>> sorted(G.edges_iter(G1)) # nbunch is a graph
371
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
372
 
 
373
 
nbunch can be an XGraph
374
 
 
375
 
>>> G1=XGraph()
376
 
>>> G1.add_nodes_from(['A','B'])
377
 
>>> sorted(G.edges_iter(G1)) # nbunch is a graph
378
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
379
 
 
380
 
 
381
 
nbunch can be a dict with nodes as keys
382
 
 
383
 
>>> ndict={'A': "thing1", 'B': "thing2"}
384
 
>>> sorted(G.edges_iter(ndict))
385
 
[('A', 'B', None), ('A', 'C', None), ('B', 'C', None), ('B', 'D', None)]
386
 
 
387
 
nbunch can be a single node
388
 
 
389
 
>>> sorted(G.edges_iter('A'))
390
 
[('A', 'B', None), ('A', 'C', None)]
391
 
 
392
 
nbunch can be nothing (whole graph)
393
 
 
394
 
>>> sorted(G.edges_iter())
395
 
[('A', 'B', None), ('A', 'C', None), ('B', 'D', None), ('C', 'B', None), ('C', 'D', None)]
396
 
>>> sorted(G.nodes_iter())
397
 
['A', 'B', 'C', 'D', 'G', 'J', 'K']
398
 
 
399
 
 
400
 
Properties
401
 
----------
402
 
degree() of an empty graph must return []
403
 
 
404
 
>>> nullX.degree()
405
 
[]
406
 
>>> nullX.degree(with_labels=True)
407
 
{}
408
 
>>> list(nullX.degree_iter())
409
 
[]
410
 
>>> dict(nullX.degree_iter(with_labels=True))
411
 
{}
412
 
 
413
 
 
414
 
degree of single node must return single int
415
 
 
416
 
>>> G.degree('A')
417
 
2
418
 
 
419
 
degree of single node in iterable container must return list
420
 
 
421
 
>>> G.degree(['A'])
422
 
[2]
423
 
 
424
 
with_labels=True always return a dict
425
 
 
426
 
>>> G.degree('A',with_labels=True)
427
 
{'A': 2}
428
 
 
429
 
>>> G.degree(['A','B'])
430
 
[2, 3]
431
 
>>> G.degree(['A','B'],with_labels=True)
432
 
{'A': 2, 'B': 3}
433
 
 
434
 
>>> sorted(G.degree())
435
 
[0, 0, 0, 2, 2, 3, 3]
436
 
>>> sorted(list(G.degree_iter()))
437
 
[0, 0, 0, 2, 2, 3, 3]
438
 
 
439
 
>>> P3X.degree(['A','B']) # silently ignore nodes not in P3
440
 
[]
441
 
>>> sorted(P10X.degree(P3X)) # nbunch can be a graph
442
 
[1, 2, 2]
443
 
>>> sorted(P3X.degree(P10X)) # nbunch can be a graph thats way to big
444
 
[1, 1, 2]
445
 
>>> P10X.degree([])
446
 
[]
447
 
>>> list(P10X.degree_iter([]))
448
 
[]
449
 
>>> dict( P10X.degree_iter([],with_labels=True) )
450
 
{}
451
 
>>> dict(P10X.degree_iter([],with_labels=True))
452
 
{}
453
 
 
454
 
>>> nullX.degree(with_labels=True)
455
 
{}
456
 
>>> list(nullX.degree_iter())
457
 
[]
458
 
>>> dict(nullX.degree_iter(with_labels=True))
459
 
{}
460
 
 
461
 
>>> G.order()
462
 
7
463
 
>>> G.size()
464
 
5
465
 
 
466
 
 
467
 
Operations
468
 
-----------
469
 
 
470
 
copy
471
 
~~~~
472
 
 
473
 
>>> H=G.copy()      # copy
474
 
>>> H.adj==G.adj
475
 
True
476
 
>>> H.name==G.name
477
 
True
478
 
>>> H==G
479
 
False
480
 
 
481
 
>>> SG=G.subgraph(['A','B','D'])     # subgraph
482
 
>>> sorted(SG.nodes())
483
 
['A', 'B', 'D']
484
 
>>> sorted(SG.edges())
485
 
[('A', 'B', None), ('B', 'D', None)]
486
 
 
487
 
>>> DG=G.to_directed()
488
 
>>> DG.is_directed()
489
 
True
490
 
>>> G.is_directed()
491
 
False
492
 
>>> DG.name==G.name
493
 
True
494
 
>>> DG.adj==G.adj
495
 
True
496
 
>>> sorted(DG.out_edges(list('A')))
497
 
[('A', 'B', None), ('A', 'C', None)]
498
 
>>> sorted(DG.in_edges(list('A')))
499
 
[('B', 'A', None), ('C', 'A', None)]
500
 
>>> DG.delete_edge('A','B')
501
 
>>> DG.has_edge('B','A') # this deletes B-A but not  A-B
502
 
True
503
 
>>> DG.has_edge('A','B')
504
 
False
505
 
 
506
 
  # to_undirected
507
 
 
508
 
 
509
 
Neighbors
510
 
---------
511
 
 
512
 
>>> sorted(G['A'])
513
 
['B', 'C']
514
 
>>> sorted(G.neighbors('A'))
515
 
['B', 'C']
516
 
>>> sorted(G.neighbors_iter('A'))
517
 
['B', 'C']
518
 
 
519
 
>>> sorted(G.neighbors('G'))
520
 
[]
521
 
>>> sorted(G.neighbors('j'))
522
 
Traceback (most recent call last):
523
 
...
524
 
NetworkXError: node j not in graph
525
 
 
526
 
 
527
 
Functional interface
528
 
--------------------
529
 
 
530
 
>>> sorted(nodes(G))
531
 
['A', 'B', 'C', 'D', 'G', 'J', 'K']
532
 
>>> sorted(nodes_iter(G))
533
 
['A', 'B', 'C', 'D', 'G', 'J', 'K']
534
 
>>> sorted(edges(G))
535
 
[('A', 'B', None), ('A', 'C', None), ('B', 'D', None), ('C', 'B', None), ('C', 'D', None)]
536
 
>>> sorted(edges_iter(G))
537
 
[('A', 'B', None), ('A', 'C', None), ('B', 'D', None), ('C', 'B', None), ('C', 'D', None)]
538
 
>>> sorted(degree(G))
539
 
[0, 0, 0, 2, 2, 3, 3]
540
 
>>> sorted(neighbors(G,'A'))
541
 
['B', 'C']
542
 
>>> number_of_nodes(G)
543
 
7
544
 
>>> number_of_edges(G)
545
 
5
546
 
>>> density(G)==5/(7*(7-1)*0.5)
547
 
True
548
 
>>> degree_histogram(G)
549
 
[3, 0, 2, 2]
550
 
 
551
 
Iterators
552
 
---------
553
 
 
554
 
>>> sorted(G.nodes_iter())
555
 
['A', 'B', 'C', 'D', 'G', 'J', 'K']
556
 
>>> sorted(G.edges_iter())
557
 
[('A', 'B', None), ('A', 'C', None), ('B', 'D', None), ('C', 'B', None), ('C', 'D', None)]
558
 
>>> sorted(G.degree_iter())
559
 
[0, 0, 0, 2, 2, 3, 3]
560
 
>>> sorted(G.degree_iter(with_labels=True))
561
 
[('A', 2), ('B', 3), ('C', 3), ('D', 2), ('G', 0), ('J', 0), ('K', 0)]
562
 
>>> sorted(G.neighbors_iter('A'))
563
 
['B', 'C']
564
 
>>> sorted(G.neighbors_iter('X'))
565
 
Traceback (most recent call last):
566
 
...
567
 
NetworkXError: node X not in graph
568
 
 
569
 
>>> G.clear()
570
 
>>> number_of_nodes(G)
571
 
0
572
 
>>> number_of_edges(G)
573
 
0
574
 
 
575
 
 
576
 
Subgraph
577
 
--------
578
 
 
579
 
Subgraph of a null graph is a null graph
580
 
 
581
 
>>> G=nullX
582
 
>>> H=G.subgraph([])
583
 
>>> is_isomorphic(H,nullX)
584
 
True
585
 
 
586
 
Subgraph of an empty graph is an empty graph. test 1 
587
 
 
588
 
>>> E5X=empty_graph(5,create_using=XGraph())
589
 
>>> E10X=empty_graph(10,create_using=XGraph())
590
 
>>> H=E10X.subgraph([])
591
 
>>> is_isomorphic(H,nullX)
592
 
True
593
 
 
594
 
Subgraph of an  empty graph is an empty graph. test 2
595
 
 
596
 
>>> H=E10X.subgraph([1,2,3,4,5])
597
 
>>> is_isomorphic(H,E5X)
598
 
True
599
 
 
600
 
Subgraph of a complete graph is a complete graph
601
 
 
602
 
>>> H=K5X.subgraph([1,2,3])
603
 
>>> is_isomorphic(H,K3X)
604
 
True
605
 
 
606
 
Test G.subgraph(nbunch), where nbunch is a single node
607
 
 
608
 
>>> H=K5X.subgraph(1)
609
 
>>> is_isomorphic(H,K1X)
610
 
True
611
 
>>> J5=K5X.copy()
612
 
>>> H=J5.subgraph(1,inplace=True)
613
 
>>> is_isomorphic(H,K1X)
614
 
True
615
 
>>> is_isomorphic(J5,K1X)
616
 
True
617
 
 
618
 
Test G.subgraph(nbunch), where nbunch is a set
619
 
 
620
 
>>> H=K5X.subgraph(set([1]))
621
 
>>> is_isomorphic(H,K1X)
622
 
True
623
 
>>> J5=K5X.copy()
624
 
>>> H=J5.subgraph(set([1]),inplace=True)
625
 
>>> is_isomorphic(H,K1X)
626
 
True
627
 
>>> is_isomorphic(J5,K1X)
628
 
True
629
 
 
630
 
Test G.subgraph(nbunch), where nbunch is an iterator
631
 
 
632
 
>>> H=K5X.subgraph(iter(K3X))
633
 
>>> is_isomorphic(H,K3X)
634
 
True
635
 
>>> J5=K5X.copy()
636
 
>>> H=J5.subgraph(iter(K3X),inplace=True)
637
 
>>> is_isomorphic(H,K3X)
638
 
True
639
 
>>> is_isomorphic(J5,K3X)
640
 
True
641
 
 
642
 
Test G.subgraph(nbunch), where nbunch is another graph
643
 
 
644
 
>>> H=K5X.subgraph(K3X)
645
 
>>> is_isomorphic(H,K3X)
646
 
True
647
 
>>> J5=K5X.copy()
648
 
>>> H=J5.subgraph(K3X,inplace=True)
649
 
>>> is_isomorphic(H,K3X)
650
 
True
651
 
>>> is_isomorphic(J5,K3X)
652
 
True
653
 
 
654
 
 
655
 
Test for no error when nbunch has node not in G.nodes()
656
 
 
657
 
>>> H=K5X.subgraph([9])
658
 
>>> is_isomorphic(H,nullX)
659
 
True