Showing the changes to python/tests (1 of 1 file). Show all
Unified · Split
| @@ -5,6 +5,8 @@ from numpy.testing import assert_equal, assert_almost_equal · 4 unmodified lines | ||
| 5 | 5 | from aubio import cvec, fvec, float_type |
| 6 | 6 | import numpy as np |
| 7 | 7 | |
| 8 | +wrong_type = 'float32' if float_type == 'float64' else 'float64' | |
| 9 | + | |
| 8 | 10 | class aubio_cvec_test_case(TestCase): |
| 9 | 11 | |
| 10 | 12 | def test_vector_created_with_zeroes(self): |
| @@ -49,8 +51,8 @@ class aubio_cvec_test_case(TestCase): · 38 unmodified lines | ||
| 49 | 51 | def test_assign_cvec_with_other_cvec(self): |
| 50 | 52 | """ check dest cvec is still reachable after source was deleted """ |
| 51 | 53 | 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) | |
| 54 | 56 | spec.norm = a |
| 55 | 57 | spec.phas = b |
| 56 | 58 | new_spec = spec |
| @@ -102,6 +104,43 @@ class aubio_cvec_test_case(TestCase): · 45 unmodified lines | ||
| 102 | 104 | with self.assertRaises(ValueError): |
| 103 | 105 | 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 | + | |
| 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 | + | |
| 105 | 144 | if __name__ == '__main__': |
| 106 | 145 | from nose2 import main |
| 107 | 146 | main() |