Changeset 146280a for interfaces


Ignore:
Timestamp:
Oct 2, 2009, 3:38:30 PM (15 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:
ccf8b77
Parents:
207ed19
Message:

python/test_aubio.py: update unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • interfaces/python/test_aubio.py

    r207ed19 r146280a  
    1 import unittest
     1from numpy.testing import TestCase, run_module_suite
     2from numpy.testing import assert_equal as numpy_assert_equal
    23from _aubio import *
    34from numpy import array
    45
    5 class aubiomodule_test_case(unittest.TestCase):
     6AUBIO_DO_CASTING = 0
     7
     8def assert_equal(a, b):
     9  numpy_assert_equal(array(a),array(b))
     10
     11class aubiomodule_test_case(TestCase):
    612
    713  def setUp(self):
     
    3844
    3945  def test_alpha_norm_of_array_of_float32(self):
     46    # check scalar fails
    4047    a = array(1, dtype = 'float32')
    4148    self.assertRaises (ValueError, alpha_norm, a, 1)
     49    # check 3d array fails
    4250    a = array([[[1,2],[3,4]]], dtype = 'float32')
    4351    self.assertRaises (ValueError, alpha_norm, a, 1)
     52    # check 1d array
    4453    a = array(range(10), dtype = 'float32')
    4554    self.assertEquals (alpha_norm(a, 1), 4.5)
     55    # check 2d array
    4656    a = array([range(10), range(10)], dtype = 'float32')
    47     self.assertEquals (alpha_norm(a, 1), 9)
    48 
    49   def test_alpha_norm_of_array_of_float64(self):
    50     a = array(1, dtype = 'float64')
    51     self.assertRaises (ValueError, alpha_norm, a, 1)
    52     a = array([[[1,2],[3,4]]], dtype = 'float64')
    53     self.assertRaises (ValueError, alpha_norm, a, 1)
    54     a = array(range(10), dtype = 'float64')
    55     self.assertEquals (alpha_norm(a, 1), 4.5)
    56     a = array([range(10), range(10)], dtype = 'float64')
    5757    self.assertEquals (alpha_norm(a, 1), 9)
    5858
     
    6969    self.assertRaises (ValueError, alpha_norm, a, 1)
    7070
     71  def test_zero_crossing_rate(self):
     72    a = array([0,1,-1], dtype='float32')
     73    self.assertEquals (zero_crossing_rate(a), 1./3 )
     74    a = array([0.]*100, dtype='float32')
     75    self.assertEquals (zero_crossing_rate(a), 0 )
     76    a = array([-1.]*100, dtype='float32')
     77    self.assertEquals (zero_crossing_rate(a), 0 )
     78    a = array([1.]*100, dtype='float32')
     79    self.assertEquals (zero_crossing_rate(a), 0 )
     80
     81  def test_alpha_norm_of_array_of_float64(self):
     82    # check scalar fail
     83    a = array(1, dtype = 'float64')
     84    self.assertRaises (ValueError, alpha_norm, a, 1)
     85    # check 3d array fail
     86    a = array([[[1,2],[3,4]]], dtype = 'float64')
     87    self.assertRaises (ValueError, alpha_norm, a, 1)
     88    if AUBIO_DO_CASTING:
     89      # check float64 1d array fail
     90      a = array(range(10), dtype = 'float64')
     91      self.assertEquals (alpha_norm(a, 1), 4.5)
     92      # check float64 2d array fail
     93      a = array([range(10), range(10)], dtype = 'float64')
     94      self.assertEquals (alpha_norm(a, 1), 9)
     95    else:
     96      # check float64 1d array fail
     97      a = array(range(10), dtype = 'float64')
     98      self.assertRaises (ValueError, alpha_norm, a, 1)
     99      # check float64 2d array fail
     100      a = array([range(10), range(10)], dtype = 'float64')
     101      self.assertRaises (ValueError, alpha_norm, a, 1)
     102
     103  def test_fvec_min_removal_of_array(self):
     104    a = array([20,1,19], dtype='float32')
     105    b = min_removal(a)
     106    assert_equal (array(b), [19, 0, 18])
     107    assert_equal (b, [19, 0, 18])
     108    assert_equal (a, b)
     109    a[0] = 0
     110    assert_equal (a, b)
     111
     112  def test_fvec_min_removal_of_array_float64(self):
     113    a = array([20,1,19], dtype='float64')
     114    if AUBIO_DO_CASTING:
     115      b = min_removal(a)
     116      assert_equal (array(b), [19, 0, 18])
     117      assert_equal (b, [19, 0, 18])
     118      #assert_equal (a, b)
     119    else:
     120      self.assertRaises (ValueError, min_removal, a)
     121     
     122  def test_fvec_min_removal_of_fvec(self):
     123    a = fvec(3, 1)
     124    a[0] = [20, 1, 19]
     125    b = min_removal(a)
     126    assert_equal (array(b), [19, 0, 18])
     127    assert_equal (b, [19, 0, 18])
     128    assert_equal (a, b)
     129
    71130if __name__ == '__main__':
    72   unittest.main()
     131  from unittest import main
     132  main()
     133
Note: See TracChangeset for help on using the changeset viewer.