Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

REf Unit test refactor of unary methods completed.

  • Loading branch information...
commit b5612dee0b06037714ccee357a870c19f9d81756 1 parent f768fdd
@kwgoodman authored
View
4 README.rst
@@ -122,9 +122,9 @@ After you have installed ``la``, run the suite of unit tests::
>>> import la
>>> la.test()
<snip>
- Ran 2995 tests in 11.011s
+ Ran 2994 tests in 11.011s
OK
- <nose.result.TextTestResult run=2995 errors=0 failures=0>
+ <nose.result.TextTestResult run=2994 errors=0 failures=0>
The ``la`` package contains C extensions that speed up common alignment
operations such as adding two unaligned larrys. If the C extensions don't
View
78 la/tests/deflarry_test.py
@@ -48,84 +48,6 @@ def test_init_array(self):
actual = larry(self.array)
ale(actual, self.desired, msg='create larry from array')
-class Test_unary(unittest.TestCase):
- "Test unary functions of larry class"
-
- def setUp(self):
- self.tol = 1e-8
- self.nancode = -9999
- self.x = np.array([[ 1.0, 1.0],
- [ 1.0, 1.0],
- [ 1.0, 1.0]])
- self.l = larry(self.x)
- self.x2 = np.array([1.0, 1.0])
- self.l2 = larry(self.x2)
- self.x3 = np.random.rand(2,3,4)
- self.l3 = larry(self.x3)
- self.l4 = larry([ nan, 0.0, np.inf, -10.0, -np.inf])
-
- def test_clip_4(self):
- "larry.clip_4"
- self.failUnlessRaises(ValueError, self.l.clip, 3, 2)
-
- def test_nan_replace_1(self):
- "larry.nan_replace_1"
- t = np.array([[ 1.0, 1.0],
- [ 1.0, 1.0],
- [ 1.0, 1.0]])
- p = self.l.nan_replace(0.0)
- msg = printfail(t, p.x, 'x')
- t[np.isnan(t)] = self.nancode
- p[np.isnan(p.x)] = self.nancode
- self.assert_((abs(t - p) < self.tol).all(), msg)
- label = [[0,1,2], [0,1]]
- self.assert_(label == p.label, printfail(label, p.label, 'label'))
- self.assert_(noreference(p, self.l), 'Reference found')
-
- def test_nan_replace_2(self):
- "larry.nan_replace_2"
- t = np.array([[ 1.0, 0.0],
- [ 1.0, 1.0],
- [ 1.0, 1.0]])
- p = self.l
- p[0,1] = np.nan
- p = p.nan_replace(0.0)
- msg = printfail(t, p.x, 'x')
- t[np.isnan(t)] = self.nancode
- p[np.isnan(p.x)] = self.nancode
- self.assert_((abs(t - p) < self.tol).all(), msg)
- label = [[0,1,2], [0,1]]
- self.assert_(label == p.label, printfail(label, p.label, 'label'))
- self.assert_(noreference(p, self.l), 'Reference found')
-
- def test_nan_replace_3(self):
- "larry.nan_replace_3"
- self.x3[0,0] = 999
- t = larry(self.x3.copy())
- p = self.l3
- p[0,0] = 999
- msg = printfail(t, p, 'larry')
- t[np.isnan(t.x)] = self.nancode
- p[np.isnan(p.x)] = self.nancode
- self.assert_((abs(t - p) < self.tol).all(), msg)
- self.assert_(noreference(p, t), 'Reference found')
-
- def test_invert_2(self):
- "larry.invert_2"
- y = larry([0, 1])
- self.failUnlessRaises(TypeError, y.invert)
-
- def test___invert___1(self):
- "larry.__invert___1"
- o = larry([True, False])
- d = larry([False, True])
- ale(~o, d, 'invert_1', original=o)
-
- def test___invert___2(self):
- "larry.__invert___2"
- y = larry([0, 1])
- self.failUnlessRaises(TypeError, y.invert)
-
class Test_binary(unittest.TestCase):
"Test binary functions of Data class"
View
62 la/tests/deflarry_unary_test.py
@@ -44,8 +44,6 @@ def arrays(dtypes=DTYPES, nans=True):
yield -a
"""
-# Unary functions -----------------------------------------------------------
-
def unit_maker(name, npfunc, arg={'la':[], 'np':[]}, imag=True):
"Test that larry.xxx gives the same output as np.xxx."
msg = '\nfunc %s | input %s (%s) | shape %s | axis %s\n'
@@ -61,86 +59,98 @@ def unit_maker(name, npfunc, arg={'la':[], 'np':[]}, imag=True):
ale(actual, desired, msg=name, original=original)
def test_log():
- "Test log"
yield unit_maker, "log", np.log
def test_exp():
- "Test exp"
yield unit_maker, "exp", np.exp
def test_sqrt():
- "Test sqrt"
yield unit_maker, "sqrt", np.sqrt
def test_sign():
- "Test sign"
yield unit_maker, "sign", np.sign
def test_power():
- "Test power"
yield unit_maker, "power", np.power, {'la':[1.3], 'np':[1.3]}
def test___pow__():
- "Test __pow__"
yield unit_maker, "__pow__", np.power, {'la':[1.3], 'np':[1.3]}
def test_cumsum():
- "Test cumsum"
yield unit_maker, "cumsum", np.cumsum, {'la':[0], 'np':[0]}
yield unit_maker, "cumsum", np.cumsum, {'la':[-1], 'np':[-1]}
def test_cumprod():
- "Test cumprod"
yield unit_maker, "cumprod", np.cumprod, {'la':[0], 'np':[0]}
yield unit_maker, "cumprod", np.cumprod, {'la':[-1], 'np':[-1]}
def test_clip():
- "Test clip"
yield unit_maker, "clip", np.clip, {'la':[-1,1], 'np':[-1,1]}
def test___neg__():
- "Test __neg__"
yield unit_maker, "__neg__", np.negative
-def positive(a):
- return a.copy()
-
def test___pos__():
- "Test __pos__"
+ def positive(a):
+ return a.copy()
yield unit_maker, "__pos__", positive
def test_abs():
- "Test abs"
yield unit_maker, "abs", np.absolute, {'la':[], 'np':[]}, False
def test___abs__():
- "Test __abs__"
yield unit_maker, "__abs__", np.absolute, {'la':[], 'np':[]}, False
def test_isnan():
- "Test isnan"
yield unit_maker, "isnan", np.isnan
def test_isfinite():
- "Test isfinite"
yield unit_maker, "isfinite", np.isfinite
def test_isinf():
- "Test isinf"
yield unit_maker, "isinf", np.isinf
+def test_nan_replace():
+ def nanreplace(a, w=0):
+ a = a.copy()
+ a[np.isnan(a)] = w
+ return a
+ yield unit_maker, "nan_replace", nanreplace
+
def test_invert():
- "larry.invert"
o = la.larry([True, False])
d = la.larry([False, True])
ale(o.invert(), d, 'invert', original=o)
- y = la.larry([0, 1])
- assert_raises(TypeError, y.invert)
def test___invert__():
- "larry.__invert__"
o = la.larry([True, False])
d = la.larry([False, True])
ale(~o, d, '__invert__', original=o)
+
+# assert raises -------------------------------------------------------------
+
+def test_cumsum_raises():
+ "cumsum raises"
+ y = la.larry([0, 1])
+ assert_raises(ValueError, y.cumsum, None)
+
+def test_cumprod_raises():
+ "cumprod raises"
y = la.larry([0, 1])
- assert_raises(TypeError, y.invert)
+ assert_raises(ValueError, y.cumprod, None)
+
+def test_clip_raises():
+ "clip raises"
+ y = la.larry([0, 1])
+ assert_raises(ValueError, y.clip, 3, 2)
+
+def test_invert_raises():
+ "invert raises"
+ y = la.larry([0, 1])
+ assert_raises(TypeError, y.invert)
+
+def test___invert__raises():
+ "invert raises"
+ y = la.larry([0, 1])
+ assert_raises(TypeError, y.invert)
+
Please sign in to comment.
Something went wrong with that request. Please try again.