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

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since c9ca5a6e was c9ca5a6e, checked in by Paul Brossier <piem@piem.org>, 10 years ago

src/utils/hist.py: kill print

  • 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    self.o = new_aubio_hist(flow, fhig, nelems, channels)
16
17  def tearDown(self):
18    del_aubio_hist(self.o)
19
20  def test_hist(self):
21    """ create and delete hist """
22    pass
23
24  def test_hist_zeroes(self):
25    """ test hist on zeroes """
26    input = new_fvec(buf_size, channels)
27    aubio_hist_do_notnull(self.o, input)
28    aubio_hist_weight(self.o)
29    self.assertEqual(0., aubio_hist_mean(self.o))
30    del_fvec(input)
31
32  def test_hist_impulse_top(self):
33    """ test hist on impulse (top - 1.) """
34    """ this returns 1./nelems because 1 element is in the range """
35    input = new_fvec(buf_size, channels)
36    constant = fhig - 1. 
37    fvec_write_sample(input,constant,0,0)
38    aubio_hist_do_notnull(self.o, input)
39    self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o))
40    del_fvec(input)
41
42  def test_hist_impulse_over(self):
43    """ test hist on impulse (top + 1.) """
44    """ this returns 0 because constant is out of range """
45    input = new_fvec(buf_size, channels)
46    constant = fhig + 1. 
47    fvec_write_sample(input,constant,0,0)
48    aubio_hist_do_notnull(self.o, input)
49    self.assertCloseEnough(0., aubio_hist_mean(self.o))
50    del_fvec(input)
51
52  def test_hist_impulse_bottom(self):
53    """ test hist on constant near lower limit """
54    """ this returns 1./nelems because 1 element is in the range """
55    input = new_fvec(buf_size, channels)
56    constant = flow + 1. 
57    fvec_write_sample(input,constant,0,0)
58    aubio_hist_do_notnull(self.o, input)
59    self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o))
60    del_fvec(input)
61
62  def test_hist_impulse_under(self):
63    """ test hist on constant under lower limit """
64    """ this returns 0 because constant is out of range """
65    input = new_fvec(buf_size, channels)
66    constant = flow - 1. 
67    fvec_write_sample(input,constant,0,0)
68    aubio_hist_do_notnull(self.o, input)
69    self.assertCloseEnough(0., aubio_hist_mean(self.o))
70    del_fvec(input)
71
72if __name__ == '__main__': unittest.main()
Note: See TracBrowser for help on using the repository browser.