Commit 7a918170 authored by Ronan Hamon's avatar Ronan Hamon

add tests of the type of the output of operations on Waveform

parent 9637b0f1
Pipeline #453 failed with stage
in 36 seconds
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment