Changeset c4b2183 for python/tests/test_fvec.py
- Timestamp:
- Apr 25, 2016, 12:53:03 AM (8 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:
- 8bffcff
- Parents:
- fbcee4f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_fvec.py
rfbcee4f rc4b2183 4 4 from numpy.testing import assert_equal, assert_almost_equal 5 5 from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal 6 from aubio import float_type 6 7 from numpy import array, shape 8 9 wrong_type = 'float32' if float_type == 'float64' else 'float64' 7 10 8 11 default_size = 512 … … 12 15 def test_vector_created_with_zeroes(self): 13 16 a = fvec(10) 14 assert a.dtype == 'float32'17 assert a.dtype == float_type 15 18 assert a.shape == (10,) 16 19 assert_equal (a, 0) … … 18 21 def test_vector_create_with_list(self): 19 22 a = fvec([0,1,2,3]) 20 assert a.dtype == 'float32'23 assert a.dtype == float_type 21 24 assert a.shape == (4,) 22 25 assert_equal (list(range(4)), a) … … 58 61 a[1] = 1 59 62 self.assertEqual (alpha_norm(a, 1), 1) 60 a = array([0, 1], dtype= 'float32')63 a = array([0, 1], dtype=float_type) 61 64 from math import sqrt 62 65 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.) … … 67 70 def test_alpha_norm_of_array_of_float32(self): 68 71 # check scalar fails 69 a = array(1, dtype = 'float32')72 a = array(1, dtype = float_type) 70 73 self.assertRaises (ValueError, alpha_norm, a, 1) 71 74 # check 2d array fails 72 a = array([[2],[4]], dtype = 'float32')75 a = array([[2],[4]], dtype = float_type) 73 76 self.assertRaises (ValueError, alpha_norm, a, 1) 74 77 # check 1d array 75 a = array(range(10), dtype = 'float32')78 a = array(range(10), dtype = float_type) 76 79 self.assertEqual (alpha_norm(a, 1), 4.5) 77 80 … … 89 92 90 93 def test_zero_crossing_rate(self): 91 a = array([0,1,-1], dtype= 'float32')94 a = array([0,1,-1], dtype=float_type) 92 95 assert_almost_equal (zero_crossing_rate(a), 1./3. ) 93 a = array([0.]*100, dtype= 'float32')96 a = array([0.]*100, dtype=float_type) 94 97 self.assertEqual (zero_crossing_rate(a), 0 ) 95 a = array([-1.]*100, dtype= 'float32')98 a = array([-1.]*100, dtype=float_type) 96 99 self.assertEqual (zero_crossing_rate(a), 0 ) 97 a = array([1.]*100, dtype= 'float32')100 a = array([1.]*100, dtype=float_type) 98 101 self.assertEqual (zero_crossing_rate(a), 0 ) 99 102 100 103 def test_alpha_norm_of_array_of_float64(self): 101 104 # check scalar fail 102 a = array(1, dtype = 'float64')105 a = array(1, dtype = wrong_type) 103 106 self.assertRaises (ValueError, alpha_norm, a, 1) 104 107 # check 3d array fail 105 a = array([[[1,2],[3,4]]], dtype = 'float64')108 a = array([[[1,2],[3,4]]], dtype = wrong_type) 106 109 self.assertRaises (ValueError, alpha_norm, a, 1) 107 110 # check float64 1d array fail 108 a = array(list(range(10)), dtype = 'float64')111 a = array(list(range(10)), dtype = wrong_type) 109 112 self.assertRaises (ValueError, alpha_norm, a, 1) 110 113 # check float64 2d array fail 111 a = array([list(range(10)), list(range(10))], dtype = 'float64')114 a = array([list(range(10)), list(range(10))], dtype = wrong_type) 112 115 self.assertRaises (ValueError, alpha_norm, a, 1) 113 116 114 117 def test_fvec_min_removal_of_array(self): 115 a = array([20,1,19], dtype= 'float32')118 a = array([20,1,19], dtype=float_type) 116 119 b = min_removal(a) 117 120 assert_equal (array(b), [19, 0, 18]) … … 122 125 123 126 def test_fvec_min_removal_of_array_float64(self): 124 a = array([20,1,19], dtype= 'float64')127 a = array([20,1,19], dtype=wrong_type) 125 128 self.assertRaises (ValueError, min_removal, a) 126 129 127 130 def test_fvec_min_removal_of_fvec(self): 128 131 a = fvec(3) 129 a = array([20, 1, 19], dtype = 'float32')132 a = array([20, 1, 19], dtype = float_type) 130 133 b = min_removal(a) 131 134 assert_equal (array(b), [19, 0, 18])
Note: See TracChangeset
for help on using the changeset viewer.