3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from aubio import fvec, digital_filter
9 flow = float(random.randint(0, 100) + random.random())
10 fhig = float(random.randint(100, 1000) + random.random())
14 class hist_test_case(TestCase):
17 self.o = new_aubio_hist(flow, fhig, nelems, channels)
20 del_aubio_hist(self.o)
23 """ create and delete hist """
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))
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 """
37 input = new_fvec(buf_size, channels)
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))
44 def test_hist_impulse_over(self):
45 """ test hist on impulse (top + 1.) """
46 """ this returns 0 because constant is out of range """
47 input = new_fvec(buf_size, channels)
49 fvec_write_sample(input,constant,0,0)
50 aubio_hist_do_notnull(self.o, input)
51 self.assertCloseEnough(0., aubio_hist_mean(self.o))
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)
59 fvec_write_sample(input,constant,0,0)
60 aubio_hist_do_notnull(self.o, input)
61 self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o))
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 """
67 vec_in = fvec(buf_size)
70 aubio_hist_do_notnull(self.o, input)
71 self.assertCloseEnough(0., aubio_hist_mean(self.o))
74 if __name__ == '__main__': unittest.main()