summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
authorstijn <stijn@ignitron.net>2021-05-10 16:40:51 +0200
committerDamien George <damien@micropython.org>2021-05-13 22:16:14 +1000
commit09be0c083cb493c70b38079aa6fd785aa9b0b90a (patch)
tree531a4e6ab1d211be846186bae4a804f2b9719b97 /tests/basics
parent57365d855734142deb030ebcd00c10efcedf554b (diff)
downloadmicropython-09be0c083cb493c70b38079aa6fd785aa9b0b90a.tar.gz
micropython-09be0c083cb493c70b38079aa6fd785aa9b0b90a.zip
py/objarray: Implement more/less comparisons for array.
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/array1.py21
-rw-r--r--tests/basics/bytearray1.py20
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/basics/array1.py b/tests/basics/array1.py
index 15789e2c99..f21ad4bd75 100644
--- a/tests/basics/array1.py
+++ b/tests/basics/array1.py
@@ -66,3 +66,24 @@ print(X('b', [0x61, 0x62, 0x63]) == b'abc')
print(X('b', [0x61, 0x62, 0x63]) != b'abc')
print(X('b', [0x61, 0x62, 0x63]) == array.array('b', [0x61, 0x62, 0x63]))
print(X('b', [0x61, 0x62, 0x63]) != array.array('b', [0x61, 0x62, 0x63]))
+
+# other comparisons
+for typecode in ["B", "H", "I", "L", "Q"]:
+ a = array.array(typecode, [1, 1])
+ print(a < a)
+ print(a <= a)
+ print(a > a)
+ print(a >= a)
+
+ al = array.array(typecode, [1, 0])
+ ab = array.array(typecode, [1, 2])
+
+ print(a < al)
+ print(a <= al)
+ print(a > al)
+ print(a >= al)
+
+ print(a < ab)
+ print(a <= ab)
+ print(a > ab)
+ print(a >= ab)
diff --git a/tests/basics/bytearray1.py b/tests/basics/bytearray1.py
index b598500264..d12292e879 100644
--- a/tests/basics/bytearray1.py
+++ b/tests/basics/bytearray1.py
@@ -27,6 +27,26 @@ print(bytearray([1]) == b"1")
print(b"1" == bytearray([1]))
print(bytearray() == bytearray())
+b1 = bytearray([1, 2, 3])
+b2 = bytearray([1, 2, 3])
+b3 = bytearray([1, 3])
+print(b1 == b2)
+print(b2 != b3)
+print(b1 <= b2)
+print(b1 <= b3)
+print(b1 < b3)
+print(b1 >= b2)
+print(b3 >= b2)
+print(b3 > b2)
+print(b1 != b2)
+print(b2 == b3)
+print(b1 > b2)
+print(b1 > b3)
+print(b1 >= b3)
+print(b1 < b2)
+print(b3 < b2)
+print(b3 <= b2)
+
# comparison with other type should return False
print(bytearray() == 1)