source: python/tests/test_hztomel.py @ 71655fee

feature/cnn_orgfeature/crepe_org
Last change on this file since 71655fee was ab8e838, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] capture hztomel warnings

  • Property mode set to 100755
File size: 3.7 KB
RevLine 
[2886984]1#! /usr/bin/env python
2
3from unittest import main
4from numpy.testing import TestCase
5from numpy.testing import assert_equal, assert_almost_equal
[ab8e838]6from _tools import assert_warns
[2886984]7import numpy as np
8import aubio
9
10from aubio import hztomel, meltohz
11from aubio import hztomel_htk, meltohz_htk
12
13
14class aubio_hztomel_test_case(TestCase):
15
16    def test_hztomel(self):
17        assert_equal(hztomel(0.), 0.)
18        assert_almost_equal(hztomel(400. / 3.), 2., decimal=5)
[0d07a2a]19        assert_almost_equal(hztomel(1000. / 3), 5.)
[2886984]20        assert_equal(hztomel(200.), 3.)
21        assert_almost_equal(hztomel(1000.), 15)
22        assert_almost_equal(hztomel(6400), 42)
23        assert_almost_equal(hztomel(40960), 69)
24
25        for m in np.linspace(0, 1000, 100):
26            assert_almost_equal(hztomel(meltohz(m)) - m, 0, decimal=3)
27
28    def test_meltohz(self):
29        assert_equal(meltohz(0.), 0.)
30        assert_almost_equal(meltohz(2), 400. / 3., decimal=4)
31        assert_equal(meltohz(3.), 200.)
32        assert_almost_equal(meltohz(5), 1000. / 3., decimal=4)
33        assert_almost_equal(meltohz(15), 1000., decimal=4)
34        assert_almost_equal(meltohz(42), 6400., decimal=2)
35        assert_almost_equal(meltohz(69), 40960., decimal=1)
36
37        for f in np.linspace(0, 20000, 1000):
38            assert_almost_equal(meltohz(hztomel(f)) - f, 0, decimal=1)
39
40    def test_meltohz_negative(self):
[ab8e838]41        with assert_warns(UserWarning):
42            assert_equal(meltohz(-1), 0)
[2886984]43
44    def test_hztomel_negative(self):
[ab8e838]45        with assert_warns(UserWarning):
46            assert_equal(hztomel(-1), 0)
[2886984]47
48
49class aubio_hztomel_htk_test_case(TestCase):
50
51    def test_meltohz(self):
52        assert_equal(meltohz(0, htk=True), 0)
53        assert_almost_equal(meltohz(2595, htk=True), 6300., decimal=1)
54
55    def test_hztomel(self):
56        assert_equal(hztomel(0, htk=True), 0)
57        assert_almost_equal(hztomel(3428.7, htk=True), 2000., decimal=1)
58        assert_almost_equal(hztomel(6300, htk=True), 2595., decimal=1)
59
60    def test_meltohz_negative(self):
[ab8e838]61        with assert_warns(UserWarning):
62            assert_equal(meltohz(-1, htk=True), 0)
[2886984]63        assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
64        assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
65
66    def test_hztomel_negative(self):
[ab8e838]67        with assert_warns(UserWarning):
68            assert_equal(meltohz(-1, htk=True), 0)
69        with assert_warns(UserWarning):
70            assert_equal(hztomel(-1, htk=True), 0)
[2886984]71        assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
72
73    def test_hztomel_htk(self):
74        for f in np.linspace(0, 20000, 1000):
75            assert_almost_equal(meltohz_htk(hztomel_htk(f)) - f, 0, decimal=1)
76        for f in np.linspace(0, 20000, 1000):
77            assert_almost_equal(hztomel_htk(meltohz_htk(f)) - f, 0, decimal=1)
78
79
80class aubio_hztomel_wrong_values(TestCase):
81    """ more tests to cover all branches """
82
83    def test_hztomel_wrong_values(self):
84        with self.assertRaises(TypeError):
85            hztomel('s')
86
87    def test_meltohz_wrong_values(self):
88        with self.assertRaises(TypeError):
89            meltohz(bytes('ad'))
90
91    def test_meltohz_no_arg(self):
92        with self.assertRaises(TypeError):
93            meltohz()
94
95    def test_meltohz_htk_no_arg(self):
96        with self.assertRaises(TypeError):
97            meltohz_htk()
98
99    def test_hztomel_htk_wrong_values(self):
100        with self.assertRaises(TypeError):
101            hztomel_htk('0')
102
103    def test_hztomel_htk_false(self):
104        assert hztomel(120, htk=False) == hztomel(120)
105
106    def test_meltohz_htk_false(self):
107        assert meltohz(12, htk=False) == meltohz(12)
108
109
110if __name__ == '__main__':
111    from unittest import main
112    main()
Note: See TracBrowser for help on using the repository browser.