source: python/tests/test_musicutils.py @ 9492ec88

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since 9492ec88 was 0b6d23d, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/tests: fix most prospect warnings

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