History

python/tests/test_mfcc.py: add more tests

Paul Brossier committed 10 years ago

Commit b6b65cb1 parent aba02791 file · +110 −0Browse files

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

Unified · Split

python/tests/test_mfcc.py+110−0
@@ -0,0 +1,110 @@
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from numpy import random, arange, log, zeros, count_nonzero
5from aubio import mfcc, cvec, float_type
6from math import pi
7
8buf_size = 2048
9n_filters = 40
10n_coeffs = 13
11samplerate = 44100
12
13from nose2.tools import params
14
15new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
16new_deflts = [1024, 40, 13, 44100]
17
18class aubio_mfcc(TestCase):
19
20 def setUp(self):
21 self.o = mfcc()
22
23 def test_default_creation(self):
24 pass
25
26 def test_delete(self):
27 del self.o
28
29 @params(*new_params)
30 def test_read_only_member(self, name):
31 o = self.o
32 with self.assertRaises((TypeError, AttributeError)):
33 setattr(o, name, 0)
34
35 @params(*zip(new_params, new_deflts))
36 def test_default_param(self, name, expected):
37 """ test mfcc.{:s} = {:d} """.format(name, expected)
38 o = self.o
39 self.assertEqual( getattr(o, name), expected)
40
41class aubio_mfcc_wrong_params(TestCase):
42
43 def test_wrong_buf_size(self):
44 with self.assertRaises(ValueError):
45 mfcc(buf_size = -1)
46
47 def test_wrong_n_filters(self):
48 with self.assertRaises(ValueError):
49 mfcc(n_filters = -1)
50
51 def test_wrong_n_coeffs(self):
52 with self.assertRaises(ValueError):
53 mfcc(n_coeffs = -1)
54
55 def test_wrong_samplerate(self):
56 with self.assertRaises(ValueError):
57 mfcc(samplerate = -1)
58
59class aubio_mfcc_compute(TestCase):
60
61 def test_members(self):
62
63 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
64 #assert_equal ([o.buf_size, o.method], [buf_size, method])
65
66 spec = cvec(buf_size)
67 #spec.norm[0] = 1
68 #spec.norm[1] = 1./2.
69 #print "%20s" % method, str(o(spec))
70 coeffs = o(spec)
71 self.assertEqual(coeffs.size, n_coeffs)
72 #print 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)
77 #print coeffs
78
79
80class aubio_mfcc_all_parameters(TestCase):
81
82 @params(
83 (2048, 40, 13, 44100),
84 (1024, 40, 13, 44100),
85 (512, 40, 13, 44100),
86 (512, 40, 13, 16000),
87 (256, 40, 13, 16000),
88 (128, 40, 13, 16000),
89 (128, 40, 12, 16000),
90 (128, 40, 13, 15000),
91 (512, 40, 20, 44100),
92 (512, 40, 40, 44100),
93 (512, 40, 3, 44100),
94 (1024, 40, 20, 44100),
95 #(1024, 30, 20, 44100),
96 (1024, 40, 40, 44100),
97 (1024, 40, 3, 44100),
98 )
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)
103 spec.phas[0] = 0.2
104 for i in range(10):
105 coeffs = o(spec)
106 #print coeffs
107
108if __name__ == '__main__':
109 import nose2
110 nose2.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