source: python/tests/test_cvec.py @ 9f8cd9f

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 9f8cd9f was 9f8cd9f, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/tests/test_cvec.py: simplify, use nose2

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase
4from numpy.testing import assert_equal, assert_almost_equal
5from aubio import cvec, float_type
6import numpy as np
7
8class aubio_cvec_test_case(TestCase):
9
10    def test_vector_created_with_zeroes(self):
11        a = cvec(10)
12        assert_equal(a.norm.shape[0], 10 / 2 + 1)
13        assert_equal(a.phas.shape[0], 10 / 2 + 1)
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] = -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)
48
49if __name__ == '__main__':
50    from nose2 import main
51    main()
Note: See TracBrowser for help on using the repository browser.