[Scipy-svn] r3821 - trunk/scipy/sandbox/cdavid/tests
scipy-svn@scip...
scipy-svn@scip...
Sat Jan 12 03:23:52 CST 2008
Author: matthew.brett@gmail.com
Date: 2008-01-12 03:23:49 -0600 (Sat, 12 Jan 2008)
New Revision: 3821
Modified:
trunk/scipy/sandbox/cdavid/tests/test_autocorr.py
trunk/scipy/sandbox/cdavid/tests/test_lpc.py
trunk/scipy/sandbox/cdavid/tests/test_segmentaxis.py
Log:
Nose tests for cdavid sandbox
Modified: trunk/scipy/sandbox/cdavid/tests/test_autocorr.py
===================================================================
--- trunk/scipy/sandbox/cdavid/tests/test_autocorr.py 2008-01-12 08:49:56 UTC (rev 3820)
+++ trunk/scipy/sandbox/cdavid/tests/test_autocorr.py 2008-01-12 09:23:49 UTC (rev 3821)
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# Last Change: Fri Dec 15 10:00 PM 2006 J
-from numpy.testing import *
+from scipy.testing import *
from numpy.random import randn, seed
from numpy import correlate, array, concatenate, require, corrcoef
from numpy.fft import fft, ifft
@@ -9,12 +9,11 @@
from numpy.ctypeslib import ndpointer, load_library
from ctypes import c_uint
-set_package_path()
-from cdavid.autocorr import _raw_autocorr_1d, _raw_autocorr_1d_noncontiguous
-from cdavid.autocorr import autocorr_oneside_nofft as autocorr
-from cdavid.autocorr import autocorr_fft , nextpow2
-from cdavid.autocorr import _autocorr_oneside_nofft_py as autocorr_py
-restore_path()
+from scipy.sandbox.cdavid.autocorr import _raw_autocorr_1d, \
+ _raw_autocorr_1d_noncontiguous, \
+ autocorr_oneside_nofft as autocorr,\
+ autocorr_fft , nextpow2, \
+ _autocorr_oneside_nofft_py as autocorr_py
import numpy
@@ -42,8 +41,8 @@
# This class tests the C functions directly. This is more a debugging tool
# that a test case, as the tested functions are not part of the public API
-class TestCType1D(NumpyTestCase):
- def check_contiguous_double(self):
+class TestCType1D(TestCase):
+ def test_contiguous_double(self):
# double test
xt = xc1
yt = _raw_autocorr_1d(xt, xt.size - 1)
@@ -53,7 +52,7 @@
assert_array_equal(yt, yr)
- def check_contiguous_float(self):
+ def test_contiguous_float(self):
# float test
xt = xcf1
@@ -64,7 +63,7 @@
assert_array_equal(yt, yr)
- def check_non_contiguous_double(self):
+ def test_non_contiguous_double(self):
# double test
xt = xf1
yt = _raw_autocorr_1d_noncontiguous(xt, xt.size - 1)
@@ -74,7 +73,7 @@
assert_array_equal(yt, yr)
- def check_non_contiguous_float(self):
+ def test_non_contiguous_float(self):
# float test
xt = xff1
yt = _raw_autocorr_1d_noncontiguous(xt, xt.size - 1)
@@ -85,8 +84,8 @@
assert_array_equal(yt, yr)
# Test autocorrelation for rank 1 arrays
-class TestAutoCorr1D(NumpyTestCase):
- def check_contiguous_double(self):
+class TestAutoCorr1D(TestCase):
+ def test_contiguous_double(self):
# double test
xt = xc1
yt = autocorr(xt, xt.size - 1)
@@ -96,7 +95,7 @@
assert_array_equal(yt, yr)
- def check_contiguous_float(self):
+ def test_contiguous_float(self):
# float test
xt = xcf1
@@ -107,7 +106,7 @@
assert_array_equal(yt, yr)
- def check_non_contiguous_double(self):
+ def test_non_contiguous_double(self):
# double test
xt = xf1
yt = autocorr(xt, xt.size - 1)
@@ -117,7 +116,7 @@
assert_array_equal(yt, yr)
- def check_non_contiguous_float(self):
+ def test_non_contiguous_float(self):
# float test
xt = xff1
yt = autocorr(xt, xt.size - 1)
@@ -131,8 +130,8 @@
# with rank 2 arrays. This will be used in the above test cases;
# this function implements the expected behaviour of the public
# autocorr function.
-class TestAutoCorrPy(NumpyTestCase):
- def check_full(self):
+class TestAutoCorrPy(TestCase):
+ def test_full(self):
xt = xc
axis = -1
lag = xt.shape[axis] - 1
@@ -155,7 +154,7 @@
center = xt[:,i].size - 1
assert_array_equal(tmp[center:center+1+lag], yt[:, i])
- def check_partial(self):
+ def test_partial(self):
xt = xc
axis = -1
lag = 1
@@ -179,8 +178,8 @@
assert_array_equal(tmp[center:center+1+lag], yt[:, i])
# Test autocorrelation for rank 2 arrays
-class TestAutoCorr2D(NumpyTestCase):
- def check_double_full(self):
+class TestAutoCorr2D(TestCase):
+ def test_double_full(self):
# C, axis 1 test
xt = xc
axis = -1
@@ -217,7 +216,7 @@
yr = autocorr_py(xt, lag, axis = axis)
assert_array_equal(yt, yr)
- def check_float(self):
+ def test_float(self):
# C, axis 1 test
xt = xcf
axis = -1
@@ -254,7 +253,7 @@
yr = autocorr_py(xt, lag, axis = axis)
assert_array_equal(yt, yr)
- def check_double_partial(self):
+ def test_double_partial(self):
# C, axis 1 test
xt = xc
axis = -1
@@ -291,15 +290,15 @@
yr = autocorr_py(xt, lag, axis = axis)
assert_array_equal(yt, yr)
-class TestAutoCorrFFT(NumpyTestCase):
+class TestAutoCorrFFT(TestCase):
n = 5
d = 3
- def check_nextpow2(self):
+ def test_nextpow2(self):
assert(nextpow2(255) == 8)
assert(nextpow2(256) == 8)
assert(nextpow2(257) == 9)
- def check_r1r(self):
+ def test_r1r(self):
"""real case, rank 1"""
a = randn(self.n)
@@ -308,7 +307,7 @@
assert_array_almost_equal(atest, aref, decimal = md)
assert atest.dtype == a.dtype
- def check_r1c(self):
+ def test_r1c(self):
"""complex case, rank 1"""
a = randn(self.n) + 1.0j * randn(self.n)
@@ -317,11 +316,11 @@
assert_array_almost_equal(atest[self.n - 1], aref, decimal = md)
assert atest.dtype == a.dtype
- def check_r2c(self):
+ def test_r2c(self):
"""complex case, rank 2"""
pass
- def check_r2r(self):
+ def test_r2r(self):
"""real case, rank 2"""
# axis 0
@@ -345,10 +344,10 @@
assert_array_almost_equal(atest, aref, decimal = md)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
-#class TestAutocorr2d(NumpyTestCase):
-# def check_double(self):
+#class TestAutocorr2d(TestCase):
+# def test_double(self):
# # C, axis 1 test
# xt = xc
# axis = -1
@@ -393,7 +392,7 @@
# tmp = correlate(xt[i], xt[i], 'full')
# assert_array_equal(tmp[lag:], yt[i])
#
-# def check_float(self):
+# def test_float(self):
# # C, axis 1 test
# xt = xcf
# axis = -1
Modified: trunk/scipy/sandbox/cdavid/tests/test_lpc.py
===================================================================
--- trunk/scipy/sandbox/cdavid/tests/test_lpc.py 2008-01-12 08:49:56 UTC (rev 3820)
+++ trunk/scipy/sandbox/cdavid/tests/test_lpc.py 2008-01-12 09:23:49 UTC (rev 3821)
@@ -1,19 +1,15 @@
#! /usr/bin/env python
# Last Change: Tue Nov 28 05:00 PM 2006 J
-from numpy.testing import *
+from scipy.testing import *
from numpy.random import randn, seed
from numpy import correlate, array, concatenate, require
from numpy.ctypeslib import ndpointer, load_library
from ctypes import c_uint
+from scipy.sandbox.cdavid.lpc import _lpc2_py as lpc_py, \
+ lpc_ref, lpc2, autocorr_oneside_nofft
-set_package_path()
-from cdavid.lpc import _lpc2_py as lpc_py
-from cdavid.lpc import lpc_ref, lpc2
-from cdavid.autocorr import autocorr_oneside_nofft
-restore_path()
-
import numpy
# number of decimals to check
@@ -41,8 +37,8 @@
# This class uses lpc in 1 dimension and loop on the axis. Is tested against
# a direct matrix inversion of the autocorrelation matrix (using matrix inverse
# instead of levinson durbin)
-class TestLpcPy(NumpyTestCase):
- def check_float(self):
+class TestLpcPy(TestCase):
+ def test_float(self):
# Axis -1
xt = xcf
axis = -1
@@ -71,7 +67,7 @@
assert_array_almost_equal(tmp, a)
- def check_double(self):
+ def test_double(self):
# Axis -1
xt = xc
axis = -1
@@ -100,8 +96,8 @@
assert_array_almost_equal(tmp, a)
-class TestLpc(NumpyTestCase):
- def check_float(self):
+class TestLpc(TestCase):
+ def test_float(self):
# Axis -1
xt = xcf
axis = -1
@@ -130,7 +126,7 @@
assert_array_almost_equal(e, et)
assert_array_almost_equal(k, kt)
- def check_float_rank1(self):
+ def test_float_rank1(self):
# test rank 1
xt = xcf[0]
axis = 0
@@ -145,7 +141,7 @@
assert_array_almost_equal(e, et)
assert_array_almost_equal(k, kt)
- def check_double(self):
+ def test_double(self):
# Axis -1
xt = xc
axis = -1
@@ -170,7 +166,7 @@
assert_array_almost_equal(e, et)
assert_array_almost_equal(k, kt)
- def check_double_rank1(self):
+ def test_double_rank1(self):
# test rank 1
xt = xc[0]
axis = 0
@@ -184,4 +180,4 @@
assert_array_almost_equal(k, kt)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/sandbox/cdavid/tests/test_segmentaxis.py
===================================================================
--- trunk/scipy/sandbox/cdavid/tests/test_segmentaxis.py 2008-01-12 08:49:56 UTC (rev 3820)
+++ trunk/scipy/sandbox/cdavid/tests/test_segmentaxis.py 2008-01-12 09:23:49 UTC (rev 3821)
@@ -1,21 +1,21 @@
#! /usr/bin/env python
# Last Change: Fri Dec 15 10:00 PM 2006 J
-from numpy.testing import *
+from scipy.testing import *
import numpy as N
-set_package_path()
-from cdavid.segmentaxis import segment_axis
-restore_path()
+from scipy.sandbox.cdavid.segmentaxis import segment_axis
+
+
# #Optional:
# set_local_path()
# # import modules that are located in the same directory as this file.
-# restore_path()
-class TestSegment(NumpyTestCase):
- def check_simple(self):
+
+class TestSegment(TestCase):
+ def test_simple(self):
assert_equal(segment_axis(N.arange(6),length=3,overlap=0),
N.array([[0,1,2],[3,4,5]]))
@@ -25,7 +25,7 @@
assert_equal(segment_axis(N.arange(7),length=3,overlap=2),
N.array([[0,1,2],[1,2,3],[2,3,4],[3,4,5],[4,5,6]]))
- def check_error_checking(self):
+ def test_error_checking(self):
self.assertRaises(ValueError,
lambda: segment_axis(N.arange(7),length=3,overlap=-1))
self.assertRaises(ValueError,
@@ -35,7 +35,7 @@
self.assertRaises(ValueError,
lambda: segment_axis(N.arange(7),length=8,overlap=3))
- def check_ending(self):
+ def test_ending(self):
assert_equal(segment_axis(N.arange(6),length=3,overlap=1,end='cut'),
N.array([[0,1,2],[2,3,4]]))
assert_equal(segment_axis(N.arange(6),length=3,overlap=1,end='wrap'),
@@ -43,7 +43,7 @@
assert_equal(segment_axis(N.arange(6),length=3,overlap=1,end='pad',endvalue=-17),
N.array([[0,1,2],[2,3,4],[4,5,-17]]))
- def check_multidimensional(self):
+ def test_multidimensional(self):
assert_equal(segment_axis(N.ones((2,3,4,5,6)),axis=3,length=3,overlap=1).shape,
(2,3,4,2,3,6))
@@ -61,4 +61,4 @@
(2,3,2,3,5,6))
if __name__=='__main__':
- NumpyTest().run()
+ unittest.main()
More information about the Scipy-svn
mailing list