Changeset c09efca


Ignore:
Timestamp:
May 13, 2016, 5:58:02 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
1167631
Parents:
1164fd85
Message:

python/tests/test_cvec.py: add more tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_cvec.py

    r1164fd85 rc09efca  
    55from aubio import cvec, fvec, float_type
    66import numpy as np
     7
     8wrong_type = 'float32' if float_type == 'float64' else 'float64'
    79
    810class aubio_cvec_test_case(TestCase):
     
    5052        """ check dest cvec is still reachable after source was deleted """
    5153        spec = cvec(1024)
    52         a = np.random.rand(1024/2+1).astype(float_type)
    53         b = np.random.rand(1024/2+1).astype(float_type)
     54        a = np.random.rand(1024//2+1).astype(float_type)
     55        b = np.random.rand(1024//2+1).astype(float_type)
    5456        spec.norm = a
    5557        spec.phas = b
     
    103105            a.phas = b
    104106
     107    def test_cvec_repr(self):
     108        win_s = 512
     109        c = cvec(win_s)
     110        expected_repr = "aubio cvec of {:d} elements".format(win_s//2+1)
     111        self.assertEqual(repr(c), expected_repr)
     112
     113class aubio_cvec_wrong_norm_input(TestCase):
     114
     115    def test_wrong_length(self):
     116        with self.assertRaises(ValueError):
     117            cvec(-1)
     118
     119    def test_set_norm_with_scalar(self):
     120        a = cvec(512)
     121        with self.assertRaises(ValueError):
     122            a.norm = 1
     123
     124    def test_set_norm_with_scalar_array(self):
     125        a = cvec(512)
     126        with self.assertRaises(ValueError):
     127            a.norm = np.ndarray(1, dtype = 'int')
     128
     129    def test_set_norm_with_int_array(self):
     130        a = cvec(512)
     131        with self.assertRaises(ValueError):
     132            a.norm = np.zeros(512//2+1, dtype = 'int')
     133
     134    def test_set_norm_with_wrong_float_array(self):
     135        a = cvec(512)
     136        with self.assertRaises(ValueError):
     137            a.norm = np.zeros(512//2+1, dtype = wrong_type)
     138
     139    def test_set_norm_with_wrong_2d_array(self):
     140        a = cvec(512)
     141        with self.assertRaises(ValueError):
     142            a.norm = np.zeros((512//2+1, 2), dtype = float_type)
     143
    105144if __name__ == '__main__':
    106145    from nose2 import main
Note: See TracChangeset for help on using the changeset viewer.