4 from nose2.tools import params
5 from numpy import random, count_nonzero
6 from numpy.testing import TestCase
7 from aubio import mfcc, cvec, float_type
15 new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
16 new_deflts = [1024, 40, 13, 44100]
18 class aubio_mfcc(TestCase):
23 def test_default_creation(self):
26 def test_delete(self):
30 def test_read_only_member(self, name):
32 with self.assertRaises((TypeError, AttributeError)):
35 @params(*zip(new_params, new_deflts))
36 def test_default_param(self, name, expected):
37 """ test mfcc.{:s} = {:d} """.format(name, expected)
39 self.assertEqual( getattr(o, name), expected)
41 class aubio_mfcc_wrong_params(TestCase):
43 def test_wrong_buf_size(self):
44 with self.assertRaises(ValueError):
47 def test_wrong_n_filters(self):
48 with self.assertRaises(ValueError):
51 def test_wrong_n_coeffs(self):
52 with self.assertRaises(ValueError):
55 def test_wrong_samplerate(self):
56 with self.assertRaises(ValueError):
59 class aubio_mfcc_compute(TestCase):
61 def test_members(self):
63 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
64 #assert_equal ([o.buf_size, o.method], [buf_size, method])
69 #print "%20s" % method, str(o(spec))
71 self.assertEqual(coeffs.size, n_coeffs)
73 spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
74 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
75 #print "%20s" % method, str(o(spec))
76 self.assertEqual(count_nonzero(o(spec) != 0.), n_coeffs)
80 class aubio_mfcc_all_parameters(TestCase):
83 (2048, 40, 13, 44100),
84 (1024, 40, 13, 44100),
94 (1024, 40, 20, 44100),
95 #(1024, 30, 20, 44100),
96 (1024, 40, 40, 44100),
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__':