source: python/tests/test_onset.py @ 7e2eef4

feature/autosinkfeature/cnnfeature/crepefix/ffmpeg5
Last change on this file since 7e2eef4 was 11c0d74, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] improve onset coverage

  • Property mode set to 100755
File size: 3.2 KB
RevLine 
[75e715f]1#! /usr/bin/env python
[312826c]2
[0b6d23d]3from unittest import main
4from numpy.testing import TestCase, assert_equal, assert_almost_equal
[11c0d74]5from aubio import onset, fvec
[312826c]6
[8eff66d]7class aubio_onset_default(TestCase):
[312826c]8
9    def test_members(self):
10        o = onset()
11        assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate],
12            [1024,512,'default',44100])
[8eff66d]13
14class aubio_onset_params(TestCase):
15
16    samplerate = 44100
17
18    def setUp(self):
19        self.o = onset(samplerate = self.samplerate)
20
21    def test_get_delay(self):
[25e0b0e]22        self.assertGreater(self.o.get_delay(), 0)
[8eff66d]23
24    def test_get_delay_s(self):
[25e0b0e]25        self.assertGreater(self.o.get_delay_s(), 0.)
[8eff66d]26
27    def test_get_delay_ms(self):
[25e0b0e]28        self.assertGreater(self.o.get_delay_ms(), 0.)
[8eff66d]29
30    def test_get_minioi(self):
[25e0b0e]31        self.assertGreater(self.o.get_minioi(), 0)
[8eff66d]32
33    def test_get_minioi_s(self):
[25e0b0e]34        self.assertGreater(self.o.get_minioi_s(), 0.)
[8eff66d]35
36    def test_get_minioi_ms(self):
[25e0b0e]37        self.assertGreater(self.o.get_minioi_ms(), 0.)
[8eff66d]38
39    def test_get_threshold(self):
[25e0b0e]40        self.assertGreater(self.o.get_threshold(), 0.)
[8eff66d]41
42    def test_set_delay(self):
43        val = 256
44        self.o.set_delay(val)
45        assert_equal (self.o.get_delay(), val)
46
47    def test_set_delay_s(self):
48        val = .05
49        self.o.set_delay_s(val)
50        assert_almost_equal (self.o.get_delay_s(), val)
51
52    def test_set_delay_ms(self):
53        val = 50.
54        self.o.set_delay_ms(val)
55        assert_almost_equal (self.o.get_delay_ms(), val)
56
57    def test_set_minioi(self):
58        val = 200
59        self.o.set_minioi(val)
60        assert_equal (self.o.get_minioi(), val)
61
62    def test_set_minioi_s(self):
63        val = 0.04
64        self.o.set_minioi_s(val)
65        assert_almost_equal (self.o.get_minioi_s(), val)
66
67    def test_set_minioi_ms(self):
68        val = 40.
69        self.o.set_minioi_ms(val)
70        assert_almost_equal (self.o.get_minioi_ms(), val)
71
72    def test_set_threshold(self):
73        val = 0.2
74        self.o.set_threshold(val)
75        assert_almost_equal (self.o.get_threshold(), val)
76
77class aubio_onset_96000(aubio_onset_params):
78    samplerate = 96000
79
80class aubio_onset_32000(aubio_onset_params):
81    samplerate = 32000
82
83class aubio_onset_8000(aubio_onset_params):
84    samplerate = 8000
[312826c]85
[11c0d74]86class aubio_onset_coverate(TestCase):
87    # extra tests to execute the C routines and improve coverage
88
89    def test_all_methods(self):
90        for method in ['default', 'energy', 'hfc', 'complexdomain', 'complex',
91                'phase', 'wphase', 'mkl', 'kl', 'specflux', 'specdiff',
92                'old_default']:
93            o = onset(method=method, buf_size=512, hop_size=256)
94            o(fvec(256))
95
96    def test_get_methods(self):
97        o = onset(method='default', buf_size=512, hop_size=256)
98
99        assert o.get_silence() == -70
100        o.set_silence(-20)
101        assert_almost_equal(o.get_silence(), -20)
102
103        assert o.get_compression() == 1
104        o.set_compression(.99)
105        assert_almost_equal(o.get_compression(), .99)
106
107        assert o.get_awhitening() == 0
108        o.set_awhitening(1)
109        assert o.get_awhitening() == 1
110
111        o.get_last()
112        o.get_last_ms()
113        o.get_last_s()
114        o.get_descriptor()
115        o.get_thresholded_descriptor()
116
117
[312826c]118if __name__ == '__main__':
119    main()
Note: See TracBrowser for help on using the repository browser.