diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2023-06-06 22:15:44 +1000 |
|---|---|---|
| committer | Jim Mussared <jim.mussared@gmail.com> | 2023-06-08 17:54:28 +1000 |
| commit | a1fbb1980cf90cc58186eac9cc405a97ebd41e64 (patch) | |
| tree | cbce396ba0360d134f82e0287c8b2a03a116ff8a /tests | |
| parent | 8211d56712301d58970904892da5312b11b2ab7c (diff) | |
extmod/modtimeq: Remove timeq module.
This is a MicroPython-specific module that existed to support the old
version of uasyncio. It's undocumented and not enabled on all ports and
takes up code size unnecessarily.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extmod/timeq1.py | 146 | ||||
| -rw-r--r-- | tests/extmod/timeq1.py.exp | 1 | ||||
| -rw-r--r-- | tests/extmod/timeq_stable.py | 22 | ||||
| -rw-r--r-- | tests/extmod/timeq_stable.py.exp | 1 | ||||
| -rw-r--r-- | tests/unix/extra_coverage.py.exp | 6 |
5 files changed, 3 insertions, 173 deletions
diff --git a/tests/extmod/timeq1.py b/tests/extmod/timeq1.py deleted file mode 100644 index 0778c8725..000000000 --- a/tests/extmod/timeq1.py +++ /dev/null @@ -1,146 +0,0 @@ -# Test for timeq module which implements task queue with support for -# wraparound time (time.ticks_ms() style). -try: - from time import ticks_add, ticks_diff - from timeq import timeq -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 = timeq(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 = timeq(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: - timeq(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 = timeq(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 = timeq(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 asymmetry 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") diff --git a/tests/extmod/timeq1.py.exp b/tests/extmod/timeq1.py.exp deleted file mode 100644 index d86bac9de..000000000 --- a/tests/extmod/timeq1.py.exp +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/tests/extmod/timeq_stable.py b/tests/extmod/timeq_stable.py deleted file mode 100644 index b19ea1b3a..000000000 --- a/tests/extmod/timeq_stable.py +++ /dev/null @@ -1,22 +0,0 @@ -try: - from timeq import timeq -except ImportError: - print("SKIP") - raise SystemExit - -h = timeq(10) - -# Check that for 2 same-key items, the queue is stable (pops items -# in the same order they were pushed). Unfortunately, this no longer -# holds for more same-key values, as the underlying heap structure -# is not stable itself. -h.push(100, 20, 0) -h.push(100, 10, 0) - -res = [0, 0, 0] -h.pop(res) -assert res == [100, 20, 0] -h.pop(res) -assert res == [100, 10, 0] - -print("OK") diff --git a/tests/extmod/timeq_stable.py.exp b/tests/extmod/timeq_stable.py.exp deleted file mode 100644 index d86bac9de..000000000 --- a/tests/extmod/timeq_stable.py.exp +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 6ec8eaaa0..04aefcfe2 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -58,11 +58,11 @@ framebuf gc hashlib heapq io json machine math os random re select socket ssl struct sys -termios time timeq uctypes -websocket zlib +termios time uctypes websocket +zlib me -time timeq +micropython machine math argv atexit byteorder exc_info executable exit getsizeof implementation |
