[208336b] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | from numpy.testing import TestCase, assert_equal, assert_almost_equal |
---|
| 4 | from aubio import fvec, digital_filter |
---|
[db62622] | 5 | import random |
---|
[d05c54f] | 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 | |
---|
[208336b] | 14 | class hist_test_case(TestCase): |
---|
[d05c54f] | 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 | |
---|
[42f1cf14] | 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 """ |
---|
[d05c54f] | 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 | |
---|
[42f1cf14] | 44 | def test_hist_impulse_over(self): |
---|
| 45 | """ test hist on impulse (top + 1.) """ |
---|
| 46 | """ this returns 0 because constant is out of range """ |
---|
[d05c54f] | 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) |
---|
[42f1cf14] | 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) |
---|
[d05c54f] | 61 | self.assertCloseEnough(1./nelems, aubio_hist_mean(self.o)) |
---|
| 62 | del_fvec(input) |
---|
| 63 | |
---|
[42f1cf14] | 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 """ |
---|
[208336b] | 67 | vec_in = fvec(buf_size) |
---|
[42f1cf14] | 68 | constant = flow - 1. |
---|
[208336b] | 69 | vec_in[0] = constant |
---|
[42f1cf14] | 70 | aubio_hist_do_notnull(self.o, input) |
---|
| 71 | self.assertCloseEnough(0., aubio_hist_mean(self.o)) |
---|
| 72 | del_fvec(input) |
---|
| 73 | |
---|
[d05c54f] | 74 | if __name__ == '__main__': unittest.main() |
---|