source: python/tests/test_fvec_shift.py @ bb63c19

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since bb63c19 was 319edae, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] avoid some imports, move main to end

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#! /usr/bin/env python
2
3import numpy as np
4from numpy.testing import TestCase, assert_equal
5import aubio
6
7class aubio_shift_test_case(TestCase):
8
9    def run_shift_ishift(self, n):
10        ramp = np.arange(n, dtype=aubio.float_type)
11        # construct expected output
12        # even length: [5. 6. 7. 8. 9. 0. 1. 2. 3. 4.]
13        # odd length: [4. 5. 6. 0. 1. 2. 3.]
14        half = n - n//2
15        expected = np.concatenate([np.arange(half, n), np.arange(half)])
16        # shift in place, returns modified copy
17        assert_equal(aubio.shift(ramp), expected)
18        # check input was changed as expected
19        assert_equal(ramp, expected)
20        # construct expected output
21        expected = np.arange(n)
22        # revert shift in place, returns modifed copy
23        assert_equal(aubio.ishift(ramp), expected)
24        # check input was shifted back
25        assert_equal(ramp, expected)
26
27    def test_can_shift_fvec(self):
28        self.run_shift_ishift(10)
29
30    def test_can_shift_fvec_odd(self):
31        self.run_shift_ishift(7)
32
33if __name__ == '__main__':
34    from unittest import main
35    main()
Note: See TracBrowser for help on using the repository browser.