@@ -0,0 +1,1586 @@
+import pytest%0Aimport numpy as np%0Afrom numpy import sin, pi%0Afrom scipy.signal import sawtooth%0A%0A# This package must first be installed with %60pip install -e .%60 or similar%0Afrom waveform_analysis.thd import THD, THDN%0A%0A%0Adef sine_wave(f, fs):%0A    %22%22%22%0A    Generate 1 second of sine wave at f frequency sampled at fs rate%0A    %22%22%22%0A    t = np.linspace(0, 1, fs, endpoint=False)%0A    return sin(2*pi * f * t)%0A%0A%0Adef sawtooth_wave(f, fs):%0A    %22%22%22%0A    Generate 1 second of sine wave at f frequency sampled at fs rate%0A    %22%22%22%0A    t = np.linspace(0, 1, fs, endpoint=False)%0A    return sawtooth(2*pi * f * t)%0A%0A%0Aclass TestTHDN(object):%0A    def test_invalid_params(self):%0A        with pytest.raises(TypeError):%0A            THDN(None)%0A%0A#        with pytest.raises(TypeError):%0A#            THDN(np.array(%5B1, 2%5D), sample_rate=50)%0A#%0A#    def test_array_like(self):%0A#        freq_from_crossings(%5B-1, +1, -1, +1%5D, 10)%0A#%0A    def test_sine(self):%0A        # TODO use non-easy signal lengths and frequencies%0A        # padding, etc.%0A        fs = 100000  # Hz%0A        f = 1000  # Hz%0A        signal = sine_wave(f, fs) + 0.1 * sine_wave(2*f, fs)%0A        assert THDN(signal, fs) == pytest.approx(0.1, rel=1e-2)%0A        # TODO: Tighten tolerances%0A%0A#    def test_interp(self):%0A#        fs = 100000  # Hz%0A#        f = 1234.56789  # Hz%0A#        signal = sine_wave(f, fs)%0A#        correct = pytest.approx(f)%0A#        assert freq_from_crossings(signal, fs, interp='none') == correct%0A#        assert freq_from_crossings(signal, fs, interp=None) == correct%0A%0A%0Aif __name__ == '__main__':%0A    pytest.main(%5B__file__, %22--capture=sys%22%5D)%0A

Add THD tests