Showing the changes to python/tests/test_cvec.py (1 of 21 files). Show all
Unified · Split
| @@ -0,0 +1,50 @@ | ||
| 1 | +from numpy.testing import TestCase, run_module_suite | |
| 2 | +from numpy.testing import assert_equal, assert_almost_equal | |
| 3 | +from aubio import cvec | |
| 4 | +from numpy import array, shape, pi | |
| 5 | + | |
| 6 | +class aubio_cvec_test_case(TestCase): | |
| 7 | + | |
| 8 | + def test_vector_created_with_zeroes(self): | |
| 9 | + a = cvec(10) | |
| 10 | + a | |
| 11 | + shape(a.norm) | |
| 12 | + shape(a.phas) | |
| 13 | + a.norm[0] | |
| 14 | + assert_equal(a.norm, 0.) | |
| 15 | + assert_equal(a.phas, 0.) | |
| 16 | + | |
| 17 | + def test_vector_assign_element(self): | |
| 18 | + a = cvec() | |
| 19 | + a.norm[0] = 1 | |
| 20 | + assert_equal(a.norm[0], 1) | |
| 21 | + a.phas[0] = 1 | |
| 22 | + assert_equal(a.phas[0], 1) | |
| 23 | + | |
| 24 | + def test_vector_assign_element_end(self): | |
| 25 | + a = cvec() | |
| 26 | + a.norm[-1] = 1 | |
| 27 | + assert_equal(a.norm[-1], 1) | |
| 28 | + assert_equal(a.norm[len(a.norm)-1], 1) | |
| 29 | + a.phas[-1] = 1 | |
| 30 | + assert_equal(a.phas[-1], 1) | |
| 31 | + assert_equal(a.phas[len(a.phas)-1], 1) | |
| 32 | + | |
| 33 | + def test_assign_cvec_norm_slice(self): | |
| 34 | + spec = cvec(1024) | |
| 35 | + spec.norm[40:100] = 100 | |
| 36 | + assert_equal (spec.norm[0:40], 0) | |
| 37 | + assert_equal (spec.norm[40:100], 100) | |
| 38 | + assert_equal (spec.norm[100:-1], 0) | |
| 39 | + assert_equal (spec.phas, 0) | |
| 40 | + | |
| 41 | + def test_assign_cvec_phas_slice(self): | |
| 42 | + spec = cvec(1024) | |
| 43 | + spec.phas[39:-1] = -pi | |
| 44 | + assert_equal (spec.phas[0:39], 0) | |
| 45 | + assert_equal (spec.phas[39:-1], -pi) | |
| 46 | + assert_equal (spec.norm, 0) | |
| 47 | + | |
| 48 | +if __name__ == '__main__': | |
| 49 | + from unittest import main | |
| 50 | + main() | |