app.py:
from py_class_base_examples import PyIterTestA
def main():
iter_test = PyIterTestA(5)
print()
print("Testing PyIterTestA with count 5")
for i in iter_test:
print(i)
print("Done iterating")
print()
print("as list: ", list(iter_test))
map_test = map(lambda x: x * 2, iter_test)
print("map test: ", list(map_test))
print()
iter_test2 = PyIterTestA(20)
print("Testing PyIterTestA with count 20")
for i in iter_test2:
print(i)
print("Done iterating")
print()
print("as list: ", list(iter_test2))
map_test2 = map(lambda x: x * 2, iter_test2)
print("map test: ", list(map_test2))
print()
print("Testing operations on iter_test and iter_test2")
print("iter_test * 2: ", iter_test * 2 )
print("iter_test + 2: ", iter_test + 2)
print("iter_test2 * 2: ", iter_test2 * 2)
print("iter_test2 + 2: ", iter_test2 + 2)
print()
print("Testing in operator")
print("2 is in iter_test?")
if 2 in iter_test:
print("\ttrue")
else:
print("\tfalse")
print("3 is in iter_test?")
if 3 in iter_test:
print("\ttrue")
else:
print("\tfalse")
print("3 is in (iter_test + 1)?")
if 3 in (iter_test + 1):
print("\ttrue")
else:
print("\tfalse")
print()
print("iter_test += 1")
iter_test += 1
print("iter_test: ", list(iter_test))
print()
print("iter_test *= 2")
iter_test *= 2
print("iter_test: ", list(iter_test))
print()
print("iter_test2 *= 2")
iter_test2 *= 2
print("iter_test2: ", list(iter_test2))
xcode log:
PyIterTestA init(max: 5)
Testing PyIterTestA with count 5
0
2
6
12
20
Done iterating
using PyIterTestA.__len__
as list: [0, 2, 6, 12, 20]
map test: [0, 4, 12, 24, 40]
PyIterTestA init(max: 20)
Testing PyIterTestA with count 20
0
2
6
12
20
30
42
56
72
90
110
132
156
182
210
240
272
306
342
380
Done iterating
using PyIterTestA.__len__
as list: [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380]
map test: [0, 4, 12, 24, 40, 60, 84, 112, 144, 180, 220, 264, 312, 364, 420, 480, 544, 612, 684, 760]
Testing operations on iter_test and iter_test2
using PyIterTestA.__mul__
iter_test * 2: [0, 4, 12, 24, 40]
using PyIterTestA.__add__
iter_test + 2: [2, 4, 8, 14, 22]
using PyIterTestA.__mul__
iter_test2 * 2: [0, 4, 12, 24, 40, 60, 84, 112, 144, 180, 220, 264, 312, 364, 420, 480, 544, 612, 684, 760]
using PyIterTestA.__add__
iter_test2 + 2: [2, 4, 8, 14, 22, 32, 44, 58, 74, 92, 112, 134, 158, 184, 212, 242, 274, 308, 344, 382]
Testing in operator
2 is in iter_test?
using PyIterTestA.__contains__
true
3 is in iter_test?
using PyIterTestA.__contains__
false
3 is in (iter_test + 1)?
using PyIterTestA.__add__
true
iter_test += 1
using PyIterTestA.__iadd__
PyIterTestA init(max: 6)
using PyIterTestA.__len__
iter_test: [0, 2, 6, 12, 20, 30]
iter_test *= 2
using PyIterTestA.__imul__
PyIterTestA init(max: 12)
PyIterTestA deinit - max: 6)
using PyIterTestA.__len__
iter_test: [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132]
iter_test2 *= 2
using PyIterTestA.__imul__
PyIterTestA init(max: 40)
using PyIterTestA.__len__
iter_test2: [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600, 650, 702, 756, 812, 870, 930, 992, 1056, 1122, 1190, 1260, 1332, 1406, 1482, 1560]
PyIterTestA deinit - max: 12)
PyIterTestA deinit - max: 5)
PyIterTestA deinit - max: 40)
PyIterTestA deinit - max: 20)