Changes in python/tests/test_cvec.py [0b6d23d:0e362b5]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_cvec.py
r0b6d23d r0e362b5 1 1 #! /usr/bin/env python 2 2 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' 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 9 7 10 8 class aubio_cvec_test_case(TestCase): … … 12 10 def test_vector_created_with_zeroes(self): 13 11 a = cvec(10) 14 assert_equal(a.norm.shape[0], 10 / 2 + 1)15 assert_equal(a.phas.shape[0], 10 / 2 + 1)16 _ =a.norm[0]12 shape(a.norm) 13 shape(a.phas) 14 a.norm[0] 17 15 assert_equal(a.norm, 0.) 18 16 assert_equal(a.phas, 0.) … … 44 42 def test_assign_cvec_phas_slice(self): 45 43 spec = cvec(1024) 46 spec.phas[39:-1] = - np.pi44 spec.phas[39:-1] = -pi 47 45 assert_equal(spec.phas[0:39], 0) 48 assert_equal(spec.phas[39:-1], - np.pi)46 assert_equal(spec.phas[39:-1], -pi) 49 47 assert_equal(spec.norm, 0) 50 48 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 = a57 spec.phas = b58 new_spec = spec59 del spec60 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.norm68 phas = spec.phas69 del spec70 new_spec = cvec(1024)71 new_spec.norm = norm72 new_spec.phas = phas73 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 norm78 del phas79 assert_equal(new_spec.norm, 0.)80 assert_equal(new_spec.phas, 0.)81 del new_spec82 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 = b88 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 = b94 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 = b100 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 = b106 107 def test_cvec_repr(self):108 win_s = 512109 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 = 1123 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 144 49 if __name__ == '__main__': 50 from unittest import main 145 51 main()
Note: See TracChangeset
for help on using the changeset viewer.