ref: e7556a18aa9a1bff3267514a2906f4e38428df77
parent: c96e6c03f1055e2fc2b74464462d08db6254d73e
author: Paul Brossier <piem@piem.org>
date: Sat Sep 16 19:46:30 EDT 2017
python/tests/test_dct.py: add comments
--- a/python/tests/test_dct.py
+++ b/python/tests/test_dct.py
@@ -5,10 +5,18 @@
from numpy.testing import TestCase, assert_almost_equal
import aubio
+precomputed_arange = [ 9.89949512, -6.44232273, 0., -0.67345482, 0.,
+ -0.20090288, 0., -0.05070186]
+
+precomputed_some_ones = [ 4.28539848, 0.2469689, -0.14625292, -0.58121818,
+ -0.83483052, -0.75921834, -0.35168475, 0.24087936,
+ 0.78539824, 1.06532764, 0.97632152, 0.57164496, 0.03688532,
+ -0.39446154, -0.54619485, -0.37771079]
+
class aubio_dct(TestCase):
def test_init(self):
- """ check aubio.dct() can be created """
+ """ test that aubio.dct() is created with expected size """
a_dct = aubio.dct()
self.assertEqual(a_dct.size, 1024)
@@ -19,27 +27,23 @@
>>> a_in = np.arange(8).astype('float32')
>>> precomputed = dct(a_in, norm='ortho')
"""
- precomputed = [ 9.89949512, -6.44232273, 0., -0.67345482, 0.,
- -0.20090288, 0., -0.05070186]
+ N = len(precomputed_arange)
a_dct = aubio.dct(8)
a_in = np.arange(8).astype('float32')
- a_expected = aubio.fvec(precomputed)
+ a_expected = aubio.fvec(precomputed_arange)
assert_almost_equal(a_dct(a_in), a_expected, decimal=6)
def test_some_ones(self):
""" test that dct(somevector) is computed correctly """
- precomputed = [ 4.28539848, 0.2469689, -0.14625292, -0.58121818,
- -0.83483052, -0.75921834, -0.35168475, 0.24087936,
- 0.78539824, 1.06532764, 0.97632152, 0.57164496, 0.03688532,
- -0.39446154, -0.54619485, -0.37771079]
a_dct = aubio.dct(16)
a_in = np.ones(16).astype('float32')
a_in[1] = 0
a_in[3] = np.pi
- a_expected = aubio.fvec(precomputed)
+ a_expected = aubio.fvec(precomputed_some_ones)
assert_almost_equal(a_dct(a_in), a_expected, decimal=7)
def test_reconstruction(self):
+ """ test that some_ones vector can be recontructed """
a_dct = aubio.dct(16)
a_in = np.ones(16).astype('float32')
a_in[1] = 0
@@ -49,10 +53,12 @@
assert_almost_equal(a_dct_reconstructed, a_in, decimal=6)
def test_negative_size(self):
+ """ test that creation fails with a negative size """
with self.assertRaises(ValueError):
aubio.dct(-1)
def test_wrong_size(self):
+ """ test that creation fails with a non power-of-two size """
# supports for non 2** fft sizes only when compiled with fftw3
try:
with self.assertRaises(RuntimeError):