mirror of
https://github.com/romanz/amodem.git
synced 2026-03-30 23:57:54 +08:00
tests: move to root directory
This commit is contained in:
53
tests/test_common.py
Normal file
53
tests/test_common.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import common
|
||||
import numpy as np
|
||||
|
||||
|
||||
def iterlist(x, *args, **kwargs):
|
||||
x = np.array(x)
|
||||
return list((i, list(x)) for i, x in common.iterate(x, *args, **kwargs))
|
||||
|
||||
|
||||
def test_iterate():
|
||||
N = 10
|
||||
assert iterlist(range(N), 1) == [
|
||||
(i, [i]) for i in range(N)]
|
||||
|
||||
assert iterlist(range(N), 2) == [
|
||||
(i, [i, i+1]) for i in range(0, N-1, 2)]
|
||||
|
||||
assert iterlist(range(N), 3) == [
|
||||
(i, [i, i+1, i+2]) for i in range(0, N-2, 3)]
|
||||
|
||||
assert iterlist(range(N), 1, func=lambda b: -np.array(b)) == [
|
||||
(i, [-i]) for i in range(N)]
|
||||
|
||||
|
||||
def test_split():
|
||||
L = [(i*2, i*2+1) for i in range(10)]
|
||||
iters = common.split(L, n=2)
|
||||
assert zip(*iters) == L
|
||||
|
||||
for i in [0, 1]:
|
||||
iters = common.split(L, n=2)
|
||||
iters[i].next()
|
||||
try:
|
||||
iters[i].next()
|
||||
assert False
|
||||
except IndexError as e:
|
||||
assert e.args == (i,)
|
||||
|
||||
|
||||
def test_icapture():
|
||||
x = range(100)
|
||||
y = []
|
||||
z = []
|
||||
for i in common.icapture(x, result=y):
|
||||
z.append(i)
|
||||
assert x == y
|
||||
assert x == z
|
||||
|
||||
|
||||
def test_dumps_loads():
|
||||
x = np.array([.1, .4, .2, .6, .3, .5])
|
||||
y = common.loads(common.dumps(x * 1j))
|
||||
assert all(x == y)
|
||||
Reference in New Issue
Block a user