]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/iterator.py
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / python / test / iterator.py
1 # Copyright David Abrahams 2004. Distributed under the Boost
2 # Software License, Version 1.0. (See accompanying
3 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 '''
5 >>> from iterator_ext import *
6 >>> from input_iterator import *
7 >>> x = list_int()
8 >>> x.push_back(1)
9 >>> x.back()
10 1
11 >>> x.push_back(3)
12 >>> x.push_back(5)
13 >>> for y in x:
14 ... print(y)
15 1
16 3
17 5
18 >>> z = range(x)
19 >>> for y in z:
20 ... print(y)
21 1
22 3
23 5
24
25 Range2 wraps a transform_iterator which doubles the elements it
26 traverses. This proves we can wrap input iterators
27
28 >>> z2 = range2(x)
29 >>> for y in z2:
30 ... print(y)
31 2
32 6
33 10
34
35 >>> l2 = two_lists()
36 >>> for y in l2.primes:
37 ... print(y)
38 2
39 3
40 5
41 7
42 11
43 13
44 >>> for y in l2.evens:
45 ... print(y)
46 2
47 4
48 6
49 8
50 10
51 12
52 >>> ll = list_list()
53 >>> ll.push_back(x)
54 >>> x.push_back(7)
55 >>> ll.push_back(x)
56 >>> for a in ll: #doctest: +NORMALIZE_WHITESPACE
57 ... for b in a:
58 ... print(b, end=' ')
59 ... print('')
60 ...
61 1 3 5
62 1 3 5 7
63 '''
64
65 from __future__ import print_function
66
67 def run(args = None):
68 import sys
69 import doctest
70
71 if args is not None:
72 sys.argv = args
73 return doctest.testmod(sys.modules.get(__name__))
74
75 if __name__ == '__main__':
76 print("running...")
77 import sys
78 status = run()[0]
79 if (status == 0): print("Done.")
80 sys.exit(status)