3 from numpy.testing import TestCase
4 from numpy.testing.utils import assert_equal, assert_almost_equal
5 from numpy import cos, arange
8 from aubio import window, level_lin, db_spl, silence_detection, level_detection
10 from aubio import fvec, float_type
12 class aubio_window(TestCase):
14 def test_accept_name_and_size(self):
15 window("default", 1024)
17 def test_fail_name_not_string(self):
18 with self.assertRaises(TypeError):
21 def test_fail_size_not_int(self):
22 with self.assertRaises(TypeError):
23 window("default", "default")
25 def test_compute_hanning_1024(self):
27 aubio_window = window("hanning", size)
28 numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size)
29 assert_almost_equal(aubio_window, numpy_window)
31 class aubio_level_lin(TestCase):
32 def test_accept_fvec(self):
35 def test_fail_not_fvec(self):
38 except ValueError as e:
41 self.fail('non-number input phase does not raise a TypeError')
43 def test_zeros_is_zeros(self):
44 assert_equal(level_lin(fvec(1024)), 0.)
46 def test_minus_ones_is_one(self):
47 from numpy import ones
48 assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.)
50 class aubio_db_spl(TestCase):
51 def test_accept_fvec(self):
54 def test_fail_not_fvec(self):
57 except ValueError as e:
60 self.fail('non-number input phase does not raise a TypeError')
62 def test_zeros_is_inf(self):
63 from math import isinf
64 assert isinf(db_spl(fvec(1024)))
66 def test_minus_ones_is_zero(self):
67 from numpy import ones
68 assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.)
70 class aubio_silence_detection(TestCase):
71 def test_accept_fvec(self):
72 silence_detection(fvec(1024), -70.)
74 def test_fail_not_fvec(self):
76 silence_detection("default", -70)
77 except ValueError as e:
80 self.fail('non-number input phase does not raise a TypeError')
82 def test_zeros_is_one(self):
83 from math import isinf
84 assert silence_detection(fvec(1024), -70) == 1
86 def test_minus_ones_is_zero(self):
87 from numpy import ones
88 assert silence_detection(ones(1024, dtype = float_type), -70) == 0
90 class aubio_level_detection(TestCase):
91 def test_accept_fvec(self):
92 level_detection(fvec(1024), -70.)
94 def test_fail_not_fvec(self):
96 level_detection("default", -70)
97 except ValueError as e:
100 self.fail('non-number input phase does not raise a TypeError')
102 def test_zeros_is_one(self):
103 from math import isinf
104 assert level_detection(fvec(1024), -70) == 1
106 def test_minus_ones_is_zero(self):
107 from numpy import ones
108 assert level_detection(ones(1024, dtype = float_type), -70) == 0
110 if __name__ == '__main__':
111 from unittest import main