source: python/tests/test_phasevoc.py @ 926f0f6

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 926f0f6 was 86ad546, checked in by Paul Brossier <piem@piem.org>, 12 years ago

python/tests/test_phasevoc.py: split tests

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[75e715f]1#! /usr/bin/env python
[1ebf8770]2
[0536612]3from numpy.testing import TestCase, run_module_suite
4from numpy.testing import assert_equal, assert_almost_equal
[4c01c0f]5from aubio import fvec, cvec, pvoc
[0536612]6from numpy import array, shape
7
8class aubio_pvoc_test_case(TestCase):
9
[86ad546]10  def test_members_automatic_sizes_default(self):
[0536612]11    f = pvoc()
12    assert_equal ([f.win_s, f.hop_s], [1024, 512])
[86ad546]13
14  def test_members_automatic_sizes_not_null(self):
[0536612]15    f = pvoc(2048, 128)
16    assert_equal ([f.win_s, f.hop_s], [2048, 128])
17
18  def test_zeros(self):
19    win_s, hop_s = 1024, 256
20    f = pvoc (win_s, hop_s)
21    t = fvec (hop_s)
22    for time in range( 4 * win_s / hop_s ):
23      s = f(t)
24      r = f.rdo(s)
25      assert_equal ( array(t), 0)
26      assert_equal ( s.norm, 0)
27      assert_equal ( s.phas, 0)
28      assert_equal ( r, 0)
29
30  def test_steps_two_channels(self):
31    """ check the resynthesis of steps is correct """
[1a6ef2c]32    f = pvoc(1024, 512)
33    t1 = fvec(512)
34    t2 = fvec(512)
[0536612]35    # positive step in first channel
[1a6ef2c]36    t1[100:200] = .1
[0536612]37    # positive step in second channel
[1a6ef2c]38    t1[20:50] = -.1
[0536612]39    s1 = f(t1)
40    r1 = f.rdo(s1)
41    s2 = f(t2)
42    r2 = f.rdo(s2)
43    #self.plot_this ( s1.norm.T )
44    assert_almost_equal ( t1, r2, decimal = 6 )
45   
46  def test_steps_three_random_channels(self):
47    from random import random
[1a6ef2c]48    f = pvoc(64, 16)
49    t0 = fvec(16)
50    t1 = fvec(16)
51    for i in xrange(16):
52        t1[i] = random() * 2. - 1.
[0536612]53    t2 = f.rdo(f(t1))
54    t2 = f.rdo(f(t0))
55    t2 = f.rdo(f(t0))
56    t2 = f.rdo(f(t0))
57    assert_almost_equal( t1, t2, decimal = 6 )
58   
59  def plot_this( self, this ):
60    from pylab import semilogy, show
61    semilogy ( this )
62    show ()
63
64if __name__ == '__main__':
65  from unittest import main
66  main()
67
Note: See TracBrowser for help on using the repository browser.