Changeset 0b6d23d for python/tests/test_musicutils.py
- Timestamp:
- May 16, 2016, 5:08:18 AM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- a6f9ebf
- Parents:
- 58a5fb9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_musicutils.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 4 import numpy as np 3 5 from numpy.testing import TestCase 4 6 from numpy.testing.utils import assert_equal, assert_almost_equal 5 from numpy import cos, arange6 from math import pi7 8 7 from aubio import window, level_lin, db_spl, silence_detection, level_detection 9 10 8 from aubio import fvec, float_type 11 9 … … 26 24 size = 1024 27 25 aubio_window = window("hanning", size) 28 numpy_window = .5 - .5 * cos(2. * pi *arange(size) / size)26 numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size) 29 27 assert_almost_equal(aubio_window, numpy_window) 30 28 … … 34 32 35 33 def test_fail_not_fvec(self): 36 try:34 with self.assertRaises(ValueError): 37 35 level_lin("default") 38 except ValueError as e:39 pass40 else:41 self.fail('non-number input phase does not raise a TypeError')42 36 43 37 def test_zeros_is_zeros(self): … … 45 39 46 40 def test_minus_ones_is_one(self): 47 from numpy import ones 48 assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.) 41 assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.) 49 42 50 43 class aubio_db_spl(TestCase): … … 53 46 54 47 def test_fail_not_fvec(self): 55 try:48 with self.assertRaises(ValueError): 56 49 db_spl("default") 57 except ValueError as e:58 pass59 else:60 self.fail('non-number input phase does not raise a TypeError')61 50 62 51 def test_zeros_is_inf(self): 63 from math import isinf 64 assert isinf(db_spl(fvec(1024))) 52 assert np.isinf(db_spl(fvec(1024))) 65 53 66 54 def test_minus_ones_is_zero(self): 67 from numpy import ones 68 assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.) 55 assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.) 69 56 70 57 class aubio_silence_detection(TestCase): … … 73 60 74 61 def test_fail_not_fvec(self): 75 try:62 with self.assertRaises(ValueError): 76 63 silence_detection("default", -70) 77 except ValueError as e:78 pass79 else:80 self.fail('non-number input phase does not raise a TypeError')81 64 82 65 def test_zeros_is_one(self): 83 from math import isinf84 66 assert silence_detection(fvec(1024), -70) == 1 85 67 … … 93 75 94 76 def test_fail_not_fvec(self): 95 try:77 with self.assertRaises(ValueError): 96 78 level_detection("default", -70) 97 except ValueError as e:98 pass99 else:100 self.fail('non-number input phase does not raise a TypeError')101 79 102 80 def test_zeros_is_one(self): 103 from math import isinf104 81 assert level_detection(fvec(1024), -70) == 1 105 82 … … 109 86 110 87 if __name__ == '__main__': 111 from unittest import main112 88 main()
Note: See TracChangeset
for help on using the changeset viewer.