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