source: python/tests/test_musicutils.py @ 4b33381

Last change on this file since 4b33381 was 2e005cc, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] update numpy.testing import

  • Property mode set to 100755
File size: 2.6 KB
RevLine 
[913a7f1]1#! /usr/bin/env python
2
[0b6d23d]3import numpy as np
[913a7f1]4from numpy.testing import TestCase
[2e005cc]5from numpy.testing import assert_equal, assert_almost_equal
[9c8c8a6]6from aubio import window, level_lin, db_spl, silence_detection, level_detection
[c4b2183]7from aubio import fvec, float_type
[913a7f1]8
9class aubio_window(TestCase):
10
11    def test_accept_name_and_size(self):
12        window("default", 1024)
13
[5e394ecc]14    def test_fail_name_not_string(self):
[98e4106]15        with self.assertRaises(TypeError):
[5e394ecc]16            window(10, 1024)
17
18    def test_fail_size_not_int(self):
[98e4106]19        with self.assertRaises(TypeError):
[5e394ecc]20            window("default", "default")
21
[efa62ce]22    def test_compute_hanning_1024(self):
23        size = 1024
24        aubio_window = window("hanning", size)
[0b6d23d]25        numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size)
[efa62ce]26        assert_almost_equal(aubio_window, numpy_window)
27
[5a7e2c3]28class aubio_level_lin(TestCase):
29    def test_accept_fvec(self):
30        level_lin(fvec(1024))
31
32    def test_fail_not_fvec(self):
[0b6d23d]33        with self.assertRaises(ValueError):
[5a7e2c3]34            level_lin("default")
35
36    def test_zeros_is_zeros(self):
37        assert_equal(level_lin(fvec(1024)), 0.)
38
39    def test_minus_ones_is_one(self):
[0b6d23d]40        assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.)
[5a7e2c3]41
[4615886a]42class aubio_db_spl(TestCase):
43    def test_accept_fvec(self):
44        db_spl(fvec(1024))
45
46    def test_fail_not_fvec(self):
[0b6d23d]47        with self.assertRaises(ValueError):
[4615886a]48            db_spl("default")
49
50    def test_zeros_is_inf(self):
[0b6d23d]51        assert np.isinf(db_spl(fvec(1024)))
[4615886a]52
53    def test_minus_ones_is_zero(self):
[0b6d23d]54        assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.)
[4615886a]55
[31a09d2]56class aubio_silence_detection(TestCase):
57    def test_accept_fvec(self):
58        silence_detection(fvec(1024), -70.)
59
60    def test_fail_not_fvec(self):
[0b6d23d]61        with self.assertRaises(ValueError):
[31a09d2]62            silence_detection("default", -70)
63
64    def test_zeros_is_one(self):
65        assert silence_detection(fvec(1024), -70) == 1
66
67    def test_minus_ones_is_zero(self):
68        from numpy import ones
[c4b2183]69        assert silence_detection(ones(1024, dtype = float_type), -70) == 0
[31a09d2]70
[9c8c8a6]71class aubio_level_detection(TestCase):
72    def test_accept_fvec(self):
73        level_detection(fvec(1024), -70.)
74
75    def test_fail_not_fvec(self):
[0b6d23d]76        with self.assertRaises(ValueError):
[9c8c8a6]77            level_detection("default", -70)
78
79    def test_zeros_is_one(self):
80        assert level_detection(fvec(1024), -70) == 1
81
82    def test_minus_ones_is_zero(self):
83        from numpy import ones
[c4b2183]84        assert level_detection(ones(1024, dtype = float_type), -70) == 0
[9c8c8a6]85
[913a7f1]86if __name__ == '__main__':
[319edae]87    from unittest import main
[913a7f1]88    main()
Note: See TracBrowser for help on using the repository browser.