History

python/tests/test_cvec.py: add more tests

Paul Brossier committed 10 years ago

Commit c09efca1 parent 1164fd81 file · +41 −2Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/test_cvec.py+41−2
@@ -5,6 +5,8 @@ from numpy.testing import assert_equal, assert_almost_equal · 4 unmodified lines
5from aubio import cvec, fvec, float_type5from aubio import cvec, fvec, float_type
6import numpy as np6import numpy as np
7 7
8wrong_type = 'float32' if float_type == 'float64' else 'float64'
9
8class aubio_cvec_test_case(TestCase):10class aubio_cvec_test_case(TestCase):
9 11
10 def test_vector_created_with_zeroes(self):12 def test_vector_created_with_zeroes(self):
@@ -49,8 +51,8 @@ class aubio_cvec_test_case(TestCase): · 38 unmodified lines
49 def test_assign_cvec_with_other_cvec(self):51 def test_assign_cvec_with_other_cvec(self):
50 """ check dest cvec is still reachable after source was deleted """52 """ check dest cvec is still reachable after source was deleted """
51 spec = cvec(1024)53 spec = cvec(1024)
52 a = np.random.rand(1024/2+1).astype(float_type)54 a = np.random.rand(1024//2+1).astype(float_type)
53 b = np.random.rand(1024/2+1).astype(float_type)55 b = np.random.rand(1024//2+1).astype(float_type)
54 spec.norm = a56 spec.norm = a
55 spec.phas = b57 spec.phas = b
56 new_spec = spec58 new_spec = spec
@@ -102,6 +104,43 @@ class aubio_cvec_test_case(TestCase): · 45 unmodified lines
102 with self.assertRaises(ValueError):104 with self.assertRaises(ValueError):
103 a.phas = b105 a.phas = b
104 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
113class 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
105if __name__ == '__main__':144if __name__ == '__main__':
106 from nose2 import main145 from nose2 import main
107 main()146 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t