Changes in python/tests/test_cvec.py [0e362b5:0b6d23d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_cvec.py
r0e362b5 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, run_module_suite 4 from numpy.testing import assert_equal, assert_almost_equal 5 from aubio import cvec 6 from numpy import array, shape, pi 3 from unittest import main 4 import numpy as np 5 from numpy.testing import TestCase, assert_equal 6 from aubio import cvec, fvec, float_type 7 8 wrong_type = 'float32' if float_type == 'float64' else 'float64' 7 9 8 10 class aubio_cvec_test_case(TestCase): … … 10 12 def test_vector_created_with_zeroes(self): 11 13 a = cvec(10) 12 shape(a.norm)13 shape(a.phas)14 a.norm[0]14 assert_equal(a.norm.shape[0], 10 / 2 + 1) 15 assert_equal(a.phas.shape[0], 10 / 2 + 1) 16 _ = a.norm[0] 15 17 assert_equal(a.norm, 0.) 16 18 assert_equal(a.phas, 0.) … … 42 44 def test_assign_cvec_phas_slice(self): 43 45 spec = cvec(1024) 44 spec.phas[39:-1] = - pi46 spec.phas[39:-1] = -np.pi 45 47 assert_equal(spec.phas[0:39], 0) 46 assert_equal(spec.phas[39:-1], - pi)48 assert_equal(spec.phas[39:-1], -np.pi) 47 49 assert_equal(spec.norm, 0) 48 50 51 def test_assign_cvec_with_other_cvec(self): 52 """ check dest cvec is still reachable after source was deleted """ 53 spec = cvec(1024) 54 a = np.random.rand(1024//2+1).astype(float_type) 55 b = np.random.rand(1024//2+1).astype(float_type) 56 spec.norm = a 57 spec.phas = b 58 new_spec = spec 59 del spec 60 assert_equal(a, new_spec.norm) 61 assert_equal(b, new_spec.phas) 62 assert_equal(id(a), id(new_spec.norm)) 63 assert_equal(id(b), id(new_spec.phas)) 64 65 def test_pass_to_numpy(self): 66 spec = cvec(1024) 67 norm = spec.norm 68 phas = spec.phas 69 del spec 70 new_spec = cvec(1024) 71 new_spec.norm = norm 72 new_spec.phas = phas 73 assert_equal(norm, new_spec.norm) 74 assert_equal(phas, new_spec.phas) 75 assert_equal(id(norm), id(new_spec.norm)) 76 assert_equal(id(phas), id(new_spec.phas)) 77 del norm 78 del phas 79 assert_equal(new_spec.norm, 0.) 80 assert_equal(new_spec.phas, 0.) 81 del new_spec 82 83 def test_assign_norm_too_large(self): 84 a = cvec(512) 85 b = fvec(512//2+1 + 4) 86 with self.assertRaises(ValueError): 87 a.norm = b 88 89 def test_assign_norm_too_small(self): 90 a = cvec(512) 91 b = fvec(512//2+1 - 4) 92 with self.assertRaises(ValueError): 93 a.norm = b 94 95 def test_assign_phas_too_large(self): 96 a = cvec(512) 97 b = fvec(512//2+1 + 4) 98 with self.assertRaises(ValueError): 99 a.phas = b 100 101 def test_assign_phas_too_small(self): 102 a = cvec(512) 103 b = fvec(512//2+1 - 4) 104 with self.assertRaises(ValueError): 105 a.phas = b 106 107 def test_cvec_repr(self): 108 win_s = 512 109 c = cvec(win_s) 110 expected_repr = "aubio cvec of {:d} elements".format(win_s//2+1) 111 self.assertEqual(repr(c), expected_repr) 112 113 class aubio_cvec_wrong_norm_input(TestCase): 114 115 def test_wrong_length(self): 116 with self.assertRaises(ValueError): 117 cvec(-1) 118 119 def test_set_norm_with_scalar(self): 120 a = cvec(512) 121 with self.assertRaises(ValueError): 122 a.norm = 1 123 124 def test_set_norm_with_scalar_array(self): 125 a = cvec(512) 126 with self.assertRaises(ValueError): 127 a.norm = np.ndarray(1, dtype = 'int') 128 129 def test_set_norm_with_int_array(self): 130 a = cvec(512) 131 with self.assertRaises(ValueError): 132 a.norm = np.zeros(512//2+1, dtype = 'int') 133 134 def test_set_norm_with_wrong_float_array(self): 135 a = cvec(512) 136 with self.assertRaises(ValueError): 137 a.norm = np.zeros(512//2+1, dtype = wrong_type) 138 139 def test_set_norm_with_wrong_2d_array(self): 140 a = cvec(512) 141 with self.assertRaises(ValueError): 142 a.norm = np.zeros((512//2+1, 2), dtype = float_type) 143 49 144 if __name__ == '__main__': 50 from unittest import main51 145 main()
Note: See TracChangeset
for help on using the changeset viewer.