3 from _tools import parametrize, assert_raises
4 from numpy import random, count_nonzero
5 from numpy.testing import TestCase
6 from aubio import mfcc, cvec, float_type
14 new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
15 new_deflts = [1024, 40, 13, 44100]
17 class Test_aubio_mfcc:
21 @parametrize(members_args, new_params)
22 def test_read_only_member(self, name):
24 with assert_raises((TypeError, AttributeError)):
27 @parametrize('name, expected', zip(new_params, new_deflts))
28 def test_default_param(self, name, expected):
29 """ test mfcc.{:s} = {:d} """.format(name, expected)
31 assert getattr(o, name) == expected
33 class aubio_mfcc_wrong_params(TestCase):
35 def test_wrong_buf_size(self):
36 with self.assertRaises(ValueError):
39 def test_wrong_n_filters(self):
40 with self.assertRaises(ValueError):
43 def test_wrong_n_coeffs(self):
44 with self.assertRaises(ValueError):
47 def test_wrong_samplerate(self):
48 with self.assertRaises(ValueError):
51 def test_wrong_input_size(self):
52 m = mfcc(buf_size = 1024)
53 with self.assertRaises(ValueError):
56 class aubio_mfcc_compute(TestCase):
58 def test_members(self):
60 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
61 #assert_equal ([o.buf_size, o.method], [buf_size, method])
66 #print "%20s" % method, str(o(spec))
68 self.assertEqual(coeffs.size, n_coeffs)
70 spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
71 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
72 #print "%20s" % method, str(o(spec))
73 self.assertEqual(count_nonzero(o(spec) != 0.), n_coeffs)
77 class Test_aubio_mfcc_all_parameters:
80 (2048, 40, 13, 44100),
81 (1024, 40, 13, 44100),
91 (1024, 40, 20, 44100),
92 #(1024, 30, 20, 44100),
93 (1024, 40, 40, 44100),
96 run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
98 @parametrize(run_args, run_values)
99 def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
100 " check mfcc can run with reasonable parameters "
101 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
102 spec = cvec(buf_size)
108 if __name__ == '__main__':
110 pytest.main(sys.argv)