[d05c54f] | 1 | from template import aubio_unit_template |
---|
[db62622] | 2 | from localaubio import * |
---|
| 3 | import random |
---|
[d05c54f] | 4 | |
---|
| 5 | buf_size = 2048 |
---|
| 6 | channels = 1 |
---|
[42f1cf14] | 7 | flow = float(random.randint(0, 100) + random.random()) |
---|
| 8 | fhig = float(random.randint(100, 1000) + random.random()) |
---|
[d05c54f] | 9 | |
---|
| 10 | nelems = 1000 |
---|
| 11 | |
---|
| 12 | class 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 | |
---|
[42f1cf14] | 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 """ |
---|
[d05c54f] | 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 | |
---|
[42f1cf14] | 42 | def test_hist_impulse_over(self): |
---|
| 43 | """ test hist on impulse (top + 1.) """ |
---|
| 44 | """ this returns 0 because constant is out of range """ |
---|
[d05c54f] | 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) |
---|
[42f1cf14] | 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) |
---|
[d05c54f] | 59 | self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o)) |
---|
| 60 | del_fvec(input) |
---|
| 61 | |
---|
[42f1cf14] | 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 | |
---|
[d05c54f] | 72 | if __name__ == '__main__': unittest.main() |
---|