source: tests/python/src/utils/hist.py @ 42f1cf14

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

tests/python/src/utils/hist.py: update existing test cases, add two more

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