1 | #! /usr/bin/env python |
---|
2 | |
---|
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 |
---|
7 | |
---|
8 | class aubio_cvec_test_case(TestCase): |
---|
9 | |
---|
10 | def test_vector_created_with_zeroes(self): |
---|
11 | a = cvec(10) |
---|
12 | shape(a.norm) |
---|
13 | shape(a.phas) |
---|
14 | a.norm[0] |
---|
15 | assert_equal(a.norm, 0.) |
---|
16 | assert_equal(a.phas, 0.) |
---|
17 | |
---|
18 | def test_vector_assign_element(self): |
---|
19 | a = cvec() |
---|
20 | a.norm[0] = 1 |
---|
21 | assert_equal(a.norm[0], 1) |
---|
22 | a.phas[0] = 1 |
---|
23 | assert_equal(a.phas[0], 1) |
---|
24 | |
---|
25 | def test_vector_assign_element_end(self): |
---|
26 | a = cvec() |
---|
27 | a.norm[-1] = 1 |
---|
28 | assert_equal(a.norm[-1], 1) |
---|
29 | assert_equal(a.norm[len(a.norm)-1], 1) |
---|
30 | a.phas[-1] = 1 |
---|
31 | assert_equal(a.phas[-1], 1) |
---|
32 | assert_equal(a.phas[len(a.phas)-1], 1) |
---|
33 | |
---|
34 | def test_assign_cvec_norm_slice(self): |
---|
35 | spec = cvec(1024) |
---|
36 | spec.norm[40:100] = 100 |
---|
37 | assert_equal(spec.norm[0:40], 0) |
---|
38 | assert_equal(spec.norm[40:100], 100) |
---|
39 | assert_equal(spec.norm[100:-1], 0) |
---|
40 | assert_equal(spec.phas, 0) |
---|
41 | |
---|
42 | def test_assign_cvec_phas_slice(self): |
---|
43 | spec = cvec(1024) |
---|
44 | spec.phas[39:-1] = -pi |
---|
45 | assert_equal(spec.phas[0:39], 0) |
---|
46 | assert_equal(spec.phas[39:-1], -pi) |
---|
47 | assert_equal(spec.norm, 0) |
---|
48 | |
---|
49 | if __name__ == '__main__': |
---|
50 | from unittest import main |
---|
51 | main() |
---|