removing pesky directories
This commit is contained in:
parent
ca757f2ead
commit
2f476731ec
@ -1,18 +0,0 @@
|
||||
This directory contains tests for various functionality areas of MicroPython.
|
||||
To run all stable tests, run "run-tests" script in this directory.
|
||||
|
||||
Tests of capabilities not supported on all platforms should be written
|
||||
to check for the capability being present. If it is not, the test
|
||||
should merely output 'SKIP' followed by the line terminator, and call
|
||||
sys.exit() to raise SystemExit, instead of attempting to test the
|
||||
missing capability. The testing framework (run-tests in this
|
||||
directory, test_main.c in qemu_arm) recognizes this as a skipped test.
|
||||
|
||||
There are a few features for which this mechanism cannot be used to
|
||||
condition a test. The run-tests script uses small scripts in the
|
||||
feature_check directory to check whether each such feature is present,
|
||||
and skips the relevant tests if not.
|
||||
|
||||
When creating new tests, anything that relies on float support should go in the
|
||||
float/ subdirectory. Anything that relies on import x, where x is not a built-in
|
||||
module, should go in the import/ subdirectory.
|
@ -1,89 +0,0 @@
|
||||
try:
|
||||
import btree
|
||||
import uio
|
||||
import uerrno
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
#f = open("_test.db", "w+b")
|
||||
f = uio.BytesIO()
|
||||
db = btree.open(f, pagesize=512)
|
||||
|
||||
db[b"foo3"] = b"bar3"
|
||||
db[b"foo1"] = b"bar1"
|
||||
db[b"foo2"] = b"bar2"
|
||||
db[b"bar1"] = b"foo1"
|
||||
|
||||
dbstr = str(db)
|
||||
print(dbstr[:7], dbstr[-1:])
|
||||
|
||||
print(db[b"foo2"])
|
||||
try:
|
||||
print(db[b"foo"])
|
||||
except KeyError:
|
||||
print("KeyError")
|
||||
print(db.get(b"foo"))
|
||||
print(db.get(b"foo", b"dflt"))
|
||||
|
||||
del db[b"foo2"]
|
||||
try:
|
||||
del db[b"foo"]
|
||||
except KeyError:
|
||||
print("KeyError")
|
||||
|
||||
for k, v in db.items():
|
||||
print((k, v))
|
||||
|
||||
print("---")
|
||||
for k, v in db.items(None, None):
|
||||
print((k, v))
|
||||
|
||||
print("---")
|
||||
for k, v in db.items(b"f"):
|
||||
print((k, v))
|
||||
|
||||
print("---")
|
||||
for k, v in db.items(b"f", b"foo3"):
|
||||
print((k, v))
|
||||
|
||||
print("---")
|
||||
for k, v in db.items(None, b"foo3"):
|
||||
print((k, v))
|
||||
|
||||
print("---")
|
||||
for k, v in db.items(b"f", b"foo3", btree.INCL):
|
||||
print((k, v))
|
||||
|
||||
print("---")
|
||||
for k, v in db.items(None, None, btree.DESC):
|
||||
print((k, v))
|
||||
|
||||
print(db.seq(1, b"foo1"))
|
||||
print(db.seq(1, b"qux"))
|
||||
|
||||
try:
|
||||
db.seq(b"foo1")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
print(list(db.keys()))
|
||||
print(list(db.values()))
|
||||
|
||||
for k in db:
|
||||
print(k)
|
||||
|
||||
db.put(b"baz1", b"qux1")
|
||||
|
||||
print("foo1", "foo1" in db)
|
||||
print("foo2", "foo2" in db)
|
||||
print("baz1", "baz1" in db)
|
||||
|
||||
try:
|
||||
print(db + db[b"foo1"])
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
db.flush()
|
||||
db.close()
|
||||
f.close()
|
@ -1,109 +0,0 @@
|
||||
try:
|
||||
import framebuf
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
w = 5
|
||||
h = 16
|
||||
size = w * h // 8
|
||||
buf = bytearray(size)
|
||||
maps = {framebuf.MONO_VLSB : 'MONO_VLSB',
|
||||
framebuf.MONO_HLSB : 'MONO_HLSB',
|
||||
framebuf.MONO_HMSB : 'MONO_HMSB'}
|
||||
|
||||
for mapping in maps.keys():
|
||||
for x in range(size):
|
||||
buf[x] = 0
|
||||
fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
|
||||
print(maps[mapping])
|
||||
# access as buffer
|
||||
print(memoryview(fbuf)[0])
|
||||
|
||||
# fill
|
||||
fbuf.fill(1)
|
||||
print(buf)
|
||||
fbuf.fill(0)
|
||||
print(buf)
|
||||
|
||||
# put pixel
|
||||
fbuf.pixel(0, 0, 1)
|
||||
fbuf.pixel(4, 0, 1)
|
||||
fbuf.pixel(0, 15, 1)
|
||||
fbuf.pixel(4, 15, 1)
|
||||
print(buf)
|
||||
|
||||
# clear pixel
|
||||
fbuf.pixel(4, 15, 0)
|
||||
print(buf)
|
||||
|
||||
# get pixel
|
||||
print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
|
||||
|
||||
# hline
|
||||
fbuf.fill(0)
|
||||
fbuf.hline(0, 1, w, 1)
|
||||
print('hline', buf)
|
||||
|
||||
# vline
|
||||
fbuf.fill(0)
|
||||
fbuf.vline(1, 0, h, 1)
|
||||
print('vline', buf)
|
||||
|
||||
# rect
|
||||
fbuf.fill(0)
|
||||
fbuf.rect(1, 1, 3, 3, 1)
|
||||
print('rect', buf)
|
||||
|
||||
#fill rect
|
||||
fbuf.fill(0)
|
||||
fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
|
||||
fbuf.fill_rect(1, 1, 3, 3, 1)
|
||||
print('fill_rect', buf)
|
||||
|
||||
# line
|
||||
fbuf.fill(0)
|
||||
fbuf.line(1, 1, 3, 3, 1)
|
||||
print('line', buf)
|
||||
|
||||
# line steep negative gradient
|
||||
fbuf.fill(0)
|
||||
fbuf.line(3, 3, 2, 1, 1)
|
||||
print('line', buf)
|
||||
|
||||
# scroll
|
||||
fbuf.fill(0)
|
||||
fbuf.pixel(2, 7, 1)
|
||||
fbuf.scroll(0, 1)
|
||||
print(buf)
|
||||
fbuf.scroll(0, -2)
|
||||
print(buf)
|
||||
fbuf.scroll(1, 0)
|
||||
print(buf)
|
||||
fbuf.scroll(-1, 0)
|
||||
print(buf)
|
||||
fbuf.scroll(2, 2)
|
||||
print(buf)
|
||||
|
||||
# print text
|
||||
fbuf.fill(0)
|
||||
fbuf.text("hello", 0, 0, 1)
|
||||
print(buf)
|
||||
fbuf.text("hello", 0, 0, 0) # clear
|
||||
print(buf)
|
||||
|
||||
# char out of font range set to chr(127)
|
||||
fbuf.text(str(chr(31)), 0, 0)
|
||||
print(buf)
|
||||
print()
|
||||
|
||||
# test invalid constructor, and stride argument
|
||||
try:
|
||||
fbuf = framebuf.FrameBuffer(buf, w, h, -1, w)
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
|
||||
# test legacy constructor
|
||||
fbuf = framebuf.FrameBuffer1(buf, w, h)
|
||||
fbuf = framebuf.FrameBuffer1(buf, w, h, w)
|
||||
print(framebuf.MVLSB == framebuf.MONO_VLSB)
|
@ -1,59 +0,0 @@
|
||||
try:
|
||||
import framebuf
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def printbuf():
|
||||
print("--8<--")
|
||||
for y in range(h):
|
||||
print(buf[y * w * 2:(y + 1) * w * 2])
|
||||
print("-->8--")
|
||||
|
||||
w = 4
|
||||
h = 5
|
||||
buf = bytearray(w * h * 2)
|
||||
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
|
||||
|
||||
# fill
|
||||
fbuf.fill(0xffff)
|
||||
printbuf()
|
||||
fbuf.fill(0x0000)
|
||||
printbuf()
|
||||
|
||||
# put pixel
|
||||
fbuf.pixel(0, 0, 0xeeee)
|
||||
fbuf.pixel(3, 0, 0xee00)
|
||||
fbuf.pixel(0, 4, 0x00ee)
|
||||
fbuf.pixel(3, 4, 0x0ee0)
|
||||
printbuf()
|
||||
|
||||
# get pixel
|
||||
print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
|
||||
|
||||
# scroll
|
||||
fbuf.fill(0x0000)
|
||||
fbuf.pixel(2, 2, 0xffff)
|
||||
printbuf()
|
||||
fbuf.scroll(0, 1)
|
||||
printbuf()
|
||||
fbuf.scroll(1, 0)
|
||||
printbuf()
|
||||
fbuf.scroll(-1, -2)
|
||||
printbuf()
|
||||
|
||||
w2 = 2
|
||||
h2 = 3
|
||||
buf2 = bytearray(w2 * h2 * 2)
|
||||
fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
|
||||
|
||||
fbuf2.fill(0x0000)
|
||||
fbuf2.pixel(0, 0, 0x0ee0)
|
||||
fbuf2.pixel(0, 2, 0xee00)
|
||||
fbuf2.pixel(1, 0, 0x00ee)
|
||||
fbuf2.pixel(1, 2, 0xe00e)
|
||||
fbuf.fill(0xffff)
|
||||
fbuf.blit(fbuf2, 3, 3, 0x0000)
|
||||
fbuf.blit(fbuf2, -1, -1, 0x0000)
|
||||
fbuf.blit(fbuf2, 16, 16, 0x0000)
|
||||
printbuf()
|
@ -1,57 +0,0 @@
|
||||
--8<--
|
||||
33333333
|
||||
33333333
|
||||
33333333
|
||||
33333333
|
||||
33333333
|
||||
-->8--
|
||||
--8<--
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
-->8--
|
||||
--8<--
|
||||
10020000
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
30020000
|
||||
-->8--
|
||||
3 0
|
||||
--8<--
|
||||
00000000
|
||||
00000000
|
||||
00300000
|
||||
00000000
|
||||
00000000
|
||||
-->8--
|
||||
--8<--
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00300000
|
||||
00000000
|
||||
-->8--
|
||||
--8<--
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00030000
|
||||
00000000
|
||||
-->8--
|
||||
--8<--
|
||||
00000000
|
||||
00300000
|
||||
00000000
|
||||
00030000
|
||||
00000000
|
||||
-->8--
|
||||
--8<--
|
||||
33333333
|
||||
23333333
|
||||
33333333
|
||||
33311333
|
||||
33333333
|
||||
-->8--
|
@ -1,53 +0,0 @@
|
||||
try:
|
||||
import framebuf
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def printbuf():
|
||||
print("--8<--")
|
||||
for y in range(h):
|
||||
print(buf[y * w // 2:(y + 1) * w // 2])
|
||||
print("-->8--")
|
||||
|
||||
w = 16
|
||||
h = 8
|
||||
buf = bytearray(w * h // 2)
|
||||
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
|
||||
|
||||
# fill
|
||||
fbuf.fill(0x0f)
|
||||
printbuf()
|
||||
fbuf.fill(0xa0)
|
||||
printbuf()
|
||||
|
||||
# put pixel
|
||||
fbuf.pixel(0, 0, 0x01)
|
||||
printbuf()
|
||||
fbuf.pixel(w-1, 0, 0x02)
|
||||
printbuf()
|
||||
fbuf.pixel(w-1, h-1, 0x03)
|
||||
printbuf()
|
||||
fbuf.pixel(0, h-1, 0x04)
|
||||
printbuf()
|
||||
|
||||
# get pixel
|
||||
print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1))
|
||||
print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1))
|
||||
|
||||
# fill rect
|
||||
fbuf.fill_rect(0, 0, w, h, 0x0f)
|
||||
printbuf()
|
||||
fbuf.fill_rect(0, 0, w, h, 0xf0)
|
||||
fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1)
|
||||
printbuf()
|
||||
fbuf.fill_rect(1, 0, w//2+1, 1, 0x10)
|
||||
fbuf.fill_rect(1, 0, w//2, 1, 0xf1)
|
||||
printbuf()
|
||||
fbuf.fill_rect(1, 0, w//2, 1, 0x10)
|
||||
fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf)
|
||||
printbuf()
|
||||
fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0)
|
||||
fbuf.fill_rect(0, h-4, w//2, 4, 0xaf)
|
||||
printbuf()
|
||||
fbuf.fill_rect(0, h-4, w//2, 4, 0xb0)
|
@ -1,20 +0,0 @@
|
||||
# test subclassing framebuf.FrameBuffer
|
||||
|
||||
try:
|
||||
import framebuf
|
||||
except ImportError:
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
class FB(framebuf.FrameBuffer):
|
||||
def __init__(self, n):
|
||||
self.n = n
|
||||
super().__init__(bytearray(2 * n * n), n, n, framebuf.RGB565)
|
||||
|
||||
def foo(self):
|
||||
self.hline(0, 2, self.n, 0x0304)
|
||||
|
||||
fb = FB(n=3)
|
||||
fb.pixel(0, 0, 0x0102)
|
||||
fb.foo()
|
||||
print(bytes(fb))
|
@ -1,28 +0,0 @@
|
||||
# test machine module
|
||||
|
||||
try:
|
||||
try:
|
||||
import umachine as machine
|
||||
except ImportError:
|
||||
import machine
|
||||
machine.mem8
|
||||
except:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(machine.mem8)
|
||||
|
||||
try:
|
||||
machine.mem16[1]
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
|
||||
try:
|
||||
machine.mem16[1] = 1
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
|
||||
try:
|
||||
del machine.mem8[0]
|
||||
except TypeError:
|
||||
print("TypeError")
|
@ -1,30 +0,0 @@
|
||||
try:
|
||||
import umachine as machine
|
||||
except ImportError:
|
||||
import machine
|
||||
try:
|
||||
machine.PinBase
|
||||
except AttributeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
class MyPin(machine.PinBase):
|
||||
|
||||
def __init__(self):
|
||||
print("__init__")
|
||||
self.v = False
|
||||
|
||||
def value(self, v=None):
|
||||
print("value:", v)
|
||||
if v is None:
|
||||
self.v = not self.v
|
||||
return int(self.v)
|
||||
|
||||
p = MyPin()
|
||||
|
||||
print(p.value())
|
||||
print(p.value())
|
||||
print(p.value())
|
||||
p.value(1)
|
||||
p.value(0)
|
@ -1,9 +0,0 @@
|
||||
__init__
|
||||
value: None
|
||||
1
|
||||
value: None
|
||||
0
|
||||
value: None
|
||||
1
|
||||
value: 1
|
||||
value: 0
|
@ -1,33 +0,0 @@
|
||||
from utime import ticks_diff, ticks_add
|
||||
|
||||
MAX = ticks_add(0, -1)
|
||||
# Should be done like this to avoid small int overflow
|
||||
MODULO_HALF = MAX // 2 + 1
|
||||
|
||||
# Invariants:
|
||||
# if ticks_diff(a, b) = c,
|
||||
# then ticks_diff(b, a) = -c
|
||||
|
||||
assert ticks_diff(1, 0) == 1, ticks_diff(1, 0)
|
||||
assert ticks_diff(0, 1) == -1
|
||||
|
||||
assert ticks_diff(0, MAX) == 1
|
||||
assert ticks_diff(MAX, 0) == -1
|
||||
|
||||
assert ticks_diff(0, MAX - 1) == 2
|
||||
|
||||
# Maximum "positive" distance
|
||||
assert ticks_diff(MODULO_HALF, 1) == MODULO_HALF - 1, ticks_diff(MODULO_HALF, 1)
|
||||
# Step further, and it becomes a negative distance
|
||||
assert ticks_diff(MODULO_HALF, 0) == -MODULO_HALF
|
||||
|
||||
# Offsetting that in either direction doesn't affect the result
|
||||
off = 100
|
||||
# Cheating and skipping to use ticks_add() when we know there's no wraparound
|
||||
# Real apps should use always it.
|
||||
assert ticks_diff(MODULO_HALF + off, 1 + off) == MODULO_HALF - 1
|
||||
assert ticks_diff(MODULO_HALF + off, 0 + off) == -MODULO_HALF
|
||||
assert ticks_diff(MODULO_HALF - off, ticks_add(1, -off)) == MODULO_HALF - 1
|
||||
assert ticks_diff(MODULO_HALF - off, ticks_add(0, -off)) == -MODULO_HALF
|
||||
|
||||
print("OK")
|
@ -1,22 +0,0 @@
|
||||
import utime
|
||||
try:
|
||||
utime.sleep_ms
|
||||
except AttributeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
utime.sleep_ms(1)
|
||||
utime.sleep_us(1)
|
||||
|
||||
t0 = utime.ticks_ms()
|
||||
t1 = utime.ticks_ms()
|
||||
print(0 <= utime.ticks_diff(t1, t0) <= 1)
|
||||
|
||||
t0 = utime.ticks_us()
|
||||
t1 = utime.ticks_us()
|
||||
print(0 <= utime.ticks_diff(t1, t0) <= 500)
|
||||
|
||||
# ticks_cpu may not be implemented, at least make sure it doesn't decrease
|
||||
t0 = utime.ticks_cpu()
|
||||
t1 = utime.ticks_cpu()
|
||||
print(utime.ticks_diff(t1, t0) >= 0)
|
@ -1,3 +0,0 @@
|
||||
True
|
||||
True
|
||||
True
|
@ -1,49 +0,0 @@
|
||||
try:
|
||||
try:
|
||||
import ubinascii as binascii
|
||||
except ImportError:
|
||||
import binascii
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(binascii.a2b_base64(b''))
|
||||
print(binascii.a2b_base64(b'Zg=='))
|
||||
print(binascii.a2b_base64(b'Zm8='))
|
||||
print(binascii.a2b_base64(b'Zm9v'))
|
||||
print(binascii.a2b_base64(b'Zm9vYg=='))
|
||||
print(binascii.a2b_base64(b'Zm9vYmE='))
|
||||
print(binascii.a2b_base64(b'Zm9vYmFy'))
|
||||
|
||||
print(binascii.a2b_base64(b'AAECAwQFBgc='))
|
||||
print(binascii.a2b_base64(b'CAkKCwwNDg8='))
|
||||
print(binascii.a2b_base64(b'f4D/'))
|
||||
print(binascii.a2b_base64(b'f4D+')) # convert '+'
|
||||
print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk'))
|
||||
|
||||
# Ignore invalid characters and pad sequences
|
||||
print(binascii.a2b_base64(b'Zm9v\n'))
|
||||
print(binascii.a2b_base64(b'Zm\x009v\n'))
|
||||
print(binascii.a2b_base64(b'Zm9v=='))
|
||||
print(binascii.a2b_base64(b'Zm9v==='))
|
||||
print(binascii.a2b_base64(b'Zm9v===YmFy'))
|
||||
|
||||
# Unicode strings can be decoded
|
||||
print(binascii.a2b_base64(u'Zm9v===YmFy'))
|
||||
|
||||
try:
|
||||
print(binascii.a2b_base64(b'abc'))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
print(binascii.a2b_base64(b'abcde='))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
print(binascii.a2b_base64(b'ab*d'))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
print(binascii.a2b_base64(b'ab=cdef='))
|
||||
except ValueError:
|
||||
print("ValueError")
|
@ -1,17 +0,0 @@
|
||||
try:
|
||||
try:
|
||||
import ubinascii as binascii
|
||||
except ImportError:
|
||||
import binascii
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
|
||||
print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
|
||||
print(binascii.hexlify(b'\x7f\x80\xff'))
|
||||
print(binascii.hexlify(b'1234ABCDabcd'))
|
||||
try:
|
||||
binascii.hexlify('')
|
||||
except TypeError:
|
||||
print("TypeError")
|
@ -1,11 +0,0 @@
|
||||
b'\xff\xff\xff\x7f5678abcd'
|
||||
b'\x00\x00\x00\x805678abcd'
|
||||
b'\x03\x02\x01\xff5678abcd'
|
||||
b'\x03\x02\x01\xff\x00\x00\x00\x80\x00\x00\x00\x00'
|
||||
b'\x03\x02\x01\xff\x00\x00\x00\x00\x01\x00\x00\x00'
|
||||
=
|
||||
b'\x7f\xff\xff\xff5678abcd'
|
||||
b'\x80\x00\x00\x005678abcd'
|
||||
b'\xff\x01\x02\x035678abcd'
|
||||
b'\xff\x01\x02\x03\x00\x00\x00\x00\x80\x00\x00\x00'
|
||||
b'\xff\x01\x02\x03\x00\x00\x00\x01\x00\x00\x00\x00'
|
@ -1,89 +0,0 @@
|
||||
import sys
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
if sys.byteorder != "little":
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = {
|
||||
# arr is array at offset 0, of UINT8 elements, array size is 2
|
||||
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
|
||||
# arr2 is array at offset 0, size 2, of structures defined recursively
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
|
||||
# aligned
|
||||
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
|
||||
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
|
||||
|
||||
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
|
||||
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
|
||||
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
|
||||
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
|
||||
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
|
||||
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
|
||||
}
|
||||
|
||||
data = bytearray(8)
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc)
|
||||
|
||||
# assign byte
|
||||
S.arr[0] = 0x11
|
||||
print(hex(S.arr[0]))
|
||||
assert hex(S.arr[0]) == "0x11"
|
||||
|
||||
# assign word
|
||||
S.arr3[0] = 0x2233
|
||||
print(hex(S.arr3[0]))
|
||||
assert hex(S.arr3[0]) == "0x2233"
|
||||
|
||||
# assign word, with index
|
||||
S.arr3[1] = 0x4455
|
||||
print(hex(S.arr3[1]))
|
||||
assert hex(S.arr3[1]) == "0x4455"
|
||||
|
||||
# assign long, aligned
|
||||
S.arr5[0] = 0x66778899
|
||||
print(hex(S.arr5[0]))
|
||||
assert hex(S.arr5[0]) == "0x66778899"
|
||||
|
||||
print(S.arr5[0] == S.arr7[0].l)
|
||||
assert S.arr5[0] == S.arr7[0].l
|
||||
|
||||
# assign int8
|
||||
S.arr8[0] = 0x11
|
||||
print(hex(S.arr8[0]))
|
||||
assert hex(S.arr8[0]) == "0x11"
|
||||
|
||||
# assign int16
|
||||
S.arr9[0] = 0x1122
|
||||
print(hex(S.arr9[0]))
|
||||
assert hex(S.arr9[0]) == "0x1122"
|
||||
|
||||
# assign int32
|
||||
S.arr10[0] = 0x11223344
|
||||
print(hex(S.arr10[0]))
|
||||
assert hex(S.arr10[0]) == "0x11223344"
|
||||
|
||||
# index out of range
|
||||
try:
|
||||
print(S.arr8[2])
|
||||
except IndexError:
|
||||
print("IndexError")
|
||||
|
||||
# syntax error in descriptor
|
||||
try:
|
||||
S.arr13[0].l = 0x11
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# operation not supported
|
||||
try:
|
||||
S.arr13[0] = 0x11
|
||||
except TypeError:
|
||||
print("TypeError")
|
@ -1,11 +0,0 @@
|
||||
0x11
|
||||
0x2233
|
||||
0x4455
|
||||
0x66778899
|
||||
True
|
||||
0x11
|
||||
0x1122
|
||||
0x11223344
|
||||
IndexError
|
||||
TypeError
|
||||
TypeError
|
@ -1,43 +0,0 @@
|
||||
import sys
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
if sys.byteorder != "little":
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = {
|
||||
# arr is array at offset 0, of UINT8 elements, array size is 2
|
||||
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
|
||||
# arr2 is array at offset 0, size 2, of structures defined recursively
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
|
||||
# aligned
|
||||
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
|
||||
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
|
||||
|
||||
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
|
||||
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
|
||||
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
|
||||
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
|
||||
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
|
||||
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
|
||||
}
|
||||
|
||||
data = bytearray(8)
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc)
|
||||
|
||||
# assign int64
|
||||
S.arr11[0] = 0x11223344
|
||||
print(hex(S.arr11[0]))
|
||||
assert hex(S.arr11[0]) == "0x11223344"
|
||||
|
||||
# assign uint64
|
||||
S.arr12[0] = 0x11223344
|
||||
print(hex(S.arr12[0]))
|
||||
assert hex(S.arr12[0]) == "0x11223344"
|
@ -1,22 +0,0 @@
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = {
|
||||
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
|
||||
"arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2),
|
||||
}
|
||||
|
||||
data = bytearray(b"01234567")
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
|
||||
|
||||
# Arrays of UINT8 are accessed as bytearrays
|
||||
print(S.arr)
|
||||
# But not INT8, because value range is different
|
||||
print(type(S.arr2))
|
||||
|
||||
# convert to buffer
|
||||
print(bytearray(S))
|
@ -1,10 +0,0 @@
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
data = bytearray(b'01234567')
|
||||
|
||||
print(uctypes.bytes_at(uctypes.addressof(data), 4))
|
||||
print(uctypes.bytearray_at(uctypes.addressof(data), 4))
|
@ -1,2 +0,0 @@
|
||||
b'0123'
|
||||
bytearray(b'0123')
|
@ -1,37 +0,0 @@
|
||||
# test general errors with uctypes
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
data = bytearray(b"01234567")
|
||||
|
||||
# del subscr not supported
|
||||
S = uctypes.struct(uctypes.addressof(data), {})
|
||||
try:
|
||||
del S[0]
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# list is an invalid descriptor
|
||||
S = uctypes.struct(uctypes.addressof(data), [])
|
||||
try:
|
||||
S.x
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# can't access attribute with invalid descriptor
|
||||
S = uctypes.struct(uctypes.addressof(data), {'x':[]})
|
||||
try:
|
||||
S.x
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# can't assign to aggregate
|
||||
S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)})
|
||||
try:
|
||||
S.x = 1
|
||||
except TypeError:
|
||||
print('TypeError')
|
@ -1,4 +0,0 @@
|
||||
TypeError
|
||||
TypeError
|
||||
TypeError
|
||||
TypeError
|
@ -1,24 +0,0 @@
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = {
|
||||
"f32": uctypes.FLOAT32 | 0,
|
||||
"f64": uctypes.FLOAT64 | 0,
|
||||
"uf64": uctypes.FLOAT64 | 2, # unaligned
|
||||
}
|
||||
|
||||
data = bytearray(10)
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
|
||||
|
||||
S.f32 = 12.34
|
||||
print('%.4f' % S.f32)
|
||||
|
||||
S.f64 = 12.34
|
||||
print('%.4f' % S.f64)
|
||||
|
||||
S.uf64 = 12.34
|
||||
print('%.4f' % S.uf64)
|
@ -1,20 +0,0 @@
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = {
|
||||
"f32": uctypes.FLOAT32 | 0,
|
||||
"f64": uctypes.FLOAT64 | 0,
|
||||
}
|
||||
|
||||
data = bytearray(8)
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
|
||||
|
||||
S.f32 = 12.34
|
||||
print('%.4f' % S.f32)
|
||||
|
||||
S.f64 = 12.34
|
||||
print('%.4f' % S.f64)
|
@ -1,34 +0,0 @@
|
||||
import sys
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
if sys.byteorder != "little":
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = {
|
||||
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
|
||||
"ptr16": (uctypes.PTR | 0, uctypes.UINT16),
|
||||
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
|
||||
}
|
||||
|
||||
bytes = b"01"
|
||||
|
||||
addr = uctypes.addressof(bytes)
|
||||
buf = addr.to_bytes(uctypes.sizeof(desc), "little")
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN)
|
||||
|
||||
print(S.ptr[0])
|
||||
assert S.ptr[0] == ord("0")
|
||||
print(S.ptr[1])
|
||||
assert S.ptr[1] == ord("1")
|
||||
print(hex(S.ptr16[0]))
|
||||
assert hex(S.ptr16[0]) == "0x3130"
|
||||
print(S.ptr2[0].b, S.ptr2[1].b)
|
||||
print (S.ptr2[0].b, S.ptr2[1].b)
|
||||
print(hex(S.ptr16[0]))
|
||||
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
|
@ -1,6 +0,0 @@
|
||||
48
|
||||
49
|
||||
0x3130
|
||||
48 49
|
||||
48 49
|
||||
0x3130
|
@ -1,7 +0,0 @@
|
||||
2
|
||||
2
|
||||
4
|
||||
TypeError
|
||||
6
|
||||
1
|
||||
TypeError
|
@ -1,28 +0,0 @@
|
||||
try:
|
||||
import uhashlib as hashlib
|
||||
except ImportError:
|
||||
try:
|
||||
import hashlib
|
||||
except ImportError:
|
||||
# This is neither uPy, nor cPy, so must be uPy with
|
||||
# uhashlib module disabled.
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
try:
|
||||
hashlib.sha1
|
||||
except AttributeError:
|
||||
# SHA1 is only available on some ports
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
sha1 = hashlib.sha1(b'hello')
|
||||
sha1.update(b'world')
|
||||
print(sha1.digest())
|
||||
|
||||
sha1 = hashlib.sha1(b'hello')
|
||||
try:
|
||||
sha1.update(u'world')
|
||||
except TypeError as e:
|
||||
print("TypeError")
|
||||
print(sha1.digest())
|
@ -1,30 +0,0 @@
|
||||
try:
|
||||
from uio import StringIO
|
||||
import ujson as json
|
||||
except:
|
||||
try:
|
||||
from io import StringIO
|
||||
import json
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
s = StringIO()
|
||||
json.dump(False, s)
|
||||
print(s.getvalue())
|
||||
|
||||
s = StringIO()
|
||||
json.dump({"a": (2, [3, None])}, s)
|
||||
print(s.getvalue())
|
||||
|
||||
# dump to a small-int not allowed
|
||||
try:
|
||||
json.dump(123, 1)
|
||||
except (AttributeError, OSError): # CPython and uPy have different errors
|
||||
print('Exception')
|
||||
|
||||
# dump to an object not allowed
|
||||
try:
|
||||
json.dump(123, {})
|
||||
except (AttributeError, OSError): # CPython and uPy have different errors
|
||||
print('Exception')
|
@ -1,9 +0,0 @@
|
||||
# test uPy ujson behaviour that's not valid in CPy
|
||||
|
||||
try:
|
||||
import ujson
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(ujson.dumps(b'1234'))
|
@ -1,10 +0,0 @@
|
||||
try:
|
||||
import ujson as json
|
||||
except ImportError:
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(json.dumps(1.2))
|
@ -1,4 +0,0 @@
|
||||
None
|
||||
abcde
|
||||
[False, True, 1, -2]
|
||||
{'a': True}
|
@ -1,74 +0,0 @@
|
||||
try:
|
||||
import ujson as json
|
||||
except ImportError:
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def my_print(o):
|
||||
if isinstance(o, dict):
|
||||
print('sorted dict', sorted(o.items()))
|
||||
else:
|
||||
print(o)
|
||||
|
||||
my_print(json.loads('null'))
|
||||
my_print(json.loads('false'))
|
||||
my_print(json.loads('true'))
|
||||
my_print(json.loads('1'))
|
||||
my_print(json.loads('-2'))
|
||||
my_print(json.loads('"abc\\u0064e"'))
|
||||
my_print(json.loads('[]'))
|
||||
my_print(json.loads('[null]'))
|
||||
my_print(json.loads('[null,false,true]'))
|
||||
my_print(json.loads(' [ null , false , true ] '))
|
||||
my_print(json.loads('{}'))
|
||||
my_print(json.loads('{"a":true}'))
|
||||
my_print(json.loads('{"a":null, "b":false, "c":true}'))
|
||||
my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}'))
|
||||
my_print(json.loads('"abc\\bdef"'))
|
||||
my_print(json.loads('"abc\\fdef"'))
|
||||
my_print(json.loads('"abc\\ndef"'))
|
||||
my_print(json.loads('"abc\\rdef"'))
|
||||
my_print(json.loads('"abc\\tdef"'))
|
||||
my_print(json.loads('"abc\\uabcd"'))
|
||||
|
||||
# whitespace handling
|
||||
my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}'))
|
||||
|
||||
# loading nothing should raise exception
|
||||
try:
|
||||
json.loads('')
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# string which is not closed
|
||||
try:
|
||||
my_print(json.loads('"abc'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# unaccompanied closing brace
|
||||
try:
|
||||
my_print(json.loads(']'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# unspecified object type
|
||||
try:
|
||||
my_print(json.loads('a'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# bad property name
|
||||
try:
|
||||
my_print(json.loads('{{}:"abc"}'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
|
||||
# unexpected characters after white space
|
||||
try:
|
||||
my_print(json.loads('[null] a'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
@ -1,17 +0,0 @@
|
||||
try:
|
||||
import ujson as json
|
||||
except ImportError:
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def my_print(o):
|
||||
print('%.3f' % o)
|
||||
|
||||
my_print(json.loads('1.2'))
|
||||
my_print(json.loads('1e2'))
|
||||
my_print(json.loads('-2.3'))
|
||||
my_print(json.loads('-2e3'))
|
||||
my_print(json.loads('-2e-3'))
|
@ -1,29 +0,0 @@
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
try:
|
||||
import random
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# check getrandbits returns a value within the bit range
|
||||
for b in (1, 2, 3, 4, 16, 32):
|
||||
for i in range(50):
|
||||
assert random.getrandbits(b) < (1 << b)
|
||||
|
||||
# check that seed(0) gives a non-zero value
|
||||
random.seed(0)
|
||||
print(random.getrandbits(16) != 0)
|
||||
|
||||
# check that PRNG is repeatable
|
||||
random.seed(1)
|
||||
r = random.getrandbits(16)
|
||||
random.seed(1)
|
||||
print(random.getrandbits(16) == r)
|
||||
|
||||
# check that it throws an error for zero bits
|
||||
try:
|
||||
random.getrandbits(0)
|
||||
except ValueError:
|
||||
print('ValueError')
|
@ -1,103 +0,0 @@
|
||||
try:
|
||||
import ure as re
|
||||
except ImportError:
|
||||
try:
|
||||
import re
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
r = re.compile(".+")
|
||||
m = r.match("abc")
|
||||
print(m.group(0))
|
||||
try:
|
||||
m.group(1)
|
||||
except IndexError:
|
||||
print("IndexError")
|
||||
|
||||
# conversion of re and match to string
|
||||
str(r)
|
||||
str(m)
|
||||
|
||||
r = re.compile("(.+)1")
|
||||
m = r.match("xyz781")
|
||||
print(m.group(0))
|
||||
print(m.group(1))
|
||||
try:
|
||||
m.group(2)
|
||||
except IndexError:
|
||||
print("IndexError")
|
||||
|
||||
r = re.compile(r"\n")
|
||||
m = r.match("\n")
|
||||
print(m.group(0))
|
||||
m = r.match("\\")
|
||||
print(m)
|
||||
r = re.compile(r"[\n-\r]")
|
||||
m = r.match("\n")
|
||||
print(m.group(0))
|
||||
r = re.compile(r"[\]]")
|
||||
m = r.match("]")
|
||||
print(m.group(0))
|
||||
print("===")
|
||||
|
||||
r = re.compile("[a-cu-z]")
|
||||
m = r.match("a")
|
||||
print(m.group(0))
|
||||
m = r.match("z")
|
||||
print(m.group(0))
|
||||
m = r.match("d")
|
||||
print(m)
|
||||
m = r.match("A")
|
||||
print(m)
|
||||
print("===")
|
||||
|
||||
r = re.compile("[^a-cu-z]")
|
||||
m = r.match("a")
|
||||
print(m)
|
||||
m = r.match("z")
|
||||
print(m)
|
||||
m = r.match("d")
|
||||
print(m.group(0))
|
||||
m = r.match("A")
|
||||
print(m.group(0))
|
||||
print("===")
|
||||
|
||||
# '-' character within character class block
|
||||
print(re.match("[-a]+", "-a]d").group(0))
|
||||
print(re.match("[a-]+", "-a]d").group(0))
|
||||
print("===")
|
||||
|
||||
r = re.compile("o+")
|
||||
m = r.search("foobar")
|
||||
print(m.group(0))
|
||||
try:
|
||||
m.group(1)
|
||||
except IndexError:
|
||||
print("IndexError")
|
||||
|
||||
|
||||
m = re.match(".*", "foo")
|
||||
print(m.group(0))
|
||||
|
||||
m = re.search("w.r", "hello world")
|
||||
print(m.group(0))
|
||||
|
||||
m = re.match('a+?', 'ab'); print(m.group(0))
|
||||
m = re.match('a*?', 'ab'); print(m.group(0))
|
||||
m = re.match('^ab$', 'ab'); print(m.group(0))
|
||||
m = re.match('a|b', 'b'); print(m.group(0))
|
||||
m = re.match('a|b|c', 'c'); print(m.group(0))
|
||||
|
||||
# Case where anchors fail to match
|
||||
r = re.compile("^b|b$")
|
||||
m = r.search("abc")
|
||||
print(m)
|
||||
|
||||
try:
|
||||
re.compile("*")
|
||||
except:
|
||||
print("Caught invalid regex")
|
||||
|
||||
# bytes objects
|
||||
m = re.match(rb'a+?', b'ab'); print(m.group(0))
|
@ -1,15 +0,0 @@
|
||||
0: rsplit 5 (3)
|
||||
2: any
|
||||
3: jmp 0 (-5)
|
||||
5: save 0
|
||||
7: split 14 (5)
|
||||
9: assert bol
|
||||
10: char a
|
||||
12: jmp 23 (9)
|
||||
14: char b
|
||||
16: class 1 0x30-0x39
|
||||
20: namedclass w
|
||||
22: assert eol
|
||||
23: save 1
|
||||
25: match
|
||||
Bytes: 26, insts: 14
|
@ -1,25 +0,0 @@
|
||||
# test errors in regex
|
||||
|
||||
try:
|
||||
import ure as re
|
||||
except ImportError:
|
||||
try:
|
||||
import re
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def test_re(r):
|
||||
try:
|
||||
re.compile(r)
|
||||
print("OK")
|
||||
except: # uPy and CPy use different errors, so just ignore the type
|
||||
print("Error")
|
||||
|
||||
test_re(r'?')
|
||||
test_re(r'*')
|
||||
test_re(r'+')
|
||||
test_re(r')')
|
||||
test_re(r'[')
|
||||
test_re(r'([')
|
||||
test_re(r'([)')
|
@ -1,32 +0,0 @@
|
||||
# test named char classes
|
||||
|
||||
try:
|
||||
import ure as re
|
||||
except ImportError:
|
||||
try:
|
||||
import re
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def print_groups(match):
|
||||
print('----')
|
||||
try:
|
||||
i = 0
|
||||
while True:
|
||||
print(m.group(i))
|
||||
i += 1
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
m = re.match(r'\w+','1234hello567 abc')
|
||||
print_groups(m)
|
||||
|
||||
m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc')
|
||||
print_groups(m)
|
||||
|
||||
m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc')
|
||||
print_groups(m)
|
||||
|
||||
m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567')
|
||||
print_groups(m)
|
@ -1 +0,0 @@
|
||||
RuntimeError
|
@ -1 +0,0 @@
|
||||
1-a2
|
@ -1,59 +0,0 @@
|
||||
# very basic test of ssl module, just to test the methods exist
|
||||
|
||||
try:
|
||||
import uio as io
|
||||
import ussl as ssl
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# create in client mode
|
||||
try:
|
||||
ss = ssl.wrap_socket(io.BytesIO())
|
||||
except OSError as er:
|
||||
print('wrap_socket:', repr(er))
|
||||
|
||||
# create in server mode (can use this object for further tests)
|
||||
socket = io.BytesIO()
|
||||
ss = ssl.wrap_socket(socket, server_side=1)
|
||||
|
||||
# print
|
||||
print(repr(ss)[:12])
|
||||
|
||||
# setblocking
|
||||
try:
|
||||
ss.setblocking(False)
|
||||
except NotImplementedError:
|
||||
print('setblocking: NotImplementedError')
|
||||
ss.setblocking(True)
|
||||
|
||||
# write
|
||||
print(ss.write(b'aaaa'))
|
||||
|
||||
# read (underlying socket has no data)
|
||||
print(ss.read(8))
|
||||
|
||||
# read (underlying socket has data, but it's bad data)
|
||||
socket.write(b'aaaaaaaaaaaaaaaa')
|
||||
socket.seek(0)
|
||||
try:
|
||||
ss.read(8)
|
||||
except OSError as er:
|
||||
print('read:', repr(er))
|
||||
|
||||
# close
|
||||
ss.close()
|
||||
# close 2nd time
|
||||
ss.close()
|
||||
|
||||
# read on closed socket
|
||||
try:
|
||||
ss.read(10)
|
||||
except OSError as er:
|
||||
print('read:', repr(er))
|
||||
|
||||
# write on closed socket
|
||||
try:
|
||||
ss.write(b'aaaa')
|
||||
except OSError as er:
|
||||
print('write:', repr(er))
|
@ -1,137 +0,0 @@
|
||||
# Test for utimeq module which implements task queue with support for
|
||||
# wraparound time (utime.ticks_ms() style).
|
||||
try:
|
||||
from utime import ticks_add, ticks_diff
|
||||
from utimeq import utimeq
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
DEBUG = 0
|
||||
|
||||
MAX = ticks_add(0, -1)
|
||||
MODULO_HALF = MAX // 2 + 1
|
||||
|
||||
if DEBUG:
|
||||
def dprint(*v):
|
||||
print(*v)
|
||||
else:
|
||||
def dprint(*v):
|
||||
pass
|
||||
|
||||
# Try not to crash on invalid data
|
||||
h = utimeq(10)
|
||||
try:
|
||||
h.push(1)
|
||||
assert False
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
h.pop(1)
|
||||
assert False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# unsupported unary op
|
||||
try:
|
||||
~h
|
||||
assert False
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
# pushing on full queue
|
||||
h = utimeq(1)
|
||||
h.push(1, 0, 0)
|
||||
try:
|
||||
h.push(2, 0, 0)
|
||||
assert False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# popping into invalid type
|
||||
try:
|
||||
h.pop([])
|
||||
assert False
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
# length
|
||||
assert len(h) == 1
|
||||
|
||||
# peektime
|
||||
assert h.peektime() == 1
|
||||
|
||||
# peektime with empty queue
|
||||
try:
|
||||
utimeq(1).peektime()
|
||||
assert False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
def pop_all(h):
|
||||
l = []
|
||||
while h:
|
||||
item = [0, 0, 0]
|
||||
h.pop(item)
|
||||
#print("!", item)
|
||||
l.append(tuple(item))
|
||||
dprint(l)
|
||||
return l
|
||||
|
||||
def add(h, v):
|
||||
h.push(v, 0, 0)
|
||||
dprint("-----")
|
||||
#h.dump()
|
||||
dprint("-----")
|
||||
|
||||
h = utimeq(10)
|
||||
add(h, 0)
|
||||
add(h, MAX)
|
||||
add(h, MAX - 1)
|
||||
add(h, 101)
|
||||
add(h, 100)
|
||||
add(h, MAX - 2)
|
||||
dprint(h)
|
||||
l = pop_all(h)
|
||||
for i in range(len(l) - 1):
|
||||
diff = ticks_diff(l[i + 1][0], l[i][0])
|
||||
assert diff > 0
|
||||
|
||||
def edge_case(edge, offset):
|
||||
h = utimeq(10)
|
||||
add(h, ticks_add(0, offset))
|
||||
add(h, ticks_add(edge, offset))
|
||||
dprint(h)
|
||||
l = pop_all(h)
|
||||
diff = ticks_diff(l[1][0], l[0][0])
|
||||
dprint(diff, diff > 0)
|
||||
return diff
|
||||
|
||||
dprint("===")
|
||||
diff = edge_case(MODULO_HALF - 1, 0)
|
||||
assert diff == MODULO_HALF - 1
|
||||
assert edge_case(MODULO_HALF - 1, 100) == diff
|
||||
assert edge_case(MODULO_HALF - 1, -100) == diff
|
||||
|
||||
# We expect diff to be always positive, per the definition of heappop() which should return
|
||||
# the smallest value.
|
||||
# This is the edge case where this invariant breaks, due to assymetry of two's-complement
|
||||
# range - there's one more negative integer than positive, so heappushing values like below
|
||||
# will then make ticks_diff() return the minimum negative value. We could make heappop
|
||||
# return them in a different order, but ticks_diff() result would be the same. Conclusion:
|
||||
# never add to a heap values where (a - b) == MODULO_HALF (and which are >= MODULO_HALF
|
||||
# ticks apart in real time of course).
|
||||
dprint("===")
|
||||
diff = edge_case(MODULO_HALF, 0)
|
||||
assert diff == -MODULO_HALF
|
||||
assert edge_case(MODULO_HALF, 100) == diff
|
||||
assert edge_case(MODULO_HALF, -100) == diff
|
||||
|
||||
dprint("===")
|
||||
diff = edge_case(MODULO_HALF + 1, 0)
|
||||
assert diff == MODULO_HALF - 1
|
||||
assert edge_case(MODULO_HALF + 1, 100) == diff
|
||||
assert edge_case(MODULO_HALF + 1, -100) == diff
|
||||
|
||||
print("OK")
|
@ -1 +0,0 @@
|
||||
OK
|
@ -1,33 +0,0 @@
|
||||
try:
|
||||
import uzlib as zlib
|
||||
import uio as io
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
# Raw DEFLATE bitstream
|
||||
buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00')
|
||||
inp = zlib.DecompIO(buf, -8)
|
||||
print(buf.seek(0, 1))
|
||||
print(inp.read(1))
|
||||
print(buf.seek(0, 1))
|
||||
print(inp.read(2))
|
||||
print(inp.read())
|
||||
print(buf.seek(0, 1))
|
||||
print(inp.read(1))
|
||||
print(inp.read())
|
||||
print(buf.seek(0, 1))
|
||||
|
||||
|
||||
# zlib bitstream
|
||||
inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'))
|
||||
print(inp.read(10))
|
||||
print(inp.read())
|
||||
|
||||
# zlib bitstream, wrong checksum
|
||||
inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0'))
|
||||
try:
|
||||
print(inp.read())
|
||||
except OSError as e:
|
||||
print(repr(e))
|
@ -1,13 +0,0 @@
|
||||
16
|
||||
b'h'
|
||||
18
|
||||
b'el'
|
||||
b'lo'
|
||||
31
|
||||
b''
|
||||
b''
|
||||
31
|
||||
b'hello'
|
||||
b'hello'
|
||||
ValueError
|
||||
OSError(22,)
|
@ -1,139 +0,0 @@
|
||||
try:
|
||||
import uerrno
|
||||
import uos
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
try:
|
||||
uos.VfsFat
|
||||
except AttributeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
class RAMFS:
|
||||
|
||||
SEC_SIZE = 512
|
||||
|
||||
def __init__(self, blocks):
|
||||
self.data = bytearray(blocks * self.SEC_SIZE)
|
||||
|
||||
def readblocks(self, n, buf):
|
||||
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
||||
for i in range(len(buf)):
|
||||
buf[i] = self.data[n * self.SEC_SIZE + i]
|
||||
return 0
|
||||
|
||||
def writeblocks(self, n, buf):
|
||||
#print("writeblocks(%s, %x)" % (n, id(buf)))
|
||||
for i in range(len(buf)):
|
||||
self.data[n * self.SEC_SIZE + i] = buf[i]
|
||||
return 0
|
||||
|
||||
def ioctl(self, op, arg):
|
||||
#print("ioctl(%d, %r)" % (op, arg))
|
||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
||||
return len(self.data) // self.SEC_SIZE
|
||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
||||
return self.SEC_SIZE
|
||||
|
||||
|
||||
try:
|
||||
bdev = RAMFS(50)
|
||||
except MemoryError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/ramdisk')
|
||||
uos.chdir('/ramdisk')
|
||||
|
||||
# file IO
|
||||
f = open("foo_file.txt", "w")
|
||||
print(str(f)[:17], str(f)[-1:])
|
||||
f.write("hello!")
|
||||
f.flush()
|
||||
f.close()
|
||||
f.close() # allowed
|
||||
try:
|
||||
f.write("world!")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.read()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.flush()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
open("foo_file.txt", "x")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EEXIST)
|
||||
|
||||
with open("foo_file.txt", "a") as f:
|
||||
f.write("world!")
|
||||
|
||||
with open("foo_file.txt") as f2:
|
||||
print(f2.read())
|
||||
print(f2.tell())
|
||||
|
||||
f2.seek(0, 0) # SEEK_SET
|
||||
print(f2.read(1))
|
||||
|
||||
f2.seek(0, 1) # SEEK_CUR
|
||||
print(f2.read(1))
|
||||
f2.seek(2, 1) # SEEK_CUR
|
||||
print(f2.read(1))
|
||||
|
||||
f2.seek(-2, 2) # SEEK_END
|
||||
print(f2.read(1))
|
||||
|
||||
# using constructor of FileIO type to open a file
|
||||
# no longer working with new VFS sub-system
|
||||
#FileIO = type(f)
|
||||
#with FileIO("/ramdisk/foo_file.txt") as f:
|
||||
# print(f.read())
|
||||
|
||||
# dirs
|
||||
vfs.mkdir("foo_dir")
|
||||
|
||||
try:
|
||||
vfs.rmdir("foo_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == 20) # uerrno.ENOTDIR
|
||||
|
||||
vfs.remove("foo_file.txt")
|
||||
print(list(vfs.ilistdir()))
|
||||
|
||||
# Here we test that opening a file with the heap locked fails correctly. This
|
||||
# is a special case because file objects use a finaliser and allocating with a
|
||||
# finaliser is a different path to normal allocation. It would be better to
|
||||
# test this in the core tests but there are no core objects that use finaliser.
|
||||
import micropython
|
||||
micropython.heap_lock()
|
||||
try:
|
||||
vfs.open('x', 'r')
|
||||
except MemoryError:
|
||||
print('MemoryError')
|
||||
micropython.heap_unlock()
|
||||
|
||||
# Here we test that the finaliser is actually called during a garbage collection.
|
||||
import gc
|
||||
N = 4
|
||||
for i in range(N):
|
||||
n = 'x%d' % i
|
||||
f = vfs.open(n, 'w')
|
||||
f.write(n)
|
||||
f = None # release f without closing
|
||||
[0, 1, 2, 3] # use up Python stack so f is really gone
|
||||
gc.collect() # should finalise all N files by closing them
|
||||
for i in range(N):
|
||||
with vfs.open('x%d' % i, 'r') as f:
|
||||
print(f.read())
|
@ -1,18 +0,0 @@
|
||||
<io.TextIOWrapper >
|
||||
True
|
||||
True
|
||||
True
|
||||
True
|
||||
hello!world!
|
||||
12
|
||||
h
|
||||
e
|
||||
o
|
||||
d
|
||||
True
|
||||
[('foo_dir', 16384, 0, 0)]
|
||||
MemoryError
|
||||
x0
|
||||
x1
|
||||
x2
|
||||
x3
|
@ -1,29 +0,0 @@
|
||||
/
|
||||
['test.txt']
|
||||
['test.txt']
|
||||
(16384, 0, 0, 0, 0, 0, 0)
|
||||
(16384, 0, 0, 0, 0, 0, 0)
|
||||
(32768, 0, 0, 0, 0, 0, 5)
|
||||
(32768, 0, 0, 0, 0, 0, 5)
|
||||
hello
|
||||
['test2.txt']
|
||||
['test3.txt']
|
||||
['test4.txt']
|
||||
['test5.txt']
|
||||
['test5.txt', 'dir']
|
||||
['test5.txt', 'dir', 'dir2']
|
||||
['subdir']
|
||||
mkdir OSError True
|
||||
mkdir OSError True
|
||||
mkdir OSError True
|
||||
mkdir OSError True
|
||||
mkdir OSError True
|
||||
(32768, 0, 0, 0, 0, 0, 5)
|
||||
['sys', 'test5.txt', 'dir', 'dir2']
|
||||
[]
|
||||
[]
|
||||
['sys', 'dir']
|
||||
/
|
||||
['sys']
|
||||
[]
|
||||
test_module!
|
@ -1,3 +0,0 @@
|
||||
[('file.txt', 32768, 0, 6)]
|
||||
hello!
|
||||
[]
|
@ -1,17 +0,0 @@
|
||||
True
|
||||
True
|
||||
label: LABEL TEST
|
||||
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
|
||||
getcwd: /
|
||||
True
|
||||
[('foo_file.txt', 32768, 0, 6)]
|
||||
stat root: (16384, 0, 0, 0, 0, 0, 0, 946684800, 946684800, 946684800)
|
||||
stat file: (32768, 0, 0, 0, 0, 0, 6)
|
||||
True
|
||||
True
|
||||
getcwd: /foo_dir
|
||||
[]
|
||||
True
|
||||
getcwd: /
|
||||
[(b'foo_file.txt', 32768, 0, 6), (b'foo_dir', 16384, 0, 0)]
|
||||
ENOENT: True
|
@ -1,14 +0,0 @@
|
||||
b'ping'
|
||||
b'ping'
|
||||
b'\x81\x04pong'
|
||||
b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping'
|
||||
b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong'
|
||||
b'\x00\x00\x00\x00'
|
||||
b''
|
||||
b'\x81\x02\x88\x00'
|
||||
b'ping'
|
||||
b'pong'
|
||||
0
|
||||
1
|
||||
2
|
||||
ioctl: EINVAL: True
|
@ -1,4 +0,0 @@
|
||||
This directory doesn't contain real tests, but code snippets to detect
|
||||
various interpreter features, which can't be/inconvenient to detecte by
|
||||
other means. Scripts here are executed by run-tests at the beginning of
|
||||
testsuite to decide what other test groups to run/exclude.
|
@ -1,3 +0,0 @@
|
||||
# check if async/await keywords are supported
|
||||
async def foo():
|
||||
await 1
|
@ -1,2 +0,0 @@
|
||||
import sys
|
||||
print(sys.byteorder)
|
@ -1,5 +0,0 @@
|
||||
try:
|
||||
complex
|
||||
print("complex")
|
||||
except NameError:
|
||||
print("no")
|
@ -1 +0,0 @@
|
||||
x = const(1)
|
@ -1,5 +0,0 @@
|
||||
try:
|
||||
extra_coverage
|
||||
print('coverage')
|
||||
except NameError:
|
||||
print('no')
|
@ -1,13 +0,0 @@
|
||||
# detect how many bits of precision the floating point implementation has
|
||||
|
||||
try:
|
||||
float
|
||||
except NameError:
|
||||
print(0)
|
||||
else:
|
||||
if float('1.0000001') == float('1.0'):
|
||||
print(30)
|
||||
elif float('1e300') == float('inf'):
|
||||
print(32)
|
||||
else:
|
||||
print(64)
|
@ -1 +0,0 @@
|
||||
64
|
@ -1,2 +0,0 @@
|
||||
# Check whether arbitrary-precision integers (MPZ) are supported
|
||||
print(1000000000000000000000000000000000000000000000)
|
@ -1 +0,0 @@
|
||||
1000000000000000000000000000000000000000000000
|
@ -1,4 +0,0 @@
|
||||
# this test for the availability of native emitter
|
||||
@micropython.native
|
||||
def f():
|
||||
pass
|
@ -1,3 +0,0 @@
|
||||
# Check for emacs keys in REPL
|
||||
t = +11
|
||||
t == 2
|
@ -1,7 +0,0 @@
|
||||
MicroPython \.\+ version
|
||||
Use \.\+
|
||||
>>> # Check for emacs keys in REPL
|
||||
>>> t = \.\+
|
||||
>>> t == 2
|
||||
True
|
||||
>>>
|
@ -1,9 +0,0 @@
|
||||
class Foo:
|
||||
|
||||
def __radd__(self, other):
|
||||
pass
|
||||
|
||||
try:
|
||||
5 + Foo()
|
||||
except TypeError:
|
||||
print("TypeError")
|
@ -1,2 +0,0 @@
|
||||
# check if set literal syntax is supported
|
||||
{1}
|
@ -1,10 +0,0 @@
|
||||
# test construction of array from array with float type
|
||||
|
||||
try:
|
||||
from array import array
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(array('f', array('h', [1, 2])))
|
||||
print(array('d', array('f', [1, 2])))
|
@ -1,25 +0,0 @@
|
||||
# test builtin hash function with float args
|
||||
|
||||
# these should hash to an integer with a specific value
|
||||
for val in (
|
||||
'0.0',
|
||||
'-0.0',
|
||||
'1.0',
|
||||
'2.0',
|
||||
'-12.0',
|
||||
'12345.0',
|
||||
):
|
||||
print(val, hash(float(val)))
|
||||
|
||||
# just check that these values are hashable
|
||||
for val in (
|
||||
'0.1',
|
||||
'-0.1',
|
||||
'10.3',
|
||||
'0.4e3',
|
||||
'1e16',
|
||||
'inf',
|
||||
'-inf',
|
||||
'nan',
|
||||
):
|
||||
print(val, type(hash(float(val))))
|
@ -1,31 +0,0 @@
|
||||
# test builtin min and max functions with float args
|
||||
try:
|
||||
min
|
||||
max
|
||||
except:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(min(0, 1.0))
|
||||
print(min(1.0, 0))
|
||||
print(min(0, -1.0))
|
||||
print(min(-1.0, 0))
|
||||
|
||||
print(max(0, 1.0))
|
||||
print(max(1.0, 0))
|
||||
print(max(0, -1.0))
|
||||
print(max(-1.0, 0))
|
||||
|
||||
print(min(1.5, -1.5))
|
||||
print(min(-1.5, 1.5))
|
||||
|
||||
print(max(1.5, -1.5))
|
||||
print(max(-1.5, 1.5))
|
||||
|
||||
print(min([1, 2.9, 4, 0, -1, 2]))
|
||||
print(max([1, 2.9, 4, 0, -1, 2]))
|
||||
|
||||
print(min([1, 2.9, 4, 6.5, -1, 2]))
|
||||
print(max([1, 2.9, 4, 6.5, -1, 2]))
|
||||
print(min([1, 2.9, 4, -6.5, -1, 2]))
|
||||
print(max([1, 2.9, 4, -6.5, -1, 2]))
|
@ -1,11 +0,0 @@
|
||||
# test builtin pow function with float args
|
||||
|
||||
print(pow(0.0, 0.0))
|
||||
print(pow(0, 1.0))
|
||||
print(pow(1.0, 1))
|
||||
print(pow(2.0, 3.0))
|
||||
print(pow(2.0, -4.0))
|
||||
|
||||
print(pow(0.0, float('inf')))
|
||||
print(pow(0.0, float('-inf')))
|
||||
print(pow(0.0, float('nan')))
|
@ -1,24 +0,0 @@
|
||||
# test round() with floats
|
||||
|
||||
# check basic cases
|
||||
tests = [
|
||||
[0.0], [1.0], [0.1], [-0.1], [123.4], [123.6], [-123.4], [-123.6],
|
||||
[1.234567, 5], [1.23456, 1], [1.23456, 0], [1234.56, -2]
|
||||
]
|
||||
for t in tests:
|
||||
print(round(*t))
|
||||
|
||||
# check .5 cases
|
||||
for i in range(11):
|
||||
print(round((i - 5) / 2))
|
||||
|
||||
# test second arg
|
||||
for i in range(-1, 3):
|
||||
print(round(1.47, i))
|
||||
|
||||
# test inf and nan
|
||||
for val in (float('inf'), float('nan')):
|
||||
try:
|
||||
round(val)
|
||||
except (ValueError, OverflowError) as e:
|
||||
print(type(e))
|
@ -1,4 +0,0 @@
|
||||
# test round() with floats that return large integers
|
||||
|
||||
for x in (-1e25, 1e25):
|
||||
print('%.3g' % round(x))
|
@ -1,9 +0,0 @@
|
||||
# test construction of bytearray from array with float type
|
||||
|
||||
try:
|
||||
from array import array
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(bytearray(array('f', [1, 2.3])))
|
@ -1,9 +0,0 @@
|
||||
# test construction of bytearray from array with float type
|
||||
|
||||
try:
|
||||
from array import array
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(bytes(array('f', [1, 2.3])))
|
@ -1,55 +0,0 @@
|
||||
# test the functions imported from cmath
|
||||
|
||||
try:
|
||||
from cmath import *
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# make sure these constants exist in cmath
|
||||
print("%.5g" % e)
|
||||
print("%.5g" % pi)
|
||||
|
||||
test_values_non_zero = []
|
||||
base_values = (0.0, 0.5, 1.2345, 10.)
|
||||
for r in base_values:
|
||||
for i in base_values:
|
||||
if r != 0. or i != 0.:
|
||||
test_values_non_zero.append(complex(r, i))
|
||||
if r != 0.:
|
||||
test_values_non_zero.append(complex(-r, i))
|
||||
if i != 0.:
|
||||
test_values_non_zero.append(complex(r, -i))
|
||||
if r != 0. and i != 0.:
|
||||
test_values_non_zero.append(complex(-r, -i))
|
||||
test_values = [complex(0., 0.),] + test_values_non_zero
|
||||
print(test_values)
|
||||
|
||||
functions = [
|
||||
('phase', phase, test_values),
|
||||
('polar', polar, test_values),
|
||||
('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))),
|
||||
('exp', exp, test_values),
|
||||
('log', log, test_values_non_zero),
|
||||
('sqrt', sqrt, test_values),
|
||||
('cos', cos, test_values),
|
||||
('sin', sin, test_values),
|
||||
]
|
||||
|
||||
for f_name, f, test_vals in functions:
|
||||
print(f_name)
|
||||
for val in test_vals:
|
||||
if type(val) == tuple:
|
||||
ret = f(*val)
|
||||
else:
|
||||
ret = f(val)
|
||||
if type(ret) == float:
|
||||
print("%.5g" % ret)
|
||||
elif type(ret) == tuple:
|
||||
print("%.5g %.5g" % ret)
|
||||
else:
|
||||
# some test (eg cmath.sqrt(-0.5)) disagree with CPython with tiny real part
|
||||
real = ret.real
|
||||
if abs(real) < 1e15:
|
||||
real = 0.
|
||||
print("complex(%.5g, %.5g)" % (real, ret.imag))
|
@ -1,31 +0,0 @@
|
||||
# test the special functions imported from cmath
|
||||
|
||||
try:
|
||||
from cmath import *
|
||||
log10
|
||||
except (ImportError, NameError):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
test_values_non_zero = []
|
||||
base_values = (0.0, 0.5, 1.2345, 10.)
|
||||
for r in base_values:
|
||||
for i in base_values:
|
||||
if r != 0. or i != 0.:
|
||||
test_values_non_zero.append(complex(r, i))
|
||||
if r != 0.:
|
||||
test_values_non_zero.append(complex(-r, i))
|
||||
if i != 0.:
|
||||
test_values_non_zero.append(complex(r, -i))
|
||||
if r != 0. and i != 0.:
|
||||
test_values_non_zero.append(complex(-r, -i))
|
||||
|
||||
functions = [
|
||||
('log10', log10, test_values_non_zero),
|
||||
]
|
||||
|
||||
for f_name, f, test_vals in functions:
|
||||
print(f_name)
|
||||
for val in test_vals:
|
||||
ret = f(val)
|
||||
print("complex(%.5g, %.5g)" % (ret.real, ret.imag))
|
@ -1,116 +0,0 @@
|
||||
# test basic complex number functionality
|
||||
|
||||
# constructor
|
||||
print(complex(1))
|
||||
print(complex(1.2))
|
||||
print(complex(1.2j))
|
||||
print(complex("1"))
|
||||
print(complex("1.2"))
|
||||
print(complex("1.2j"))
|
||||
print(complex(1, 2))
|
||||
print(complex(1j, 2j))
|
||||
|
||||
# unary ops
|
||||
print(bool(1j))
|
||||
print(+(1j))
|
||||
print(-(1 + 2j))
|
||||
|
||||
# binary ops
|
||||
print(1j + False)
|
||||
print(1j + True)
|
||||
print(1j + 2)
|
||||
print(1j + 2j)
|
||||
print(1j - 2)
|
||||
print(1j - 2j)
|
||||
print(1j * 2)
|
||||
print(1j * 2j)
|
||||
print(1j / 2)
|
||||
print((1j / 2j).real)
|
||||
print(1j / (1 + 2j))
|
||||
ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
|
||||
# comparison
|
||||
print(1j == 1)
|
||||
print(1j == 1j)
|
||||
|
||||
# comparison of nan is special
|
||||
nan = float('nan') * 1j
|
||||
print(nan == 1j)
|
||||
print(nan == nan)
|
||||
|
||||
# builtin abs
|
||||
print(abs(1j))
|
||||
print("%.5g" % abs(1j + 2))
|
||||
|
||||
# builtin hash
|
||||
print(hash(1 + 0j))
|
||||
print(type(hash(1j)))
|
||||
|
||||
# float on lhs should delegate to complex
|
||||
print(1.2 + 3j)
|
||||
|
||||
# negative base and fractional power should create a complex
|
||||
ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
|
||||
# check printing of inf/nan
|
||||
print(float('nan') * 1j)
|
||||
print(float('-nan') * 1j)
|
||||
print(float('inf') * (1 + 1j))
|
||||
print(float('-inf') * (1 + 1j))
|
||||
|
||||
# can't assign to attributes
|
||||
try:
|
||||
(1j).imag = 0
|
||||
except AttributeError:
|
||||
print('AttributeError')
|
||||
|
||||
# can't convert rhs to complex
|
||||
try:
|
||||
1j + []
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# unsupported unary op
|
||||
try:
|
||||
~(1j)
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# unsupported binary op
|
||||
try:
|
||||
1j // 2
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# unsupported binary op
|
||||
try:
|
||||
1j < 2j
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
#small int on LHS, complex on RHS, unsupported op
|
||||
try:
|
||||
print(1 | 1j)
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# zero division
|
||||
try:
|
||||
1j / 0
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
||||
|
||||
# zero division via power
|
||||
try:
|
||||
0j ** -1
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
||||
try:
|
||||
0j ** 1j
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
@ -1,4 +0,0 @@
|
||||
# test basic complex number functionality
|
||||
|
||||
# convert bignum to complex on rhs
|
||||
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))
|
@ -1,119 +0,0 @@
|
||||
# test basic float capabilities
|
||||
|
||||
# literals
|
||||
print(.12)
|
||||
print(1.)
|
||||
print(1.2)
|
||||
print(0e0)
|
||||
print(0e+0)
|
||||
print(0e-0)
|
||||
|
||||
# float construction
|
||||
print(float(1.2))
|
||||
print(float("1.2"))
|
||||
print(float("+1"))
|
||||
print(float("1e1"))
|
||||
print(float("1e+1"))
|
||||
print(float("1e-1"))
|
||||
print(float("inf"))
|
||||
print(float("-inf"))
|
||||
print(float("INF"))
|
||||
print(float("infinity"))
|
||||
print(float("INFINITY"))
|
||||
print(float("nan"))
|
||||
print(float("-nan"))
|
||||
print(float("NaN"))
|
||||
try:
|
||||
float("")
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
float("1e+")
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
float("1z")
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
|
||||
# construct from something with the buffer protocol
|
||||
print(float(b"1.2"))
|
||||
print(float(bytearray(b"3.4")))
|
||||
|
||||
# unary operators
|
||||
print(bool(0.0))
|
||||
print(bool(1.2))
|
||||
print(+(1.2))
|
||||
print(-(1.2))
|
||||
|
||||
# division of integers
|
||||
x = 1 / 2
|
||||
print(x)
|
||||
|
||||
# /= operator
|
||||
a = 1
|
||||
a /= 2
|
||||
print(a)
|
||||
|
||||
# floor division
|
||||
print(1.0 // 2)
|
||||
print(2.0 // 2)
|
||||
|
||||
# comparison
|
||||
print(1.2 <= 3.4)
|
||||
print(1.2 <= -3.4)
|
||||
print(1.2 >= 3.4)
|
||||
print(1.2 >= -3.4)
|
||||
|
||||
# comparison of nan is special
|
||||
nan = float('nan')
|
||||
print(nan == 1.2)
|
||||
print(nan == nan)
|
||||
|
||||
try:
|
||||
1.0 / 0
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
||||
|
||||
try:
|
||||
1.0 // 0
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
||||
|
||||
try:
|
||||
1.2 % 0
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
||||
|
||||
try:
|
||||
0.0 ** -1
|
||||
except ZeroDivisionError:
|
||||
print("ZeroDivisionError")
|
||||
|
||||
# unsupported unary ops
|
||||
|
||||
try:
|
||||
~1.2
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
try:
|
||||
1.2 in 3.4
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# small int on LHS, float on RHS, unsupported op
|
||||
try:
|
||||
print(1 | 1.0)
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# can't convert list to float
|
||||
try:
|
||||
float([])
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# test constant float with more than 255 chars
|
||||
x = 1.84728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189
|
||||
print("%.5f" % x)
|
@ -1,100 +0,0 @@
|
||||
# check cases converting float to int, requiring double precision float
|
||||
|
||||
try:
|
||||
import ustruct as struct
|
||||
except:
|
||||
import struct
|
||||
|
||||
import sys
|
||||
maxsize_bits = 0
|
||||
maxsize = sys.maxsize
|
||||
while maxsize:
|
||||
maxsize >>= 1
|
||||
maxsize_bits += 1
|
||||
|
||||
# work out configuration values
|
||||
is_64bit = maxsize_bits > 32
|
||||
# 0 = none, 1 = long long, 2 = mpz
|
||||
ll_type = None
|
||||
if is_64bit:
|
||||
if maxsize_bits < 63:
|
||||
ll_type = 0
|
||||
else:
|
||||
if maxsize_bits < 31:
|
||||
ll_type = 0
|
||||
if ll_type is None:
|
||||
one = 1
|
||||
if one << 65 < one << 62:
|
||||
ll_type = 1
|
||||
else:
|
||||
ll_type = 2
|
||||
|
||||
# This case occurs with time.time() values
|
||||
if ll_type != 0:
|
||||
print(int(1418774543.))
|
||||
print("%d" % 1418774543.)
|
||||
if ll_type == 3:
|
||||
print(int(2.**100))
|
||||
print("%d" % 2.**100)
|
||||
else:
|
||||
print(int(1073741823.))
|
||||
print("%d" % 1073741823.)
|
||||
|
||||
testpass = True
|
||||
p2_rng = ((30,63,1024),(62,63,1024))[is_64bit][ll_type]
|
||||
for i in range(0,p2_rng):
|
||||
bitcnt = len(bin(int(2.**i))) - 3;
|
||||
if i != bitcnt:
|
||||
print('fail: 2**%u was %u bits long' % (i, bitcnt));
|
||||
testpass = False
|
||||
print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
|
||||
|
||||
testpass = True
|
||||
p10_rng = ((9,18,23),(18,18,23))[is_64bit][ll_type]
|
||||
for i in range(0,p10_rng):
|
||||
digcnt = len(str(int(10.**i))) - 1;
|
||||
if i != digcnt:
|
||||
print('fail: 10**%u was %u digits long' % (i, digcnt));
|
||||
testpass = False
|
||||
print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
|
||||
|
||||
def fp2int_test(num, name, should_fail):
|
||||
try:
|
||||
x = int(num)
|
||||
passed = ~should_fail
|
||||
except:
|
||||
passed = should_fail
|
||||
print('%s: %s' % (name, passed and 'passed' or 'failed'))
|
||||
|
||||
if ll_type != 2:
|
||||
if ll_type == 0:
|
||||
if is_64bit:
|
||||
neg_bad_fp = -1.00000005*2.**62.
|
||||
pos_bad_fp = 2.**62.
|
||||
neg_good_fp = -2.**62.
|
||||
pos_good_fp = 0.99999993*2.**62.
|
||||
else:
|
||||
neg_bad_fp = -1.00000005*2.**30.
|
||||
pos_bad_fp = 2.**30.
|
||||
neg_good_fp = -2.**30.
|
||||
pos_good_fp = 0.9999999499*2.**30.
|
||||
else:
|
||||
neg_bad_fp = -0.51*2.**64.
|
||||
pos_bad_fp = 2.**63.
|
||||
neg_good_fp = -2.**63.
|
||||
pos_good_fp = 1.9999998*2.**62.
|
||||
|
||||
fp2int_test(neg_bad_fp, 'neg bad', True)
|
||||
fp2int_test(pos_bad_fp, 'pos bad', True)
|
||||
fp2int_test(neg_good_fp, 'neg good', False)
|
||||
fp2int_test(pos_good_fp, 'pos good', False)
|
||||
else:
|
||||
fp2int_test(-1.9999999999999981*2.**1023., 'large neg', False)
|
||||
fp2int_test(1.9999999999999981*2.**1023., 'large pos', False)
|
||||
|
||||
fp2int_test(float('inf'), 'inf test', True)
|
||||
fp2int_test(float('nan'), 'NaN test', True)
|
||||
|
||||
# test numbers < 1 (this used to fail; see issue #1044)
|
||||
fp2int_test(0.0001, 'small num', False)
|
||||
struct.pack('I', int(1/2))
|
@ -1,97 +0,0 @@
|
||||
# check cases converting float to int, relying only on single precision float
|
||||
|
||||
try:
|
||||
import ustruct as struct
|
||||
except:
|
||||
import struct
|
||||
|
||||
import sys
|
||||
maxsize_bits = 0
|
||||
maxsize = sys.maxsize
|
||||
while maxsize:
|
||||
maxsize >>= 1
|
||||
maxsize_bits += 1
|
||||
|
||||
# work out configuration values
|
||||
is_64bit = maxsize_bits > 32
|
||||
# 0 = none, 1 = long long, 2 = mpz
|
||||
ll_type = None
|
||||
if is_64bit:
|
||||
if maxsize_bits < 63:
|
||||
ll_type = 0
|
||||
else:
|
||||
if maxsize_bits < 31:
|
||||
ll_type = 0
|
||||
if ll_type is None:
|
||||
one = 1
|
||||
if one << 65 < one << 62:
|
||||
ll_type = 1
|
||||
else:
|
||||
ll_type = 2
|
||||
|
||||
# basic conversion
|
||||
print(int(14187744.))
|
||||
print("%d" % 14187744.)
|
||||
if ll_type == 2:
|
||||
print(int(2.**100))
|
||||
print("%d" % 2.**100)
|
||||
|
||||
testpass = True
|
||||
p2_rng = ((30,63,127),(62,63,127))[is_64bit][ll_type]
|
||||
for i in range(0,p2_rng):
|
||||
bitcnt = len(bin(int(2.**i))) - 3;
|
||||
if i != bitcnt:
|
||||
print('fail: 2.**%u was %u bits long' % (i, bitcnt));
|
||||
testpass = False
|
||||
print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
|
||||
|
||||
# TODO why does 10**12 fail this test for single precision float?
|
||||
testpass = True
|
||||
p10_rng = 9
|
||||
for i in range(0,p10_rng):
|
||||
digcnt = len(str(int(10.**i))) - 1;
|
||||
if i != digcnt:
|
||||
print('fail: 10.**%u was %u digits long' % (i, digcnt));
|
||||
testpass = False
|
||||
print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
|
||||
|
||||
def fp2int_test(num, name, should_fail):
|
||||
try:
|
||||
x = int(num)
|
||||
passed = ~should_fail
|
||||
except:
|
||||
passed = should_fail
|
||||
print('%s: %s' % (name, passed and 'passed' or 'failed'))
|
||||
|
||||
if ll_type != 2:
|
||||
if ll_type == 0:
|
||||
if is_64bit:
|
||||
neg_bad_fp = -1.00000005*2.**62.
|
||||
pos_bad_fp = 2.**62.
|
||||
neg_good_fp = -2.**62.
|
||||
pos_good_fp = 0.99999993*2.**62.
|
||||
else:
|
||||
neg_bad_fp = -1.00000005*2.**30.
|
||||
pos_bad_fp = 2.**30.
|
||||
neg_good_fp = -2.**30.
|
||||
pos_good_fp = 0.9999999499*2.**30.
|
||||
else:
|
||||
neg_bad_fp = -0.51*2.**64.
|
||||
pos_bad_fp = 2.**63.
|
||||
neg_good_fp = -2.**63.
|
||||
pos_good_fp = 1.9999998*2.**62.
|
||||
|
||||
fp2int_test(neg_bad_fp, 'neg bad', True)
|
||||
fp2int_test(pos_bad_fp, 'pos bad', True)
|
||||
fp2int_test(neg_good_fp, 'neg good', False)
|
||||
fp2int_test(pos_good_fp, 'pos good', False)
|
||||
else:
|
||||
fp2int_test(-1.999999879*2.**126., 'large neg', False)
|
||||
fp2int_test(1.999999879*2.**126., 'large pos', False)
|
||||
|
||||
fp2int_test(float('inf'), 'inf test', True)
|
||||
fp2int_test(float('nan'), 'NaN test', True)
|
||||
|
||||
# test numbers < 1 (this used to fail; see issue #1044)
|
||||
fp2int_test(0.0001, 'small num', False)
|
||||
struct.pack('I', int(1/2))
|
@ -1,99 +0,0 @@
|
||||
# check cases converting float to int, relying only on single precision float
|
||||
|
||||
try:
|
||||
import ustruct as struct
|
||||
except:
|
||||
import struct
|
||||
|
||||
import sys
|
||||
|
||||
maxsize_bits = 0
|
||||
maxsize = sys.maxsize
|
||||
while maxsize:
|
||||
maxsize >>= 1
|
||||
maxsize_bits += 1
|
||||
|
||||
# work out configuration values
|
||||
is_64bit = maxsize_bits > 32
|
||||
# 0 = none, 1 = long long, 2 = mpz
|
||||
ll_type = None
|
||||
if is_64bit:
|
||||
if maxsize_bits < 63:
|
||||
ll_type = 0
|
||||
else:
|
||||
if maxsize_bits < 31:
|
||||
ll_type = 0
|
||||
if ll_type is None:
|
||||
one = 1
|
||||
if one << 65 < one << 62:
|
||||
ll_type = 1
|
||||
else:
|
||||
ll_type = 2
|
||||
|
||||
|
||||
# basic conversion
|
||||
print(int(14187745.))
|
||||
print("%d" % 14187745.)
|
||||
if ll_type == 2:
|
||||
print(int(2.**100))
|
||||
print("%d" % 2.**100)
|
||||
|
||||
testpass = True
|
||||
p2_rng = ((30,63,127),(62,63,127))[is_64bit][ll_type]
|
||||
for i in range(0,p2_rng):
|
||||
bitcnt = len(bin(int(2.**i))) - 3;
|
||||
if i != bitcnt:
|
||||
print('fail: 2.**%u was %u bits long' % (i, bitcnt));
|
||||
testpass = False
|
||||
print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
|
||||
|
||||
# TODO why does 10**12 fail this test for single precision float?
|
||||
testpass = True
|
||||
p10_rng = 9 if (ll_type == 0 and ~is_64bit) else 11
|
||||
for i in range(0,p10_rng):
|
||||
digcnt = len(str(int(10.**i))) - 1;
|
||||
if i != digcnt:
|
||||
print('fail: 10.**%u was %u digits long' % (i, digcnt));
|
||||
testpass = False
|
||||
print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
|
||||
|
||||
def fp2int_test(num, name, should_fail):
|
||||
try:
|
||||
x = int(num)
|
||||
passed = ~should_fail
|
||||
except:
|
||||
passed = should_fail
|
||||
print('%s: %s' % (name, passed and 'passed' or 'failed'))
|
||||
|
||||
if ll_type != 2:
|
||||
if ll_type == 0:
|
||||
if is_64bit:
|
||||
neg_bad_fp = -1.00000005*2.**62.
|
||||
pos_bad_fp = 2.**62.
|
||||
neg_good_fp = -2.**62.
|
||||
pos_good_fp = 0.99999993*2.**62.
|
||||
else:
|
||||
neg_bad_fp = -1.00000005*2.**30.
|
||||
pos_bad_fp = 2.**30.
|
||||
neg_good_fp = -2.**30.
|
||||
pos_good_fp = 0.9999999499*2.**30.
|
||||
else:
|
||||
neg_bad_fp = -0.51*2.**64.
|
||||
pos_bad_fp = 2.**63.
|
||||
neg_good_fp = -2.**63.
|
||||
pos_good_fp = 1.9999998*2.**62.
|
||||
|
||||
fp2int_test(neg_bad_fp, 'neg bad', True)
|
||||
fp2int_test(pos_bad_fp, 'pos bad', True)
|
||||
fp2int_test(neg_good_fp, 'neg good', False)
|
||||
fp2int_test(pos_good_fp, 'pos good', False)
|
||||
else:
|
||||
fp2int_test(-1.999999879*2.**127., 'large neg', False)
|
||||
fp2int_test(1.999999879*2.**127., 'large pos', False)
|
||||
|
||||
fp2int_test(float('inf'), 'inf test', True)
|
||||
fp2int_test(float('nan'), 'NaN test', True)
|
||||
|
||||
# test numbers < 1 (this used to fail; see issue #1044)
|
||||
fp2int_test(0.0001, 'small num', False)
|
||||
struct.pack('I', int(1/2))
|
@ -1,20 +0,0 @@
|
||||
try:
|
||||
from array import array
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
def test(a):
|
||||
print(a)
|
||||
a.append(1.2)
|
||||
print(len(a), '%.3f' % a[0])
|
||||
a.append(1)
|
||||
a.append(False)
|
||||
print(len(a), '%.3f %.3f' % (a[1], a[2]))
|
||||
a[-1] = 3.45
|
||||
print('%.3f' % a[-1])
|
||||
|
||||
test(array('f'))
|
||||
test(array('d'))
|
||||
|
||||
print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0]))
|
@ -1,22 +0,0 @@
|
||||
# Extended float comparisons
|
||||
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
foo = Foo()
|
||||
|
||||
print(foo == 1.0)
|
||||
print(1.0 == foo)
|
||||
print(1.0 == Foo)
|
||||
print(1.0 == [])
|
||||
print(1.0 == {})
|
||||
|
||||
try:
|
||||
print(foo < 1.0)
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
try:
|
||||
print(1.0 < foo)
|
||||
except TypeError:
|
||||
print("TypeError")
|
@ -1,25 +0,0 @@
|
||||
# test floating point floor divide and modulus
|
||||
# it has some tricky corner cases
|
||||
|
||||
def test(x, y):
|
||||
div, mod = divmod(x, y)
|
||||
print('%.8f %.8f %.8f %.8f' % (x // y, x % y, div, mod))
|
||||
print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-15)
|
||||
|
||||
test(1.23456, 0.7)
|
||||
test(-1.23456, 0.7)
|
||||
test(1.23456, -0.7)
|
||||
test(-1.23456, -0.7)
|
||||
|
||||
a = 1.23456
|
||||
b = 0.7
|
||||
test(a, b)
|
||||
test(a, -b)
|
||||
test(-a, b)
|
||||
test(-a, -b)
|
||||
|
||||
for i in range(25):
|
||||
x = (i - 12.5) / 6
|
||||
for j in range(25):
|
||||
y = (j - 12.5) / 6
|
||||
test(x, y)
|
@ -1,33 +0,0 @@
|
||||
# test floating point floor divide and modulus
|
||||
# it has some tricky corner cases
|
||||
|
||||
# pyboard has 32-bit floating point and gives different (but still
|
||||
# correct) answers for certain combinations of divmod arguments.
|
||||
|
||||
def test(x, y):
|
||||
div, mod = divmod(x, y)
|
||||
print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-6)
|
||||
|
||||
test(1.23456, 0.7)
|
||||
test(-1.23456, 0.7)
|
||||
test(1.23456, -0.7)
|
||||
test(-1.23456, -0.7)
|
||||
|
||||
a = 1.23456
|
||||
b = 0.7
|
||||
test(a, b)
|
||||
test(a, -b)
|
||||
test(-a, b)
|
||||
test(-a, -b)
|
||||
|
||||
for i in range(25):
|
||||
x = (i - 12.5) / 6
|
||||
for j in range(25):
|
||||
y = (j - 12.5) / 6
|
||||
test(x, y)
|
||||
|
||||
# test division by zero error
|
||||
try:
|
||||
divmod(1.0, 0)
|
||||
except ZeroDivisionError:
|
||||
print('ZeroDivisionError')
|
@ -1,19 +0,0 @@
|
||||
# test float formatting
|
||||
|
||||
# general rounding
|
||||
for val in (116, 1111, 1234, 5010, 11111):
|
||||
print('%.0f' % val)
|
||||
print('%.1f' % val)
|
||||
print('%.3f' % val)
|
||||
|
||||
# make sure rounding is done at the correct precision
|
||||
for prec in range(8):
|
||||
print(('%%.%df' % prec) % 6e-5)
|
||||
|
||||
# check certain cases that had a digit value of 10 render as a ":" character
|
||||
print('%.2e' % float('9' * 51 + 'e-39'))
|
||||
print('%.2e' % float('9' * 40 + 'e-21'))
|
||||
|
||||
# check a case that would render negative digit values, eg ")" characters
|
||||
# the string is converted back to a float to check for no illegal characters
|
||||
float('%.23e' % 1e-80)
|
@ -1,32 +0,0 @@
|
||||
# test parsing of floats
|
||||
|
||||
inf = float('inf')
|
||||
|
||||
# it shouldn't matter where the decimal point is if the exponent balances the value
|
||||
print(float('1234') - float('0.1234e4'))
|
||||
print(float('1.015625') - float('1015625e-6'))
|
||||
|
||||
# very large integer part with a very negative exponent should cancel out
|
||||
print('%.4e' % float('9' * 60 + 'e-60'))
|
||||
print('%.4e' % float('9' * 60 + 'e-40'))
|
||||
|
||||
# many fractional digits
|
||||
print(float('.' + '9' * 70))
|
||||
print(float('.' + '9' * 70 + 'e20'))
|
||||
print(float('.' + '9' * 70 + 'e-50') == float('1e-50'))
|
||||
|
||||
# tiny fraction with large exponent
|
||||
print(float('.' + '0' * 60 + '1e10') == float('1e-51'))
|
||||
print(float('.' + '0' * 60 + '9e25') == float('9e-36'))
|
||||
print(float('.' + '0' * 60 + '9e40') == float('9e-21'))
|
||||
|
||||
# ensure that accuracy is retained when value is close to a subnormal
|
||||
print(float('1.00000000000000000000e-37'))
|
||||
print(float('10.0000000000000000000e-38'))
|
||||
print(float('100.000000000000000000e-39'))
|
||||
|
||||
# very large exponent literal
|
||||
print(float('1e4294967301'))
|
||||
print(float('1e-4294967301'))
|
||||
print(float('1e18446744073709551621'))
|
||||
print(float('1e-18446744073709551621'))
|
@ -1,21 +0,0 @@
|
||||
# test parsing of floats, requiring double-precision
|
||||
|
||||
# very large integer part with a very negative exponent should cancel out
|
||||
print(float('9' * 400 + 'e-100'))
|
||||
print(float('9' * 400 + 'e-200'))
|
||||
print(float('9' * 400 + 'e-400'))
|
||||
|
||||
# many fractional digits
|
||||
print(float('.' + '9' * 400))
|
||||
print(float('.' + '9' * 400 + 'e100'))
|
||||
print(float('.' + '9' * 400 + 'e-100'))
|
||||
|
||||
# tiny fraction with large exponent
|
||||
print('%.14e' % float('.' + '0' * 400 + '9e100'))
|
||||
print('%.14e' % float('.' + '0' * 400 + '9e200'))
|
||||
print('%.14e' % float('.' + '0' * 400 + '9e400'))
|
||||
|
||||
# ensure that accuracy is retained when value is close to a subnormal
|
||||
print(float('1.00000000000000000000e-307'))
|
||||
print(float('10.0000000000000000000e-308'))
|
||||
print(float('100.000000000000000000e-309'))
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user