Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_cvec.py

    r0b6d23d r0e362b5  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    4 import numpy as np
    5 from numpy.testing import TestCase, assert_equal
    6 from aubio import cvec, fvec, float_type
    7 
    8 wrong_type = 'float32' if float_type == 'float64' else 'float64'
     3from numpy.testing import TestCase, run_module_suite
     4from numpy.testing import assert_equal, assert_almost_equal
     5from aubio import cvec
     6from numpy import array, shape, pi
    97
    108class aubio_cvec_test_case(TestCase):
     
    1210    def test_vector_created_with_zeroes(self):
    1311        a = cvec(10)
    14         assert_equal(a.norm.shape[0], 10 / 2 + 1)
    15         assert_equal(a.phas.shape[0], 10 / 2 + 1)
    16         _ = a.norm[0]
     12        shape(a.norm)
     13        shape(a.phas)
     14        a.norm[0]
    1715        assert_equal(a.norm, 0.)
    1816        assert_equal(a.phas, 0.)
     
    4442    def test_assign_cvec_phas_slice(self):
    4543        spec = cvec(1024)
    46         spec.phas[39:-1] = -np.pi
     44        spec.phas[39:-1] = -pi
    4745        assert_equal(spec.phas[0:39], 0)
    48         assert_equal(spec.phas[39:-1], -np.pi)
     46        assert_equal(spec.phas[39:-1], -pi)
    4947        assert_equal(spec.norm, 0)
    5048
    51     def test_assign_cvec_with_other_cvec(self):
    52         """ check dest cvec is still reachable after source was deleted """
    53         spec = cvec(1024)
    54         a = np.random.rand(1024//2+1).astype(float_type)
    55         b = np.random.rand(1024//2+1).astype(float_type)
    56         spec.norm = a
    57         spec.phas = b
    58         new_spec = spec
    59         del spec
    60         assert_equal(a, new_spec.norm)
    61         assert_equal(b, new_spec.phas)
    62         assert_equal(id(a), id(new_spec.norm))
    63         assert_equal(id(b), id(new_spec.phas))
    64 
    65     def test_pass_to_numpy(self):
    66         spec = cvec(1024)
    67         norm = spec.norm
    68         phas = spec.phas
    69         del spec
    70         new_spec = cvec(1024)
    71         new_spec.norm = norm
    72         new_spec.phas = phas
    73         assert_equal(norm, new_spec.norm)
    74         assert_equal(phas, new_spec.phas)
    75         assert_equal(id(norm), id(new_spec.norm))
    76         assert_equal(id(phas), id(new_spec.phas))
    77         del norm
    78         del phas
    79         assert_equal(new_spec.norm, 0.)
    80         assert_equal(new_spec.phas, 0.)
    81         del new_spec
    82 
    83     def test_assign_norm_too_large(self):
    84         a = cvec(512)
    85         b = fvec(512//2+1 + 4)
    86         with self.assertRaises(ValueError):
    87             a.norm = b
    88 
    89     def test_assign_norm_too_small(self):
    90         a = cvec(512)
    91         b = fvec(512//2+1 - 4)
    92         with self.assertRaises(ValueError):
    93             a.norm = b
    94 
    95     def test_assign_phas_too_large(self):
    96         a = cvec(512)
    97         b = fvec(512//2+1 + 4)
    98         with self.assertRaises(ValueError):
    99             a.phas = b
    100 
    101     def test_assign_phas_too_small(self):
    102         a = cvec(512)
    103         b = fvec(512//2+1 - 4)
    104         with self.assertRaises(ValueError):
    105             a.phas = b
    106 
    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 
    113 class 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 
    14449if __name__ == '__main__':
     50    from unittest import main
    14551    main()
Note: See TracChangeset for help on using the changeset viewer.