4 from numpy.testing import TestCase
5 from numpy.testing import assert_equal, assert_almost_equal
6 from aubio import window, level_lin, db_spl, silence_detection, level_detection
7 from aubio import fvec, float_type
9 class aubio_window(TestCase):
11 def test_accept_name_and_size(self):
12 window("default", 1024)
14 def test_fail_name_not_string(self):
15 with self.assertRaises(TypeError):
18 def test_fail_size_not_int(self):
19 with self.assertRaises(TypeError):
20 window("default", "default")
22 def test_compute_hanning_1024(self):
24 aubio_window = window("hanning", size)
25 numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size)
26 assert_almost_equal(aubio_window, numpy_window)
28 class aubio_level_lin(TestCase):
29 def test_accept_fvec(self):
32 def test_fail_not_fvec(self):
33 with self.assertRaises(ValueError):
36 def test_zeros_is_zeros(self):
37 assert_equal(level_lin(fvec(1024)), 0.)
39 def test_minus_ones_is_one(self):
40 assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.)
42 class aubio_db_spl(TestCase):
43 def test_accept_fvec(self):
46 def test_fail_not_fvec(self):
47 with self.assertRaises(ValueError):
50 def test_zeros_is_inf(self):
51 assert np.isinf(db_spl(fvec(1024)))
53 def test_minus_ones_is_zero(self):
54 assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.)
56 class aubio_silence_detection(TestCase):
57 def test_accept_fvec(self):
58 silence_detection(fvec(1024), -70.)
60 def test_fail_not_fvec(self):
61 with self.assertRaises(ValueError):
62 silence_detection("default", -70)
64 def test_zeros_is_one(self):
65 assert silence_detection(fvec(1024), -70) == 1
67 def test_minus_ones_is_zero(self):
68 from numpy import ones
69 assert silence_detection(ones(1024, dtype = float_type), -70) == 0
71 class aubio_level_detection(TestCase):
72 def test_accept_fvec(self):
73 level_detection(fvec(1024), -70.)
75 def test_fail_not_fvec(self):
76 with self.assertRaises(ValueError):
77 level_detection("default", -70)
79 def test_zeros_is_one(self):
80 assert level_detection(fvec(1024), -70) == 1
82 def test_minus_ones_is_zero(self):
83 from numpy import ones
84 assert level_detection(ones(1024, dtype = float_type), -70) == 0
86 if __name__ == '__main__':
87 from unittest import main