source: python/tests/test_musicutils.py @ 1164fd85

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

python/tests/test_musicutils.py: simplify, check TypeError? is raised

  • Property mode set to 100755
File size: 3.2 KB
RevLine 
[913a7f1]1#! /usr/bin/env python
2
3from numpy.testing import TestCase
[5a7e2c3]4from numpy.testing.utils import assert_equal, assert_almost_equal
5from numpy import cos, arange
6from math import pi
7
[9c8c8a6]8from aubio import window, level_lin, db_spl, silence_detection, level_detection
[5a7e2c3]9
[c4b2183]10from aubio import fvec, float_type
[913a7f1]11
12class aubio_window(TestCase):
13
14    def test_accept_name_and_size(self):
15        window("default", 1024)
16
[5e394ecc]17    def test_fail_name_not_string(self):
[98e4106]18        with self.assertRaises(TypeError):
[5e394ecc]19            window(10, 1024)
20
21    def test_fail_size_not_int(self):
[98e4106]22        with self.assertRaises(TypeError):
[5e394ecc]23            window("default", "default")
24
[efa62ce]25    def test_compute_hanning_1024(self):
26        size = 1024
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)
30
[5a7e2c3]31class aubio_level_lin(TestCase):
32    def test_accept_fvec(self):
33        level_lin(fvec(1024))
34
35    def test_fail_not_fvec(self):
36        try:
37            level_lin("default")
[689106e]38        except ValueError as e:
[5a7e2c3]39            pass
40        else:
41            self.fail('non-number input phase does not raise a TypeError')
42
43    def test_zeros_is_zeros(self):
44        assert_equal(level_lin(fvec(1024)), 0.)
45
46    def test_minus_ones_is_one(self):
47        from numpy import ones
[c4b2183]48        assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.)
[5a7e2c3]49
[4615886a]50class aubio_db_spl(TestCase):
51    def test_accept_fvec(self):
52        db_spl(fvec(1024))
53
54    def test_fail_not_fvec(self):
55        try:
56            db_spl("default")
[689106e]57        except ValueError as e:
[4615886a]58            pass
59        else:
60            self.fail('non-number input phase does not raise a TypeError')
61
62    def test_zeros_is_inf(self):
63        from math import isinf
64        assert isinf(db_spl(fvec(1024)))
65
66    def test_minus_ones_is_zero(self):
67        from numpy import ones
[c4b2183]68        assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.)
[4615886a]69
[31a09d2]70class aubio_silence_detection(TestCase):
71    def test_accept_fvec(self):
72        silence_detection(fvec(1024), -70.)
73
74    def test_fail_not_fvec(self):
75        try:
76            silence_detection("default", -70)
[689106e]77        except ValueError as e:
[31a09d2]78            pass
79        else:
80            self.fail('non-number input phase does not raise a TypeError')
81
82    def test_zeros_is_one(self):
83        from math import isinf
84        assert silence_detection(fvec(1024), -70) == 1
85
86    def test_minus_ones_is_zero(self):
87        from numpy import ones
[c4b2183]88        assert silence_detection(ones(1024, dtype = float_type), -70) == 0
[31a09d2]89
[9c8c8a6]90class aubio_level_detection(TestCase):
91    def test_accept_fvec(self):
92        level_detection(fvec(1024), -70.)
93
94    def test_fail_not_fvec(self):
95        try:
96            level_detection("default", -70)
[689106e]97        except ValueError as e:
[9c8c8a6]98            pass
99        else:
100            self.fail('non-number input phase does not raise a TypeError')
101
102    def test_zeros_is_one(self):
103        from math import isinf
104        assert level_detection(fvec(1024), -70) == 1
105
106    def test_minus_ones_is_zero(self):
107        from numpy import ones
[c4b2183]108        assert level_detection(ones(1024, dtype = float_type), -70) == 0
[9c8c8a6]109
[913a7f1]110if __name__ == '__main__':
111    from unittest import main
112    main()
Note: See TracBrowser for help on using the repository browser.