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/tests/test_cvec.py (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
55 from aubio import cvec, fvec, float_type
66 import numpy as np
77
8+wrong_type = 'float32' if float_type == 'float64' else 'float64'
9+
810 class aubio_cvec_test_case(TestCase):
911
1012 def test_vector_created_with_zeroes(self):
@@ -49,8 +51,8 @@ class aubio_cvec_test_case(TestCase): · 38 unmodified lines
4951 def test_assign_cvec_with_other_cvec(self):
5052 """ check dest cvec is still reachable after source was deleted """
5153 spec = cvec(1024)
52− a = np.random.rand(1024/2+1).astype(float_type)
53− b = np.random.rand(1024/2+1).astype(float_type)
54+ a = np.random.rand(1024//2+1).astype(float_type)
55+ b = np.random.rand(1024//2+1).astype(float_type)
5456 spec.norm = a
5557 spec.phas = b
5658 new_spec = spec
@@ -102,6 +104,43 @@ class aubio_cvec_test_case(TestCase): · 45 unmodified lines
102104 with self.assertRaises(ValueError):
103105 a.phas = b
104106
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+
105144 if __name__ == '__main__':
106145 from nose2 import main
107146 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