From e2bc26f651921ef3534e92e8e00021d865a4a4a4 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Fri, 18 Aug 2023 20:41:27 -0400 Subject: [PATCH] Add unit tests for `sdr.downsample()` --- tests/dsp/test_downsample.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/dsp/test_downsample.py diff --git a/tests/dsp/test_downsample.py b/tests/dsp/test_downsample.py new file mode 100644 index 000000000..dbeb0f265 --- /dev/null +++ b/tests/dsp/test_downsample.py @@ -0,0 +1,27 @@ +import numpy as np +import pytest + +import sdr + + +def test_exceptions(): + x = np.random.randn(40) + + with pytest.raises(TypeError): + # Rate must be an integer + sdr.downsample(x, 4.0) + with pytest.raises(ValueError): + # Rate must be positive + sdr.downsample(x, 0) + + +def test_1(): + """ + Matlab: + >> x = 0:39; + >> downsample(x, 4)' + """ + x = np.arange(40) + y = sdr.downsample(x, 4) + y_truth = np.array([0, 4, 8, 12, 16, 20, 24, 28, 32, 36]) + assert np.array_equal(y, y_truth)