source: python/tests/test_hist.py.old @ a0a073f

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since a0a073f was 208336b, checked in by Paul Brossier <piem@piem.org>, 12 years ago

tests/python/: removed old python tests

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[208336b]1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, digital_filter
[db62622]5import random
[d05c54f]6
7buf_size = 2048
8channels = 1
[42f1cf14]9flow = float(random.randint(0, 100) + random.random())
10fhig = float(random.randint(100, 1000) + random.random())
[d05c54f]11
12nelems = 1000
13
[208336b]14class hist_test_case(TestCase):
[d05c54f]15
16  def setUp(self):
17    self.o = new_aubio_hist(flow, fhig, nelems, channels)
18
19  def tearDown(self):
20    del_aubio_hist(self.o)
21
22  def test_hist(self):
23    """ create and delete hist """
24    pass
25
26  def test_hist_zeroes(self):
27    """ test hist on zeroes """
28    input = new_fvec(buf_size, channels)
29    aubio_hist_do_notnull(self.o, input)
30    aubio_hist_weight(self.o)
31    self.assertEqual(0., aubio_hist_mean(self.o))
32    del_fvec(input)
33
[42f1cf14]34  def test_hist_impulse_top(self):
35    """ test hist on impulse (top - 1.) """
36    """ this returns 1./nelems because 1 element is in the range """
[d05c54f]37    input = new_fvec(buf_size, channels)
38    constant = fhig - 1.
39    fvec_write_sample(input,constant,0,0)
40    aubio_hist_do_notnull(self.o, input)
41    self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o))
42    del_fvec(input)
43
[42f1cf14]44  def test_hist_impulse_over(self):
45    """ test hist on impulse (top + 1.) """
46    """ this returns 0 because constant is out of range """
[d05c54f]47    input = new_fvec(buf_size, channels)
48    constant = fhig + 1.
49    fvec_write_sample(input,constant,0,0)
50    aubio_hist_do_notnull(self.o, input)
[42f1cf14]51    self.assertCloseEnough(0., aubio_hist_mean(self.o))
52    del_fvec(input)
53
54  def test_hist_impulse_bottom(self):
55    """ test hist on constant near lower limit """
56    """ this returns 1./nelems because 1 element is in the range """
57    input = new_fvec(buf_size, channels)
58    constant = flow + 1.
59    fvec_write_sample(input,constant,0,0)
60    aubio_hist_do_notnull(self.o, input)
[d05c54f]61    self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o))
62    del_fvec(input)
63
[42f1cf14]64  def test_hist_impulse_under(self):
65    """ test hist on constant under lower limit """
66    """ this returns 0 because constant is out of range """
[208336b]67    vec_in = fvec(buf_size)
[42f1cf14]68    constant = flow - 1.
[208336b]69    vec_in[0] = constant
[42f1cf14]70    aubio_hist_do_notnull(self.o, input)
71    self.assertCloseEnough(0., aubio_hist_mean(self.o))
72    del_fvec(input)
73
[d05c54f]74if __name__ == '__main__': unittest.main()
Note: See TracBrowser for help on using the repository browser.