source: python/tests/test_mathutils.py @ 319edae

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

[tests] avoid some imports, move main to end

  • Property mode set to 100755
File size: 3.3 KB
RevLine 
[6a50b9e]1#! /usr/bin/env python
2
[afceccd]3from numpy.testing import TestCase, assert_equal
[143cc43]4from numpy import array, arange, isnan, isinf
[6a50b9e]5from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq
[6514bb6]6from aubio import unwrap2pi
[143cc43]7from aubio import fvec
8from math import pi
[6a50b9e]9
10class aubio_mathutils(TestCase):
11
[6514bb6]12    def test_unwrap2pi(self):
[143cc43]13        unwrap2pi(int(23))
14        unwrap2pi(float(23.))
[689106e]15        unwrap2pi(int(23.))
[143cc43]16        unwrap2pi(arange(10))
17        unwrap2pi(arange(10).astype("int"))
18        unwrap2pi(arange(10).astype("float"))
19        unwrap2pi(arange(10).astype("float32"))
20        unwrap2pi([1,3,5])
21        unwrap2pi([23.,24.,25.])
22        a = fvec(10)
23        a[:] = 4.
24        unwrap2pi(a)
25        a = pi/100. * arange(-600,600).astype("float")
[0b6d23d]26        unwrap2pi(a)
[143cc43]27        #print zip(a, b)
[6514bb6]28
[0b6d23d]29    def test_unwrap2pi_fails_on_list(self):
[a6f9ebf]30        with self.assertRaises((TypeError, NotImplementedError)):
[0b6d23d]31            unwrap2pi(["23.","24.",25.])
[6a50b9e]32
[143cc43]33    def test_unwrap2pi_takes_fvec(self):
34        a = fvec(10)
35        b = unwrap2pi(a)
36        #print zip(a, b)
37        assert ( b > -pi ).all()
38        assert ( b <= pi ).all()
[6a50b9e]39
[143cc43]40    def test_unwrap2pi_takes_array_of_float(self):
41        a = arange(-10., 10.).astype("float")
42        b = unwrap2pi(a)
43        #print zip(a, b)
44        assert ( b > -pi ).all()
45        assert ( b <= pi ).all()
[6a50b9e]46
[143cc43]47    def test_unwrap2pi_takes_array_of_float32(self):
48        a = arange(-10, 10).astype("float32")
49        b = unwrap2pi(a)
50        #print zip(a, b)
51        assert ( b > -pi ).all()
52        assert ( b <= pi ).all()
[6a50b9e]53
54    def test_freqtomidi(self):
[689106e]55        a = array(list(range(-20, 50000, 100)) + [ -1e32, 1e32 ])
[143cc43]56        b = freqtomidi(a)
57        #print zip(a, b)
58        assert_equal ( isnan(array(b)), False )
59        assert_equal ( isinf(array(b)), False )
60        assert_equal ( array(b) < 0, False )
[6a50b9e]61
62    def test_miditofreq(self):
[689106e]63        a = list(range(-30, 200)) + [-100000, 10000]
[143cc43]64        b = miditofreq(a)
65        #print zip(a, b)
66        assert_equal ( isnan(b), False )
67        assert_equal ( isinf(b), False )
68        assert_equal ( b < 0, False )
69
70    def test_miditobin(self):
[689106e]71        a = list(range(-30, 200)) + [-100000, 10000]
[ddfa6be]72        b = [ miditobin(x, 44100, 512) for x in a ]
[143cc43]73        #print zip(a, b)
74        assert_equal ( isnan(array(b)), False )
75        assert_equal ( isinf(array(b)), False )
76        assert_equal ( array(b) < 0, False )
77
78    def test_bintomidi(self):
[689106e]79        a = list(range(-100, 512))
[143cc43]80        b = [ bintomidi(x, 44100, 512) for x in a ]
81        #print zip(a, b)
82        assert_equal ( isnan(array(b)), False )
83        assert_equal ( isinf(array(b)), False )
84        assert_equal ( array(b) < 0, False )
85
86    def test_freqtobin(self):
[689106e]87        a = list(range(-20, 50000, 100)) + [ -1e32, 1e32 ]
[143cc43]88        b = [ freqtobin(x, 44100, 512) for x in a ]
89        #print zip(a, b)
90        assert_equal ( isnan(array(b)), False )
91        assert_equal ( isinf(array(b)), False )
92        assert_equal ( array(b) < 0, False )
93
94    def test_bintofreq(self):
[689106e]95        a = list(range(-20, 148))
[143cc43]96        b = [ bintofreq(x, 44100, 512) for x in a ]
97        #print zip(a, b)
98        assert_equal ( isnan(array(b)), False )
99        assert_equal ( isinf(array(b)), False )
100        assert_equal ( array(b) < 0, False )
[6a50b9e]101
102if __name__ == '__main__':
[319edae]103    from unittest import main
[6a50b9e]104    main()
Note: See TracBrowser for help on using the repository browser.