mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 01:18:02 +08:00
test: add noisy channel support
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import os
|
||||
from cStringIO import StringIO
|
||||
import numpy as np
|
||||
|
||||
import send
|
||||
import recv
|
||||
import common
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='%(asctime)s %(levelname)-12s %(message)s')
|
||||
|
||||
class Args(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
def run(chan, size):
|
||||
def run(size, chan):
|
||||
tx_data = os.urandom(size)
|
||||
tx_audio = StringIO()
|
||||
send.main(Args(silence_start=1, silence_stop=1, input=StringIO(tx_data), output=tx_audio))
|
||||
@@ -27,7 +32,18 @@ def run(chan, size):
|
||||
assert rx_data == tx_data
|
||||
|
||||
def test_small():
|
||||
run(chan=lambda x: x, size=1024)
|
||||
run(1024, lambda x: x)
|
||||
|
||||
def test_large():
|
||||
run(chan=lambda x: x, size=64 << 10)
|
||||
run(54321, lambda x: x)
|
||||
|
||||
def test_attenuation():
|
||||
run(5120, lambda x: x * 0.1)
|
||||
|
||||
def test_low_noise():
|
||||
r = np.random.RandomState(seed=0)
|
||||
run(5120, lambda x: x + r.normal(size=len(x), scale=0.0001))
|
||||
|
||||
def test_medium_noise():
|
||||
r = np.random.RandomState(seed=0)
|
||||
run(5120, lambda x: x + r.normal(size=len(x), scale=0.001))
|
||||
|
||||
Reference in New Issue
Block a user