comparison tests/test_signal.py @ 372:d653e3f58f3c

`samples` should always return a list of arrays
author Amine Sehili <amine.sehili@gmail.com>
date Fri, 15 Jan 2021 21:02:29 +0100
parents 63871bac77f6
children 323d59b404a2
comparison
equal deleted inserted replaced
371:8d3e2b492c6f 372:d653e3f58f3c
12 def setUp(self): 12 def setUp(self):
13 self.data = b"012345679ABC" 13 self.data = b"012345679ABC"
14 self.numpy_fmt = {"b": np.int8, "h": np.int16, "i": np.int32} 14 self.numpy_fmt = {"b": np.int8, "h": np.int16, "i": np.int32}
15 15
16 @genty_dataset( 16 @genty_dataset(
17 int8_mono=(1, [48, 49, 50, 51, 52, 53, 54, 55, 57, 65, 66, 67]), 17 int8_mono=(1, [[48, 49, 50, 51, 52, 53, 54, 55, 57, 65, 66, 67]]),
18 int16_mono=(2, [12592, 13106, 13620, 14134, 16697, 17218]), 18 int16_mono=(2, [[12592, 13106, 13620, 14134, 16697, 17218]]),
19 int32_mono=(4, [858927408, 926299444, 1128415545]), 19 int32_mono=(4, [[858927408, 926299444, 1128415545]]),
20 int8_stereo=(1, [[48, 50, 52, 54, 57, 66], [49, 51, 53, 55, 65, 67]]), 20 int8_stereo=(1, [[48, 50, 52, 54, 57, 66], [49, 51, 53, 55, 65, 67]]),
21 int16_stereo=(2, [[12592, 13620, 16697], [13106, 14134, 17218]]), 21 int16_stereo=(2, [[12592, 13620, 16697], [13106, 14134, 17218]]),
22 int32_3channel=(4, [[858927408], [926299444], [1128415545]]), 22 int32_3channel=(4, [[858927408], [926299444], [1128415545]]),
23 ) 23 )
24 def test_to_array(self, sample_width, expected): 24 def test_to_array(self, sample_width, expected):
25 if isinstance(expected[0], list): 25 channels = len(expected)
26 channels = len(expected) 26 expected = [
27 expected = [ 27 array_(signal_.FORMAT[sample_width], xi) for xi in expected
28 array_(signal_.FORMAT[sample_width], xi) for xi in expected 28 ]
29 ]
30 else:
31 channels = 1
32 expected = array_(signal_.FORMAT[sample_width], expected)
33 result = signal_.to_array(self.data, sample_width, channels) 29 result = signal_.to_array(self.data, sample_width, channels)
34 result_numpy = signal_numpy.to_array(self.data, sample_width, channels) 30 result_numpy = signal_numpy.to_array(self.data, sample_width, channels)
35 self.assertEqual(result, expected) 31 self.assertEqual(result, expected)
36 self.assertTrue((result_numpy == np.asarray(expected)).all()) 32 self.assertTrue((result_numpy == np.asarray(expected)).all())
37 self.assertEqual(result_numpy.dtype, np.float64) 33 self.assertEqual(result_numpy.dtype, np.float64)