source: python/tests/test_filter.py @ 7982203

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 7982203 was a4cc8e5, checked in by Paul Brossier <piem@piem.org>, 12 years ago

tests/: array_from_file to look for file in tests/

  • Property mode set to 100755
File size: 2.1 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 numpy import array
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
71if __name__ == '__main__':
72  from unittest import main
73  main()
74
Note: See TracBrowser for help on using the repository browser.