diff --git a/madarrays/tests/test_waveform.py b/madarrays/tests/test_waveform.py index fb57bb1deca95ee0944e2456a81a9b68f3b22d8d..24d7bb974616f40d66e20e4f1738b08015ac1f01 100644 --- a/madarrays/tests/test_waveform.py +++ b/madarrays/tests/test_waveform.py @@ -61,9 +61,11 @@ import simpleaudio as sa import matplotlib.pyplot as plt import numpy as np + from scipy.io import wavfile from IPython.display import Audio +from madarrays.mad_array import MadArray from madarrays.waveform import Waveform from .utils import assert_array_less_or_equal @@ -967,32 +969,27 @@ class TestWaveform: assert np.all(~cmp_w) def test_operations(self): + w1 = Waveform(self.x_mono, fs=self.fs) - w2 = Waveform(self.x_mono, fs=1 if self.fs > 1 else 44100) - - np.testing.assert_equal(w1 + w1, self.x_mono + self.x_mono, - err_msg='add') - np.testing.assert_equal(w1 - w1, self.x_mono - self.x_mono, - err_msg='sub') - np.testing.assert_equal(w1 * w1, self.x_mono * self.x_mono, - err_msg='mul') - np.testing.assert_equal(w1 / w1, self.x_mono / self.x_mono, - err_msg='truediv') - np.testing.assert_equal(w1 // w1, self.x_mono // self.x_mono, - err_msg='floordiv') - - match = 'Waveforms do not have the same fs: \d+ and \d+' - with pytest.raises(ValueError, match=match): - w1 + w2 + w2 = Waveform(self.x_mono, fs=self.fs) + w3 = Waveform(self.x_mono, fs=1 if self.fs > 1 else 44100) + ma = MadArray(self.x_mono) - with pytest.raises(ValueError, match=match): - w1 * w2 + for operator in ['+', '-', '*', '/', '//']: + print('Operation: {}'.format(operator)) - with pytest.raises(ValueError, match=match): - w1 / w2 + ws = eval('w1 {} w2'.format(operator)) + assert isinstance(ws, Waveform) + np.testing.assert_equal(ws, self.x_mono + self.x_mono) + + match='Waveforms do not have the same fs: \d+ and \d+' + with pytest.raises(ValueError, match=match): + eval('w1 {} w3'.format(operator)) + + ms = eval('w1 {} ma'.format(operator)) + assert isinstance(ws, Waveform) + np.testing.assert_equal(ws, self.x_mono + self.x_mono) - with pytest.raises(ValueError, match=match): - w1 // w2 with pytest.raises(ValueError, match=match): w1 == w2