python/tests/test_source.py: skip tests if no sounds were found
[aubio.git] / python / tests / test_hist.py.old
1 #! /usr/bin/env python
2
3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from aubio import fvec, digital_filter
5 import random
6
7 buf_size = 2048
8 channels = 1
9 flow = float(random.randint(0, 100) + random.random())
10 fhig = float(random.randint(100, 1000) + random.random())
11
12 nelems = 1000
13
14 class hist_test_case(TestCase):
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
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)
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
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)
48     constant = fhig + 1. 
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))
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)
61     self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o))
62     del_fvec(input)
63
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)
68     constant = flow - 1. 
69     vec_in[0] = constant
70     aubio_hist_do_notnull(self.o, input)
71     self.assertCloseEnough(0., aubio_hist_mean(self.o))
72     del_fvec(input)
73
74 if __name__ == '__main__': unittest.main()