tests/python/src/utils/scale.py: replace with python/tests/test_scale.py
authorPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 20:40:00 +0000 (15:40 -0500)
committerPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 20:40:00 +0000 (15:40 -0500)
python/tests/test_scale.py [new file with mode: 0755]
tests/python/src/utils/scale.py [deleted file]

diff --git a/python/tests/test_scale.py b/python/tests/test_scale.py
new file mode 100755 (executable)
index 0000000..279af4b
--- /dev/null
@@ -0,0 +1,18 @@
+#! /usr/bin/env python
+
+from numpy.testing import TestCase, run_module_suite
+from numpy.testing import assert_equal, assert_almost_equal
+from numpy import arange
+from aubio import fvec, scale
+
+class aubio_cvec_test_case(TestCase):
+
+    def test_scale_simple(self):
+        a = arange(10).astype('float32')
+        s = scale ( 0., 10., 3., 8.)
+        s(a)
+        assert_equal ( a, [ 3., 3.5, 4., 4.5, 5., 5.5, 6., 6.5, 7., 7.5])
+
+if __name__ == '__main__':
+    from unittest import main
+    main()
diff --git a/tests/python/src/utils/scale.py b/tests/python/src/utils/scale.py
deleted file mode 100644 (file)
index 510873e..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-from template import aubio_unit_template
-from localaubio import *
-
-buf_size = 2000
-channels = 2
-
-ilow = .40
-ihig = 40.00
-olow = 100.0
-ohig = 1000.
-
-class scale_unit(aubio_unit_template):
-
-  def setUp(self):
-    self.o = new_aubio_scale(ilow, ihig, olow, ohig)
-
-  def tearDown(self):
-    del_aubio_scale(self.o)
-
-  def test(self):
-    """ create and delete scale """
-    pass
-
-  def test_zeroes(self):
-    """ test scale on zeroes """
-    input = new_fvec(buf_size, channels)
-    aubio_scale_do(self.o, input)
-    for index in range(buf_size):
-      for channel in range(channels):
-        expval = (- ilow) * (ohig - olow) / \
-          (ihig - ilow) + olow
-        val = fvec_read_sample(input, channel, index)
-        self.assertCloseEnough(expval, val)
-    del_fvec(input)
-
-  def test_ilow(self):
-    """ test scale on ilow """
-    input = new_fvec(buf_size, channels)
-    for index in range(buf_size):
-      for channel in range(channels):
-        fvec_write_sample(input, ilow, channel, index)
-    aubio_scale_do(self.o, input)
-    for index in range(buf_size):
-      for channel in range(channels):
-        val = fvec_read_sample(input, channel, index)
-        self.assertAlmostEqual(olow, val)
-    del_fvec(input)
-
-  def test_ihig(self):
-    """ test scale on ihig """
-    input = new_fvec(buf_size, channels)
-    for index in range(buf_size):
-      for channel in range(channels):
-        fvec_write_sample(input, ihig, channel, index)
-    aubio_scale_do(self.o, input)
-    for index in range(buf_size):
-      for channel in range(channels):
-        val = fvec_read_sample(input, channel, index)
-        self.assertCloseEnough(ohig, val)
-    del_fvec(input)
-
-  def test_climbing_ramp(self):
-    """ test scale on climbing ramp """
-    input = new_fvec(buf_size, channels)
-    for index in range(buf_size):
-      for channel in range(channels):
-        rampval = index*(ihig-ilow)/buf_size + ilow 
-        fvec_write_sample(input, rampval, channel, index)
-    aubio_scale_do(self.o, input)
-    for index in range(buf_size):
-      for channel in range(channels):
-        expval = index*(ohig-olow)/buf_size + olow
-        self.assertCloseEnough(expval, \
-          fvec_read_sample(input, channel, index))
-    del_fvec(input)
-
-  def test_falling_ramp(self):
-    """ test scale on falling ramp """
-    input = new_fvec(buf_size, channels)
-    for index in range(buf_size):
-      for channel in range(channels):
-        fvec_write_sample(input, ihig \
-          - index*(ihig-ilow)/buf_size, \
-          channel, index)
-    aubio_scale_do(self.o, input)
-    for index in range(buf_size):
-      for channel in range(channels):
-        expval = ohig - index*(ohig-olow)/buf_size
-        self.assertCloseEnough(expval, \
-          fvec_read_sample(input, channel, index))
-    del_fvec(input)
-
-if __name__ == '__main__': unittest.main()