source: python/tests/test_filter.py @ ff28d81

feature/autosinkfeature/constantqfeature/pitchshiftfeature/timestretch
Last change on this file since ff28d81 was d4fae34, checked in by Paul Brossier <piem@piem.org>, 14 months ago

[tests] remove init.py, use absolute imports

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