From 467122daa160b993eef8a0f3fb145d31b0c65688 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 22 Feb 2014 15:37:16 -0300 Subject: [PATCH] python/tests/test_phasevoc.py: improve --- python/tests/test_phasevoc.py | 115 ++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/python/tests/test_phasevoc.py b/python/tests/test_phasevoc.py index e317a7d1..1ffd26c2 100755 --- a/python/tests/test_phasevoc.py +++ b/python/tests/test_phasevoc.py @@ -1,65 +1,80 @@ #! /usr/bin/env python -from numpy.testing import TestCase, run_module_suite -from numpy.testing import assert_equal, assert_almost_equal +from numpy.testing import TestCase, assert_equal, assert_almost_equal from aubio import fvec, cvec, pvoc from numpy import array, shape +from numpy.random import random + +precision = 6 class aubio_pvoc_test_case(TestCase): + """ pvoc object test case """ + + def test_members_automatic_sizes_default(self): + """ check object creation with default parameters """ + f = pvoc() + assert_equal ([f.win_s, f.hop_s], [1024, 512]) - def test_members_automatic_sizes_default(self): - f = pvoc() - assert_equal ([f.win_s, f.hop_s], [1024, 512]) + def test_members_unnamed_params(self): + """ check object creation with unnamed parameters """ + f = pvoc(2048, 128) + assert_equal ([f.win_s, f.hop_s], [2048, 128]) - def test_members_automatic_sizes_not_null(self): - f = pvoc(2048, 128) - assert_equal ([f.win_s, f.hop_s], [2048, 128]) + def test_members_named_params(self): + """ check object creation with named parameters """ + f = pvoc(hop_s = 128, win_s = 2048) + assert_equal ([f.win_s, f.hop_s], [2048, 128]) - def test_zeros(self): - win_s, hop_s = 1024, 256 - f = pvoc (win_s, hop_s) - t = fvec (hop_s) - for time in range( 4 * win_s / hop_s ): - s = f(t) - r = f.rdo(s) - assert_equal ( array(t), 0) - assert_equal ( s.norm, 0) - assert_equal ( s.phas, 0) - assert_equal ( r, 0) + def test_zeros(self): + """ check the resynthesis of zeros gives zeros """ + win_s, hop_s = 1024, 256 + f = pvoc (win_s, hop_s) + t = fvec (hop_s) + for time in range( 4 * win_s / hop_s ): + s = f(t) + r = f.rdo(s) + assert_equal ( array(t), 0) + assert_equal ( s.norm, 0) + assert_equal ( s.phas, 0) + assert_equal ( r, 0) - def test_steps_two_channels(self): - """ check the resynthesis of steps is correct """ - f = pvoc(1024, 512) - t1 = fvec(512) - t2 = fvec(512) - # positive step in first channel - t1[100:200] = .1 - # positive step in second channel - t1[20:50] = -.1 - s1 = f(t1) - r1 = f.rdo(s1) - s2 = f(t2) - r2 = f.rdo(s2) - #self.plot_this ( s1.norm.T ) - assert_almost_equal ( t1, r2, decimal = 6 ) + def test_resynth_two_steps(self): + """ check the resynthesis of steps is correct with 50% overlap """ + hop_s = 512 + buf_s = hop_s * 2 + f = pvoc(buf_s, hop_s) + sigin = fvec(hop_s) + zeros = fvec(hop_s) + # negative step + sigin[20:50] = -.1 + # positive step + sigin[100:200] = .1 + s1 = f(sigin) + r1 = f.rdo(s1) + s2 = f(zeros) + r2 = f.rdo(s2) + #self.plot_this ( s2.norm.T ) + assert_almost_equal ( r2, sigin, decimal = precision ) - def test_steps_three_random_channels(self): - from random import random - f = pvoc(64, 16) - t0 = fvec(16) - t1 = fvec(16) - for i in xrange(16): - t1[i] = random() * 2. - 1. - t2 = f.rdo(f(t1)) - t2 = f.rdo(f(t0)) - t2 = f.rdo(f(t0)) - t2 = f.rdo(f(t0)) - assert_almost_equal( t1, t2, decimal = 6 ) + def test_resynth_three_steps(self): + """ check the resynthesis of steps is correct with 25% overlap """ + hop_s = 16 + buf_s = hop_s * 4 + sigin = fvec(hop_s) + zeros = fvec(hop_s) + f = pvoc(buf_s, hop_s) + for i in xrange(hop_s): + sigin[i] = random() * 2. - 1. + t2 = f.rdo( f(sigin) ) + t2 = f.rdo( f(zeros) ) + t2 = f.rdo( f(zeros) ) + t2 = f.rdo( f(zeros) ) + assert_almost_equal( sigin, t2, decimal = precision ) - def plot_this( self, this ): - from pylab import semilogy, show - semilogy ( this ) - show () + def plot_this( self, this ): + from pylab import semilogy, show + semilogy ( this ) + show () if __name__ == '__main__': from unittest import main -- 2.11.0