source: interfaces/python/test_aubio.py @ ae6e15c

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ae6e15c was ae6e15c, checked in by Paul Brossier <piem@piem.org>, 15 years ago

interfaces/python: improve draft wrapper alpha_norm example, add some unit tests

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import unittest
2from _aubio import *
3from numpy import array
4
5class aubiomodule_test_case(unittest.TestCase):
6
7  def setUp(self):
8    """ try importing aubio """
9
10  def test_vector(self):
11    a = fvec()
12    a.length, a.channels
13    a[0]
14    array(a)
15    a = fvec(10)
16    a = fvec(1, 2)
17    array(a).T
18    a[0] = range(a.length)
19    a[1][0] = 2
20
21  def test_wrong_values(self):
22    self.assertRaises (ValueError, fvec, -10)
23    self.assertRaises (ValueError, fvec, 1, -1)
24 
25    a = fvec(2, 3)
26    self.assertRaises (IndexError, a.__getitem__, 3)
27    self.assertRaises (IndexError, a[0].__getitem__, 2)
28
29  def test_alpha_norm_of_fvec(self):
30    a = fvec(2, 2)
31    self.assertEquals (alpha_norm(a, 1), 0)
32    a[0] = [1, 2] 
33    self.assertEquals (alpha_norm(a, 1), 1.5)
34    a[1] = [1, 2] 
35    self.assertEquals (alpha_norm(a, 1), 3)
36    a[0] = [0, 1]; a[1] = [1, 0]
37    self.assertEquals (alpha_norm(a, 2), 1)
38
39  def test_alpha_norm_of_array_of_float32(self):
40    a = array(1, dtype = 'float32')
41    self.assertRaises (ValueError, alpha_norm, a, 1)
42    a = array([[[1,2],[3,4]]], dtype = 'float32')
43    self.assertRaises (ValueError, alpha_norm, a, 1)
44    a = array(range(10), dtype = 'float32')
45    self.assertEquals (alpha_norm(a, 1), 4.5)
46    a = array([range(10), range(10)], dtype = 'float32')
47    self.assertEquals (alpha_norm(a, 1), 9)
48
49  def test_alpha_norm_of_array_of_float64(self):
50    a = array(1, dtype = 'float64')
51    self.assertRaises (ValueError, alpha_norm, a, 1)
52    a = array([[[1,2],[3,4]]], dtype = 'float64')
53    self.assertRaises (ValueError, alpha_norm, a, 1)
54    a = array(range(10), dtype = 'float64')
55    self.assertEquals (alpha_norm(a, 1), 4.5)
56    a = array([range(10), range(10)], dtype = 'float64')
57    self.assertEquals (alpha_norm(a, 1), 9)
58
59  def test_alpha_norm_of_array_of_int(self):
60    a = array(1, dtype = 'int')
61    self.assertRaises (ValueError, alpha_norm, a, 1)
62    a = array([[[1,2],[3,4]]], dtype = 'int')
63    self.assertRaises (ValueError, alpha_norm, a, 1)
64    a = array(range(10), dtype = 'int')
65    self.assertRaises (ValueError, alpha_norm, a, 1)
66
67  def test_alpha_norm_of_array_of_string (self):
68    a = "hello"
69    self.assertRaises (ValueError, alpha_norm, a, 1)
70
71if __name__ == '__main__':
72  unittest.main()
Note: See TracBrowser for help on using the repository browser.