From: Paul Brossier Date: Sat, 10 Nov 2018 10:58:54 +0000 (+0100) Subject: Merge branch 'master' into feature/pytest X-Git-Tag: 0.4.9~71^2~15 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=893e699deadca272129fa1493aaeb04b4b6ba1c6;p=aubio.git Merge branch 'master' into feature/pytest --- 893e699deadca272129fa1493aaeb04b4b6ba1c6 diff --cc python/tests/test_filterbank_mel.py index 79f28d63,fc8c1598..1a5e05ed --- a/python/tests/test_filterbank_mel.py +++ b/python/tests/test_filterbank_mel.py @@@ -2,10 -2,12 +2,10 @@@ import numpy as np from numpy.testing import TestCase, assert_equal, assert_almost_equal +from _tools import assert_warns - from aubio import cvec, filterbank, float_type + from aubio import fvec, cvec, filterbank, float_type -import warnings -warnings.filterwarnings('ignore', category=UserWarning, append=True) - class aubio_filterbank_mel_test_case(TestCase): def test_slaney(self): @@@ -47,37 -47,69 +47,101 @@@ [ 0.02070313, 0.02138672, 0.02127604, 0.02135417, 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) + def test_triangle_freqs_normal(self): + """ create a filter with set_triangle_bands, normal mode """ + f = filterbank(3, 1024) + freq_list = [100, 1000, 10000, 15000, 20000] + freqs = np.array(freq_list, dtype = float_type) + f.set_triangle_bands(freqs, 44100) + + def test_triangle_freqs_too_long(self): + """ create a filter with freq_list too long """ + f = filterbank(2, 1024) + freq_list = [100, 1000, 10000, 15000, 20000] + freqs = np.array(freq_list, dtype = float_type) + with assert_warns(UserWarning): + f.set_triangle_bands(freqs, 44100) + + def test_triangle_freqs_too_short(self): + """ create a filter with freq_list too short """ + f = filterbank(4, 1024) + freq_list = [100, 1000, 10000, 15000, 20000] + freqs = np.array(freq_list, dtype = float_type) + with assert_warns(UserWarning): + f.set_triangle_bands(freqs, 44100) + + def test_above_nyquist(self): + """ create a filter with freq_list too short """ + f = filterbank(3, 1024) + freq_list = [100, 1000, 10000, 15000, 23000] + freqs = np.array(freq_list, dtype = float_type) + with assert_warns(UserWarning): + f.set_triangle_bands(freqs, 44100) + + def test_triangle_freqs_with_zeros(self): + """make sure set_triangle_bands works when list starts with 0""" + freq_list = [0, 40, 80] + freqs = np.array(freq_list, dtype = float_type) + f = filterbank(len(freqs)-2, 1024) + f.set_triangle_bands(freqs, 48000) + assert_equal ( f(cvec(1024)), 0) + self.assertIsInstance(f.get_coeffs(), np.ndarray) + + def test_triangle_freqs_with_wrong_negative(self): + """make sure set_triangle_bands fails when list contains a negative""" + freq_list = [-10, 0, 80] + f = filterbank(len(freq_list)-2, 1024) + with self.assertRaises(ValueError): + f.set_triangle_bands(fvec(freq_list), 48000) + + def test_triangle_freqs_with_wrong_ordering(self): + """make sure set_triangle_bands fails when list not ordered""" + freq_list = [0, 80, 40] + f = filterbank(len(freq_list)-2, 1024) + with self.assertRaises(ValueError): + f.set_triangle_bands(fvec(freq_list), 48000) + + def test_triangle_freqs_with_large_freq(self): + """make sure set_triangle_bands warns when freq > nyquist""" + samplerate = 22050 + freq_list = [0, samplerate//4, samplerate // 2 + 1] + f = filterbank(len(freq_list)-2, 1024) + # TODO add assert_warns + f.set_triangle_bands(fvec(freq_list), samplerate) + + def test_triangle_freqs_with_not_enough_filters(self): + """make sure set_triangle_bands warns when not enough filters""" + samplerate = 22050 + freq_list = [0, 100, 1000, 4000, 8000, 10000] + f = filterbank(len(freq_list)-3, 1024) + # TODO add assert_warns + f.set_triangle_bands(fvec(freq_list), samplerate) + + def test_triangle_freqs_with_too_many_filters(self): + """make sure set_triangle_bands warns when too many filters""" + samplerate = 22050 + freq_list = [0, 100, 1000, 4000, 8000, 10000] + f = filterbank(len(freq_list)-1, 1024) + # TODO add assert_warns + f.set_triangle_bands(fvec(freq_list), samplerate) + + def test_triangle_freqs_with_double_value(self): + """make sure set_triangle_bands works with 2 duplicate freqs""" + samplerate = 22050 + freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] + f = filterbank(len(freq_list)-2, 1024) + # TODO add assert_warns + f.set_triangle_bands(fvec(freq_list), samplerate) + + def test_triangle_freqs_with_triple(self): + """make sure set_triangle_bands works with 3 duplicate freqs""" + samplerate = 22050 + freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] + f = filterbank(len(freq_list)-2, 1024) + # TODO add assert_warns + f.set_triangle_bands(fvec(freq_list), samplerate) + ++ if __name__ == '__main__': - import nose2 - nose2.main() + from unittest import main + main()