mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 01:18:02 +08:00
23 lines
485 B
Python
23 lines
485 B
Python
import ecc
|
|
import random
|
|
import itertools
|
|
|
|
|
|
def concat(chunks):
|
|
return bytearray(itertools.chain.from_iterable(chunks))
|
|
|
|
|
|
def test_random():
|
|
r = random.Random(0)
|
|
x = bytearray(r.randrange(0, 256) for i in range(16 * 1024))
|
|
y = ecc.encode(x)
|
|
x_ = concat(ecc.decode(y))
|
|
assert x_[:len(x)] == x
|
|
assert all(v == 0 for v in x_[len(x):])
|
|
|
|
|
|
def test_file():
|
|
data = open('data.send').read()
|
|
enc = ecc.encode(data)
|
|
assert concat(ecc.decode(enc)) == data
|