1 | import unittest |
---|
2 | |
---|
3 | from template import aubio_unit_template |
---|
4 | from aubio.aubiowrapper import * |
---|
5 | |
---|
6 | buf_size = 2048 |
---|
7 | channels = 1 |
---|
8 | flow = 0. |
---|
9 | fhig = 100. |
---|
10 | |
---|
11 | nelems = 1000 |
---|
12 | |
---|
13 | class hist_unit(aubio_unit_template): |
---|
14 | |
---|
15 | def setUp(self): |
---|
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(self): |
---|
34 | """ test hist on impulse """ |
---|
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_impulse2(self): |
---|
43 | """ test hist on impulse """ |
---|
44 | input = new_fvec(buf_size, channels) |
---|
45 | constant = fhig + 1. |
---|
46 | fvec_write_sample(input,constant,0,0) |
---|
47 | aubio_hist_do_notnull(self.o, input) |
---|
48 | self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o)) |
---|
49 | del_fvec(input) |
---|
50 | |
---|
51 | if __name__ == '__main__': unittest.main() |
---|