source: python/tests/test_filter.py @ fa0ef3b

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since fa0ef3b was a1bf01d, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/tests/: use local import, create init.py

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#! /usr/bin/env python
2
3from unittest import main
4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from aubio import fvec, digital_filter
6from .utils import array_from_text_file
7
8class aubio_filter_test_case(TestCase):
9
10    def test_members(self):
11        f = digital_filter()
12        assert_equal (f.order, 7)
13        f = digital_filter(5)
14        assert_equal (f.order, 5)
15        f(fvec())
16
17    def test_cweighting_error(self):
18        f = digital_filter (2)
19        self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
20        f = digital_filter (8)
21        self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
22        f = digital_filter (5)
23        self.assertRaises ( ValueError, f.set_c_weighting, 4000 )
24        f = digital_filter (5)
25        self.assertRaises ( ValueError, f.set_c_weighting, 193000 )
26        f = digital_filter (7)
27        self.assertRaises ( ValueError, f.set_a_weighting, 193000 )
28        f = digital_filter (5)
29        self.assertRaises ( ValueError, f.set_a_weighting, 192000 )
30
31    def test_c_weighting(self):
32        expected = array_from_text_file('c_weighting_test_simple.expected')
33        f = digital_filter(5)
34        f.set_c_weighting(44100)
35        v = fvec(32)
36        v[12] = .5
37        u = f(v)
38        assert_almost_equal (expected[1], u)
39
40    def test_c_weighting_8000(self):
41        expected = array_from_text_file('c_weighting_test_simple_8000.expected')
42        f = digital_filter(5)
43        f.set_c_weighting(8000)
44        v = fvec(32)
45        v[12] = .5
46        u = f(v)
47        assert_almost_equal (expected[1], u)
48
49    def test_a_weighting(self):
50        expected = array_from_text_file('a_weighting_test_simple.expected')
51        f = digital_filter(7)
52        f.set_a_weighting(44100)
53        v = fvec(32)
54        v[12] = .5
55        u = f(v)
56        assert_almost_equal (expected[1], u)
57
58    def test_a_weighting_parted(self):
59        expected = array_from_text_file('a_weighting_test_simple.expected')
60        f = digital_filter(7)
61        f.set_a_weighting(44100)
62        v = fvec(16)
63        v[12] = .5
64        u = f(v)
65        assert_almost_equal (expected[1][:16], u)
66        # one more time
67        v = fvec(16)
68        u = f(v)
69        assert_almost_equal (expected[1][16:], u)
70
71    def test_set_biquad(self):
72        f = digital_filter(3)
73        f.set_biquad(0., 0., 0, 0., 0.)
74
75    def test_set_biquad_wrong_order(self):
76        f = digital_filter(4)
77        with self.assertRaises(ValueError):
78            f.set_biquad(0., 0., 0, 0., 0.)
79
80class aubio_filter_wrong_params(TestCase):
81
82    def test_negative_order(self):
83        with self.assertRaises(ValueError):
84            digital_filter(-1)
85
86if __name__ == '__main__':
87    main()
Note: See TracBrowser for help on using the repository browser.