From 63fbee8bfcb4aa0b3aaa5720efea6e76f57995f8 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sat, 5 Jul 2014 09:40:09 +0300 Subject: [PATCH] Add test for sampling --- sampling.py | 4 ++-- test_sampling.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test_sampling.py diff --git a/sampling.py b/sampling.py index a53cc1b..5737391 100644 --- a/sampling.py +++ b/sampling.py @@ -25,10 +25,10 @@ class Interpolator(object): return coeffs, k - self.width class Sampler(object): - def __init__(self, src, interp): + def __init__(self, src, interp=None): self.src = iter(src) self.freq = 1.0 - self.interp = interp + self.interp = interp if (interp is not None) else Interpolator() coeffs, begin = self.interp.get(0) self.offset = -begin # should fill samples buffer self.buff = np.zeros(len(coeffs)) diff --git a/test_sampling.py b/test_sampling.py new file mode 100644 index 0000000..0a67b11 --- /dev/null +++ b/test_sampling.py @@ -0,0 +1,12 @@ +import sampling +import numpy as np + +def test_resample(): + x = np.arange(300) + s = sampling.Sampler(x) + y = np.array(list(s)) + + k = s.interp.width - 1 + x = x[k:-k-1] + err = np.max(np.abs(x - y)) + assert err < 1e-10