source: tests/python/src/utils/hist.py @ db62622

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

tests/python: update imports

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