diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-05-12 11:17:29 -0400 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2019-05-12 11:17:29 -0400 |
| commit | 8664a6574b4cb448df26bfaa0e12eb203cc5d759 (patch) | |
| tree | 3fbbb02abd779ccb7e34f53b0b20d37a25b3e27c /tests | |
| parent | d103ac1d6325a075be3fafe812858584435f3144 (diff) | |
use approx of original @godlygeek code for smallints; add tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/bigint_array_overflow.py (renamed from tests/basics/array_overflow.py) | 7 | ||||
| -rw-r--r-- | tests/basics/int_bytes.py | 2 | ||||
| -rw-r--r-- | tests/basics/smallint_array_overflow.py | 52 |
3 files changed, 54 insertions, 7 deletions
diff --git a/tests/basics/array_overflow.py b/tests/basics/bigint_array_overflow.py index ba3eb7f06..0dd79c23d 100644 --- a/tests/basics/array_overflow.py +++ b/tests/basics/bigint_array_overflow.py @@ -13,13 +13,6 @@ def test_array_overflow(typecode, val): except OverflowError: print('OverflowError') -# small int -1 -test_array_overflow('Q', -1) -test_array_overflow('L', -1) -test_array_overflow('I', -1) -test_array_overflow('H', -1) -test_array_overflow('B', -1) - # big int -1 test_array_overflow('Q', -2**64 // 2**64) test_array_overflow('L', -2**64 // 2**64) diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 8c0c9a82f..aaf440081 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -1,4 +1,6 @@ print((10).to_bytes(1, "little")) +# Test fitting in length that's not a power of two. +print((0x10000).to_bytes(3, 'little')) print((111111).to_bytes(4, "little")) print((100).to_bytes(10, "little")) diff --git a/tests/basics/smallint_array_overflow.py b/tests/basics/smallint_array_overflow.py new file mode 100644 index 000000000..25b457cca --- /dev/null +++ b/tests/basics/smallint_array_overflow.py @@ -0,0 +1,52 @@ +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit + +def test_array_overflow(typecode, val): + try: + print(array(typecode, [val])) + except OverflowError: + print('OverflowError') + +def test_bytearray_overflow(val): + try: + print(bytearray([val])) + except (OverflowError, ValueError): + # CircuitPython always does OverflowError + print('(OverflowError, ValueError)') + + +# small int -1 +test_array_overflow('Q', -1) +test_array_overflow('L', -1) +test_array_overflow('I', -1) +test_array_overflow('H', -1) +test_array_overflow('B', -1) + +# 0 ok +test_array_overflow('Q', 0) +test_array_overflow('L', 0) +test_array_overflow('I', 0) +test_array_overflow('H', 0) +test_array_overflow('B', 0) + +# 1 ok +test_array_overflow('Q', 1) +test_array_overflow('L', 1) +test_array_overflow('I', 1) +test_array_overflow('H', 1) +test_array_overflow('B', 1) + +# truth value conversions +test_array_overflow('b', True) +test_array_overflow('b', False) + +# similar tests for bytearrays +test_bytearray_overflow(0) +test_bytearray_overflow(1) +test_bytearray_overflow(-1) +test_bytearray_overflow(256) +test_bytearray_overflow(True) +test_bytearray_overflow(False) |
