History

[filterbank] improve unit tests

Paul Brossier committed 8 years ago

Commit e33d9601 parent edd3dac1 file · +39 −1Browse files

Showing the changes to python/tests (1 of 1 file). Show all

Unified · Split

python/tests/test_filterbank_mel.py+39−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
3import numpy as np3import numpy as np
4from numpy.testing import TestCase, assert_equal, assert_almost_equal4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5 5
6from aubio import cvec, filterbank, float_type6from aubio import fvec, cvec, filterbank, float_type
7 7
8import warnings8import warnings
9warnings.filterwarnings('ignore', category=UserWarning, append=True)9warnings.filterwarnings('ignore', category=UserWarning, append=True)
@@ -56,6 +56,44 @@ class aubio_filterbank_mel_test_case(TestCase): · 46 unmodified lines
56 assert_equal ( f(cvec(1024)), 0)56 assert_equal ( f(cvec(1024)), 0)
57 self.assertIsInstance(f.get_coeffs(), np.ndarray)57 self.assertIsInstance(f.get_coeffs(), np.ndarray)
58 58
59 def test_triangle_freqs_with_wrong_negative(self):
60 """make sure set_triangle_bands fails when list contains a negative"""
61 freq_list = [-10, 0, 80]
62 f = filterbank(len(freq_list)-2, 1024)
63 with self.assertRaises(ValueError):
64 f.set_triangle_bands(fvec(freq_list), 48000)
65
66 def test_triangle_freqs_with_wrong_ordering(self):
67 """make sure set_triangle_bands fails when list not ordered"""
68 freq_list = [0, 80, 40]
69 f = filterbank(len(freq_list)-2, 1024)
70 with self.assertRaises(ValueError):
71 f.set_triangle_bands(fvec(freq_list), 48000)
72
73 def test_triangle_freqs_with_large_freq(self):
74 """make sure set_triangle_bands warns when freq > nyquist"""
75 samplerate = 22050
76 freq_list = [0, samplerate//4, samplerate // 2 + 1]
77 f = filterbank(len(freq_list)-2, 1024)
78 # TODO add assert_warns
79 f.set_triangle_bands(fvec(freq_list), samplerate)
80
81 def test_triangle_freqs_with_not_enough_filters(self):
82 """make sure set_triangle_bands warns when not enough filters"""
83 samplerate = 22050
84 freq_list = [0, 100, 1000, 4000, 8000, 10000]
85 f = filterbank(len(freq_list)-3, 1024)
86 # TODO add assert_warns
87 f.set_triangle_bands(fvec(freq_list), samplerate)
88
89 def test_triangle_freqs_with_too_many_filters(self):
90 """make sure set_triangle_bands warns when too many filters"""
91 samplerate = 22050
92 freq_list = [0, 100, 1000, 4000, 8000, 10000]
93 f = filterbank(len(freq_list)-1, 1024)
94 # TODO add assert_warns
95 f.set_triangle_bands(fvec(freq_list), samplerate)
96
59if __name__ == '__main__':97if __name__ == '__main__':
60 import nose298 import nose2
61 nose2.main()99 nose2.main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t