source: interfaces/python/test_filter.py @ 577cb49

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

test_filter.py: clean up

  • Property mode set to 100755
File size: 1.9 KB
Line 
1#! /usr/bin/python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, digital_filter
5from numpy import array
6
7def array_from_text_file(filename, dtype = 'float'):
8  return array([line.split() for line in open(filename).readlines()], 
9      dtype = dtype)
10
11class aubio_filter_test_case(TestCase):
12
13  def test_members(self):
14    f = digital_filter()
15    assert_equal (f.order, 7)
16    f = digital_filter(5)
17    assert_equal (f.order, 5)
18    f(fvec())
19 
20  def test_cweighting_error(self):
21    f = digital_filter (2)
22    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
23    f = digital_filter (8)
24    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
25    f = digital_filter (5)
26    self.assertRaises ( ValueError, f.set_c_weighting, 4000 )
27    f = digital_filter (5)
28    self.assertRaises ( ValueError, f.set_c_weighting, 193000 )
29    f = digital_filter (7)
30    self.assertRaises ( ValueError, f.set_a_weighting, 193000 )
31    f = digital_filter (5)
32    self.assertRaises ( ValueError, f.set_a_weighting, 192000 )
33
34  def test_c_weighting(self):
35    expected = array_from_text_file('c_weighting_test_simple.expected')
36    f = digital_filter(5)
37    f.set_c_weighting(44100)
38    v = fvec(32)
39    v[12] = .5
40    u = f(v)
41    assert_almost_equal (expected[1], u)
42
43  def test_a_weighting(self):
44    expected = array_from_text_file('a_weighting_test_simple.expected')
45    f = digital_filter(7)
46    f.set_a_weighting(44100)
47    v = fvec(32)
48    v[12] = .5
49    u = f(v)
50    assert_almost_equal (expected[1], u)
51
52  def test_a_weighting_parted(self):
53    expected = array_from_text_file('a_weighting_test_simple.expected')
54    f = digital_filter(7)
55    f.set_a_weighting(44100)
56    v = fvec(16)
57    v[12] = .5
58    u = f(v)
59    assert_almost_equal (expected[1][:16], u)
60    # one more time
61    v = fvec(16)
62    u = f(v)
63    assert_almost_equal (expected[1][16:], u)
64
65if __name__ == '__main__':
66  from unittest import main
67  main()
68
Note: See TracBrowser for help on using the repository browser.