History

Merge branch 'master' into feature/pytest

Paul Brossier committed 8 years ago

Commit 893e6992 parents 568fc60 9ef3c6e2 files · +81 −16Browse files

Showing the changes to python (1 of 2 files). Show all

Unified · Split

python/tests/test_filterbank_mel.py+65−1
@@ -4,7 +4,7 @@ import numpy as np · 3 unmodified lines
44 from numpy.testing import TestCase, assert_equal, assert_almost_equal
55 from _tools import assert_warns
66
7−from aubio import cvec, filterbank, float_type
7+from aubio import fvec, cvec, filterbank, float_type
88
99 class aubio_filterbank_mel_test_case(TestCase):
1010
@@ -78,6 +78,70 @@ class aubio_filterbank_mel_test_case(TestCase): · 67 unmodified lines
7878 with assert_warns(UserWarning):
7979 f.set_triangle_bands(freqs, 44100)
8080
81+ def test_triangle_freqs_with_zeros(self):
82+ """make sure set_triangle_bands works when list starts with 0"""
83+ freq_list = [0, 40, 80]
84+ freqs = np.array(freq_list, dtype = float_type)
85+ f = filterbank(len(freqs)-2, 1024)
86+ f.set_triangle_bands(freqs, 48000)
87+ assert_equal ( f(cvec(1024)), 0)
88+ self.assertIsInstance(f.get_coeffs(), np.ndarray)
89+
90+ def test_triangle_freqs_with_wrong_negative(self):
91+ """make sure set_triangle_bands fails when list contains a negative"""
92+ freq_list = [-10, 0, 80]
93+ f = filterbank(len(freq_list)-2, 1024)
94+ with self.assertRaises(ValueError):
95+ f.set_triangle_bands(fvec(freq_list), 48000)
96+
97+ def test_triangle_freqs_with_wrong_ordering(self):
98+ """make sure set_triangle_bands fails when list not ordered"""
99+ freq_list = [0, 80, 40]
100+ f = filterbank(len(freq_list)-2, 1024)
101+ with self.assertRaises(ValueError):
102+ f.set_triangle_bands(fvec(freq_list), 48000)
103+
104+ def test_triangle_freqs_with_large_freq(self):
105+ """make sure set_triangle_bands warns when freq > nyquist"""
106+ samplerate = 22050
107+ freq_list = [0, samplerate//4, samplerate // 2 + 1]
108+ f = filterbank(len(freq_list)-2, 1024)
109+ # TODO add assert_warns
110+ f.set_triangle_bands(fvec(freq_list), samplerate)
111+
112+ def test_triangle_freqs_with_not_enough_filters(self):
113+ """make sure set_triangle_bands warns when not enough filters"""
114+ samplerate = 22050
115+ freq_list = [0, 100, 1000, 4000, 8000, 10000]
116+ f = filterbank(len(freq_list)-3, 1024)
117+ # TODO add assert_warns
118+ f.set_triangle_bands(fvec(freq_list), samplerate)
119+
120+ def test_triangle_freqs_with_too_many_filters(self):
121+ """make sure set_triangle_bands warns when too many filters"""
122+ samplerate = 22050
123+ freq_list = [0, 100, 1000, 4000, 8000, 10000]
124+ f = filterbank(len(freq_list)-1, 1024)
125+ # TODO add assert_warns
126+ f.set_triangle_bands(fvec(freq_list), samplerate)
127+
128+ def test_triangle_freqs_with_double_value(self):
129+ """make sure set_triangle_bands works with 2 duplicate freqs"""
130+ samplerate = 22050
131+ freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
132+ f = filterbank(len(freq_list)-2, 1024)
133+ # TODO add assert_warns
134+ f.set_triangle_bands(fvec(freq_list), samplerate)
135+
136+ def test_triangle_freqs_with_triple(self):
137+ """make sure set_triangle_bands works with 3 duplicate freqs"""
138+ samplerate = 22050
139+ freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
140+ f = filterbank(len(freq_list)-2, 1024)
141+ # TODO add assert_warns
142+ f.set_triangle_bands(fvec(freq_list), samplerate)
143+
144+
81145 if __name__ == '__main__':
82146 from unittest import main
83147 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