ref: 143cc436f4a9003e01c202a41fd63d1d07649235
parent: b583c099161b21c8d09eba137e7dab9861331af3
author: Paul Brossier <piem@piem.org>
date: Wed Mar 6 10:23:18 EST 2013
tests/test_mathutils.py: improve
--- a/python/tests/test_mathutils.py
+++ b/python/tests/test_mathutils.py
@@ -2,34 +2,104 @@
from numpy.testing import TestCase, run_module_suite
from numpy.testing import assert_equal, assert_almost_equal
+from numpy import array, arange, isnan, isinf
from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq
from aubio import unwrap2pi
+from aubio import fvec
+from math import pi
class aubio_mathutils(TestCase):
def test_unwrap2pi(self):
- a = [ x/100. for x in range(-600,600,100) ]
- b = [ unwrap2pi(x) for x in a ]
- #print b
+ unwrap2pi(int(23))
+ unwrap2pi(float(23.))
+ unwrap2pi(long(23.))
+ unwrap2pi(arange(10))
+ unwrap2pi(arange(10).astype("int"))
+ unwrap2pi(arange(10).astype("float"))
+ unwrap2pi(arange(10).astype("float32"))
+ unwrap2pi([1,3,5])
+ unwrap2pi([23.,24.,25.])
+ a = fvec(10)
+ a[:] = 4.
+ unwrap2pi(a)
+ a = pi/100. * arange(-600,600).astype("float")
+ b = unwrap2pi (a)
+ #print zip(a, b)
- def test_miditobin(self):
- a = [ miditobin(a, 44100, 512) for a in range(128) ]
+ try:
+ print unwrap2pi(["23.","24.",25.])
+ except TypeError:
+ pass
- def test_bintomidi(self):
- a = [ bintomidi(a, 44100, 512) for a in range(128) ]
+ def test_unwrap2pi_takes_fvec(self):
+ a = fvec(10)
+ b = unwrap2pi(a)
+ #print zip(a, b)
+ assert ( b > -pi ).all()
+ assert ( b <= pi ).all()
- def test_freqtobin(self):
- a = [ freqtobin(a, 44100, 512) for a in range(128) ]
+ def test_unwrap2pi_takes_array_of_float(self):
+ a = arange(-10., 10.).astype("float")
+ b = unwrap2pi(a)
+ #print zip(a, b)
+ assert ( b > -pi ).all()
+ assert ( b <= pi ).all()
- def test_bintofreq(self):
- a = [ bintofreq(a, 44100, 512) for a in range(128) ]
+ def test_unwrap2pi_takes_array_of_float32(self):
+ a = arange(-10, 10).astype("float32")
+ b = unwrap2pi(a)
+ #print zip(a, b)
+ assert ( b > -pi ).all()
+ assert ( b <= pi ).all()
def test_freqtomidi(self):
- a = [ freqtomidi(a) for a in range(128) ]
+ a = array(range(-20, 50000, 100) + [ -1e32, 1e32 ])
+ b = freqtomidi(a)
+ #print zip(a, b)
+ assert_equal ( isnan(array(b)), False )
+ assert_equal ( isinf(array(b)), False )
+ assert_equal ( array(b) < 0, False )
def test_miditofreq(self):
- freqs = [ miditofreq(a) for a in range(128) ]
- midis = [ freqtomidi(a) for a in freqs ]
+ a = range(-30, 200) + [-100000, 10000]
+ b = miditofreq(a)
+ #print zip(a, b)
+ assert_equal ( isnan(b), False )
+ assert_equal ( isinf(b), False )
+ assert_equal ( b < 0, False )
+
+ def test_miditobin(self):
+ a = range(-30, 200) + [-100000, 10000]
+ b = [ bintomidi(x, 44100, 512) for x in a ]
+ #print zip(a, b)
+ assert_equal ( isnan(array(b)), False )
+ assert_equal ( isinf(array(b)), False )
+ assert_equal ( array(b) < 0, False )
+
+ def test_bintomidi(self):
+ a = range(-100, 512)
+ b = [ bintomidi(x, 44100, 512) for x in a ]
+ #print zip(a, b)
+ assert_equal ( isnan(array(b)), False )
+ assert_equal ( isinf(array(b)), False )
+ assert_equal ( array(b) < 0, False )
+
+ def test_freqtobin(self):
+ a = range(-20, 50000, 100) + [ -1e32, 1e32 ]
+ b = [ freqtobin(x, 44100, 512) for x in a ]
+ #print zip(a, b)
+ assert_equal ( isnan(array(b)), False )
+ assert_equal ( isinf(array(b)), False )
+ assert_equal ( array(b) < 0, False )
+
+ def test_bintofreq(self):
+ a = range(-20, 148)
+ b = [ bintofreq(x, 44100, 512) for x in a ]
+ #print zip(a, b)
+ assert_equal ( isnan(array(b)), False )
+ assert_equal ( isinf(array(b)), False )
+ assert_equal ( array(b) < 0, False )
if __name__ == '__main__':
from unittest import main