ref: e116e192d0dad8719b941bad9bd848605aaecfe8
parent: c4fc0f2b95b05cabdeaf37e1058aa1a252753786
author: Paul Brossier <piem@piem.org>
date: Thu Sep 14 12:33:21 EDT 2017
python/tests/test_filterbank*.py: clean-up, improve get_coeff tests
--- a/python/tests/test_filterbank.py
+++ b/python/tests/test_filterbank.py
@@ -1,9 +1,8 @@
#! /usr/bin/env python
-from unittest import main
-from numpy.testing import TestCase
-from numpy.testing import assert_equal, assert_almost_equal
import numpy as np
+from numpy.testing import TestCase, assert_equal, assert_almost_equal
+
from aubio import cvec, filterbank, float_type
from .utils import array_from_text_file
@@ -62,6 +61,13 @@
f.set_mel_coeffs_slaney(16000)
assert_almost_equal ( expected, f.get_coeffs() )
+ def test_mfcc_coeffs_get_coeffs(self):
+ f = filterbank(40, 512)
+ coeffs = f.get_coeffs()
+ self.assertIsInstance(coeffs, np.ndarray)
+ assert_equal (coeffs, 0)
+ assert_equal (np.shape(coeffs), (40, 512 / 2 + 1))
+
class aubio_filterbank_wrong_values(TestCase):
def test_negative_window(self):
@@ -81,4 +87,5 @@
f(cvec(256))
if __name__ == '__main__':
- main()
+ import nose2
+ nose2.main()
--- a/python/tests/test_filterbank_mel.py
+++ b/python/tests/test_filterbank_mel.py
@@ -1,9 +1,8 @@
#! /usr/bin/env python
-from unittest import main
-from numpy.testing import TestCase
-from numpy.testing import assert_equal, assert_almost_equal
-from numpy import array, shape
+import numpy as np
+from numpy.testing import TestCase, assert_equal, assert_almost_equal
+
from aubio import cvec, filterbank, float_type
class aubio_filterbank_mel_test_case(TestCase):
@@ -12,33 +11,33 @@
f = filterbank(40, 512)
f.set_mel_coeffs_slaney(16000)
a = f.get_coeffs()
- assert_equal(shape (a), (40, 512/2 + 1) )
+ assert_equal(np.shape (a), (40, 512/2 + 1) )
def test_other_slaney(self):
f = filterbank(40, 512*2)
f.set_mel_coeffs_slaney(44100)
- _ = f.get_coeffs()
+ self.assertIsInstance(f.get_coeffs(), np.ndarray)
#print "sum is", sum(sum(a))
for win_s in [256, 512, 1024, 2048, 4096]:
f = filterbank(40, win_s)
f.set_mel_coeffs_slaney(32000)
- _ = f.get_coeffs()
#print "sum is", sum(sum(a))
+ self.assertIsInstance(f.get_coeffs(), np.ndarray)
def test_triangle_freqs_zeros(self):
f = filterbank(9, 1024)
freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
- freqs = array(freq_list, dtype = float_type)
+ freqs = np.array(freq_list, dtype = float_type)
f.set_triangle_bands(freqs, 48000)
- _ = f.get_coeffs().T
assert_equal ( f(cvec(1024)), 0)
+ self.assertIsInstance(f.get_coeffs(), np.ndarray)
def test_triangle_freqs_ones(self):
f = filterbank(9, 1024)
freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
- freqs = array(freq_list, dtype = float_type)
+ freqs = np.array(freq_list, dtype = float_type)
f.set_triangle_bands(freqs, 48000)
- _ = f.get_coeffs().T
+ self.assertIsInstance(f.get_coeffs(), np.ndarray)
spec = cvec(1024)
spec.norm[:] = 1
assert_almost_equal ( f(spec),
@@ -46,4 +45,5 @@
0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
if __name__ == '__main__':
- main()
+ import nose2
+ nose2.main()