Changeset 146280a for interfaces
- Timestamp:
- Oct 2, 2009, 3:38:30 PM (15 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:
- ccf8b77
- Parents:
- 207ed19
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/test_aubio.py
r207ed19 r146280a 1 import unittest 1 from numpy.testing import TestCase, run_module_suite 2 from numpy.testing import assert_equal as numpy_assert_equal 2 3 from _aubio import * 3 4 from numpy import array 4 5 5 class aubiomodule_test_case(unittest.TestCase): 6 AUBIO_DO_CASTING = 0 7 8 def assert_equal(a, b): 9 numpy_assert_equal(array(a),array(b)) 10 11 class aubiomodule_test_case(TestCase): 6 12 7 13 def setUp(self): … … 38 44 39 45 def test_alpha_norm_of_array_of_float32(self): 46 # check scalar fails 40 47 a = array(1, dtype = 'float32') 41 48 self.assertRaises (ValueError, alpha_norm, a, 1) 49 # check 3d array fails 42 50 a = array([[[1,2],[3,4]]], dtype = 'float32') 43 51 self.assertRaises (ValueError, alpha_norm, a, 1) 52 # check 1d array 44 53 a = array(range(10), dtype = 'float32') 45 54 self.assertEquals (alpha_norm(a, 1), 4.5) 55 # check 2d array 46 56 a = array([range(10), range(10)], dtype = 'float32') 47 self.assertEquals (alpha_norm(a, 1), 9)48 49 def test_alpha_norm_of_array_of_float64(self):50 a = array(1, dtype = 'float64')51 self.assertRaises (ValueError, alpha_norm, a, 1)52 a = array([[[1,2],[3,4]]], dtype = 'float64')53 self.assertRaises (ValueError, alpha_norm, a, 1)54 a = array(range(10), dtype = 'float64')55 self.assertEquals (alpha_norm(a, 1), 4.5)56 a = array([range(10), range(10)], dtype = 'float64')57 57 self.assertEquals (alpha_norm(a, 1), 9) 58 58 … … 69 69 self.assertRaises (ValueError, alpha_norm, a, 1) 70 70 71 def test_zero_crossing_rate(self): 72 a = array([0,1,-1], dtype='float32') 73 self.assertEquals (zero_crossing_rate(a), 1./3 ) 74 a = array([0.]*100, dtype='float32') 75 self.assertEquals (zero_crossing_rate(a), 0 ) 76 a = array([-1.]*100, dtype='float32') 77 self.assertEquals (zero_crossing_rate(a), 0 ) 78 a = array([1.]*100, dtype='float32') 79 self.assertEquals (zero_crossing_rate(a), 0 ) 80 81 def test_alpha_norm_of_array_of_float64(self): 82 # check scalar fail 83 a = array(1, dtype = 'float64') 84 self.assertRaises (ValueError, alpha_norm, a, 1) 85 # check 3d array fail 86 a = array([[[1,2],[3,4]]], dtype = 'float64') 87 self.assertRaises (ValueError, alpha_norm, a, 1) 88 if AUBIO_DO_CASTING: 89 # check float64 1d array fail 90 a = array(range(10), dtype = 'float64') 91 self.assertEquals (alpha_norm(a, 1), 4.5) 92 # check float64 2d array fail 93 a = array([range(10), range(10)], dtype = 'float64') 94 self.assertEquals (alpha_norm(a, 1), 9) 95 else: 96 # check float64 1d array fail 97 a = array(range(10), dtype = 'float64') 98 self.assertRaises (ValueError, alpha_norm, a, 1) 99 # check float64 2d array fail 100 a = array([range(10), range(10)], dtype = 'float64') 101 self.assertRaises (ValueError, alpha_norm, a, 1) 102 103 def test_fvec_min_removal_of_array(self): 104 a = array([20,1,19], dtype='float32') 105 b = min_removal(a) 106 assert_equal (array(b), [19, 0, 18]) 107 assert_equal (b, [19, 0, 18]) 108 assert_equal (a, b) 109 a[0] = 0 110 assert_equal (a, b) 111 112 def test_fvec_min_removal_of_array_float64(self): 113 a = array([20,1,19], dtype='float64') 114 if AUBIO_DO_CASTING: 115 b = min_removal(a) 116 assert_equal (array(b), [19, 0, 18]) 117 assert_equal (b, [19, 0, 18]) 118 #assert_equal (a, b) 119 else: 120 self.assertRaises (ValueError, min_removal, a) 121 122 def test_fvec_min_removal_of_fvec(self): 123 a = fvec(3, 1) 124 a[0] = [20, 1, 19] 125 b = min_removal(a) 126 assert_equal (array(b), [19, 0, 18]) 127 assert_equal (b, [19, 0, 18]) 128 assert_equal (a, b) 129 71 130 if __name__ == '__main__': 72 unittest.main() 131 from unittest import main 132 main() 133
Note: See TracChangeset
for help on using the changeset viewer.