3 from unittest import main
5 from numpy.testing import TestCase
6 from numpy.testing.utils import assert_equal, assert_almost_equal
7 from aubio import window, level_lin, db_spl, silence_detection, level_detection
8 from aubio import fvec, float_type
10 class aubio_window(TestCase):
12 def test_accept_name_and_size(self):
13 window("default", 1024)
15 def test_fail_name_not_string(self):
16 with self.assertRaises(TypeError):
19 def test_fail_size_not_int(self):
20 with self.assertRaises(TypeError):
21 window("default", "default")
23 def test_compute_hanning_1024(self):
25 aubio_window = window("hanning", size)
26 numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size)
27 assert_almost_equal(aubio_window, numpy_window)
29 class aubio_level_lin(TestCase):
30 def test_accept_fvec(self):
33 def test_fail_not_fvec(self):
34 with self.assertRaises(ValueError):
37 def test_zeros_is_zeros(self):
38 assert_equal(level_lin(fvec(1024)), 0.)
40 def test_minus_ones_is_one(self):
41 assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.)
43 class aubio_db_spl(TestCase):
44 def test_accept_fvec(self):
47 def test_fail_not_fvec(self):
48 with self.assertRaises(ValueError):
51 def test_zeros_is_inf(self):
52 assert np.isinf(db_spl(fvec(1024)))
54 def test_minus_ones_is_zero(self):
55 assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.)
57 class aubio_silence_detection(TestCase):
58 def test_accept_fvec(self):
59 silence_detection(fvec(1024), -70.)
61 def test_fail_not_fvec(self):
62 with self.assertRaises(ValueError):
63 silence_detection("default", -70)
65 def test_zeros_is_one(self):
66 assert silence_detection(fvec(1024), -70) == 1
68 def test_minus_ones_is_zero(self):
69 from numpy import ones
70 assert silence_detection(ones(1024, dtype = float_type), -70) == 0
72 class aubio_level_detection(TestCase):
73 def test_accept_fvec(self):
74 level_detection(fvec(1024), -70.)
76 def test_fail_not_fvec(self):
77 with self.assertRaises(ValueError):
78 level_detection("default", -70)
80 def test_zeros_is_one(self):
81 assert level_detection(fvec(1024), -70) == 1
83 def test_minus_ones_is_zero(self):
84 from numpy import ones
85 assert level_detection(ones(1024, dtype = float_type), -70) == 0
87 if __name__ == '__main__':