diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-14 23:17:06 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-14 23:17:06 +1100 |
commit | d77da83d55c5de4768720fa578b9ffa5ec502dc6 (patch) | |
tree | 83af1a61c38ea661736c75f86b2d0ab7cc67a96e /tests/basics/builtin_range_binop.py | |
parent | 5604b710c2490e2a7cfd1bac6cd60fc2c8527a37 (diff) | |
download | micropython-d77da83d55c5de4768720fa578b9ffa5ec502dc6.tar.gz micropython-d77da83d55c5de4768720fa578b9ffa5ec502dc6.zip |
py/objrange: Implement (in)equality comparison between range objects.
This feature is not often used so is guarded by the config option
MICROPY_PY_BUILTINS_RANGE_BINOP which is disabled by default. With this
option disabled MicroPython will always return false when comparing two
range objects for equality (unless they are exactly the same object
instance). This does not match CPython so if (in)equality between range
objects is needed then this option should be enabled.
Enabling this option costs between 100 and 200 bytes of code space
depending on the machine architecture.
Diffstat (limited to 'tests/basics/builtin_range_binop.py')
-rw-r--r-- | tests/basics/builtin_range_binop.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/basics/builtin_range_binop.py b/tests/basics/builtin_range_binop.py new file mode 100644 index 0000000000..e4e054c276 --- /dev/null +++ b/tests/basics/builtin_range_binop.py @@ -0,0 +1,32 @@ +# test binary operations on range objects; (in)equality only + +# this "feature test" actually tests the implementation but is the best we can do +if range(1) != range(1): + print("SKIP") + raise SystemExit + +# basic (in)equality +print(range(1) == range(1)) +print(range(1) != range(1)) +print(range(1) != range(2)) + +# empty range +print(range(0) == range(0)) +print(range(1, 0) == range(0)) +print(range(1, 4, -1) == range(6, 3)) + +# 1 element range +print(range(1, 4, 10) == range(1, 4, 10)) +print(range(1, 4, 10) == range(1, 4, 20)) +print(range(1, 4, 10) == range(1, 8, 20)) + +# more than 1 element +print(range(0, 3, 2) == range(0, 3, 2)) +print(range(0, 3, 2) == range(0, 4, 2)) +print(range(0, 3, 2) == range(0, 5, 2)) + +# unsupported binary op +try: + range(1) + 10 +except TypeError: + print('TypeError') |