circuitpython/tests/basics/builtin_reversed.py
Scott Shawcroft fab634e3ee Turn on Rosie CI testing to test new builds on real hardware.
This introduces a skip_if module that can be used by tests to
determine when they should be skipped due to the environment.

Some tests have been split in order to have finer grained skip
control.
2017-08-11 17:16:13 -07:00

41 lines
657 B
Python

import skip_if
skip_if.no_reversed()
# list
print(list(reversed([])))
print(list(reversed([1])))
print(list(reversed([1, 2, 3])))
# tuple
print(list(reversed(())))
print(list(reversed((1, 2, 3))))
# string
for c in reversed('ab'):
print(c)
# bytes
for b in reversed(b'1234'):
print(b)
# range
for i in reversed(range(3)):
print(i)
# user object
class A:
def __init__(self):
pass
def __len__(self):
return 3
def __getitem__(self, pos):
return pos + 1
for a in reversed(A()):
print(a)
# user object with __reversed__
class B:
def __reversed__(self):
return [1, 2, 3]
print(reversed(B()))