3 from numpy.testing import TestCase
4 from numpy.testing import assert_equal, assert_almost_equal
5 from aubio import cvec, float_type
8 class aubio_cvec_test_case(TestCase):
10 def test_vector_created_with_zeroes(self):
12 assert_equal(a.norm.shape[0], 10 / 2 + 1)
13 assert_equal(a.phas.shape[0], 10 / 2 + 1)
15 assert_equal(a.norm, 0.)
16 assert_equal(a.phas, 0.)
18 def test_vector_assign_element(self):
21 assert_equal(a.norm[0], 1)
23 assert_equal(a.phas[0], 1)
25 def test_vector_assign_element_end(self):
28 assert_equal(a.norm[-1], 1)
29 assert_equal(a.norm[len(a.norm)-1], 1)
31 assert_equal(a.phas[-1], 1)
32 assert_equal(a.phas[len(a.phas)-1], 1)
34 def test_assign_cvec_norm_slice(self):
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)
42 def test_assign_cvec_phas_slice(self):
44 spec.phas[39:-1] = -np.pi
45 assert_equal(spec.phas[0:39], 0)
46 assert_equal(spec.phas[39:-1], -np.pi)
47 assert_equal(spec.norm, 0)
49 def test_assign_cvec_with_other_cvec(self):
50 """ check dest cvec is still reachable after source was deleted """
52 a = np.random.rand(1024/2+1).astype(float_type)
53 b = np.random.rand(1024/2+1).astype(float_type)
58 assert_equal(a, new_spec.norm)
59 assert_equal(b, new_spec.phas)
60 assert_equal(id(a), id(new_spec.norm))
61 assert_equal(id(b), id(new_spec.phas))
63 def test_pass_to_numpy(self):
71 assert_equal(norm, new_spec.norm)
72 assert_equal(phas, new_spec.phas)
73 assert_equal(id(norm), id(new_spec.norm))
74 assert_equal(id(phas), id(new_spec.phas))
77 assert_equal(new_spec.norm, 0.)
78 assert_equal(new_spec.phas, 0.)
81 if __name__ == '__main__':
82 from nose2 import main