1 | from numpy.testing import TestCase, run_module_suite |
---|
2 | from numpy.testing import assert_equal, assert_almost_equal |
---|
3 | from _aubio import * |
---|
4 | from numpy import array |
---|
5 | |
---|
6 | def array_from_text_file(filename, dtype = 'float'): |
---|
7 | return array([line.split() for line in open(filename).readlines()], |
---|
8 | dtype = dtype) |
---|
9 | |
---|
10 | class aubio_filter_test_case(TestCase): |
---|
11 | |
---|
12 | def test_members(self): |
---|
13 | f = digital_filter() |
---|
14 | assert_equal ([f.channels, f.order, f.samplerate], [1, 7, 44100]) |
---|
15 | f = digital_filter(48000, 5, 2) |
---|
16 | assert_equal ([f.channels, f.order, f.samplerate], [2, 5, 48000]) |
---|
17 | f(fvec()) |
---|
18 | |
---|
19 | def test_cweighting_error(self): |
---|
20 | f = digital_filter (44100, 2, 1) |
---|
21 | self.assertRaises ( ValueError, f.set_c_weighting ) |
---|
22 | f = digital_filter (44100, 8, 1) |
---|
23 | self.assertRaises ( ValueError, f.set_c_weighting ) |
---|
24 | f = digital_filter (4000, 5, 1) |
---|
25 | self.assertRaises ( ValueError, f.set_c_weighting ) |
---|
26 | f = digital_filter (193000, 5, 1) |
---|
27 | self.assertRaises ( ValueError, f.set_c_weighting ) |
---|
28 | f = digital_filter (193000, 7, 1) |
---|
29 | self.assertRaises ( ValueError, f.set_a_weighting ) |
---|
30 | f = digital_filter (192000, 5, 1) |
---|
31 | self.assertRaises ( ValueError, f.set_a_weighting ) |
---|
32 | |
---|
33 | def test_c_weighting(self): |
---|
34 | expected = array_from_text_file('c_weighting_test_simple.expected') |
---|
35 | f = digital_filter(44100, 5, 1) |
---|
36 | f.set_c_weighting() |
---|
37 | v = fvec(32) |
---|
38 | v[0][12] = .5 |
---|
39 | u = f(v) |
---|
40 | assert_almost_equal (expected[1], u) |
---|
41 | |
---|
42 | def test_a_weighting(self): |
---|
43 | expected = array_from_text_file('a_weighting_test_simple.expected') |
---|
44 | f = digital_filter(44100, 7, 1) |
---|
45 | f.set_a_weighting() |
---|
46 | v = fvec(32) |
---|
47 | v[0][12] = .5 |
---|
48 | u = f(v) |
---|
49 | assert_almost_equal (expected[1], u) |
---|
50 | |
---|
51 | def test_a_weighting_parted(self): |
---|
52 | expected = array_from_text_file('a_weighting_test_simple.expected') |
---|
53 | f = digital_filter(44100, 7, 1) |
---|
54 | f.set_a_weighting() |
---|
55 | v = fvec(16) |
---|
56 | v[0][12] = .5 |
---|
57 | u = f(v) |
---|
58 | assert_almost_equal (expected[1][:16], u) |
---|
59 | # one more time |
---|
60 | v = fvec(16) |
---|
61 | u = f(v) |
---|
62 | assert_almost_equal (expected[1][16:], u) |
---|
63 | |
---|
64 | if __name__ == '__main__': |
---|
65 | from unittest import main |
---|
66 | main() |
---|
67 | |
---|