summaryrefslogtreecommitdiff
path: root/numpy/polynomial/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/polynomial/tests')
-rw-r--r--numpy/polynomial/tests/test_chebyshev.py18
-rw-r--r--numpy/polynomial/tests/test_classes.py28
-rw-r--r--numpy/polynomial/tests/test_hermite.py17
-rw-r--r--numpy/polynomial/tests/test_hermite_e.py21
-rw-r--r--numpy/polynomial/tests/test_laguerre.py17
-rw-r--r--numpy/polynomial/tests/test_legendre.py17
-rw-r--r--numpy/polynomial/tests/test_polynomial.py16
-rw-r--r--numpy/polynomial/tests/test_polyutils.py8
8 files changed, 80 insertions, 62 deletions
diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py
index 82c3ba9ea..a596905f6 100644
--- a/numpy/polynomial/tests/test_chebyshev.py
+++ b/numpy/polynomial/tests/test_chebyshev.py
@@ -400,14 +400,14 @@ class TestFitting(TestCase):
return x*(x - 1)*(x - 2)
# Test exceptions
- assert_raises(ValueError, cheb.chebfit, [1], [1], -1)
- assert_raises(TypeError, cheb.chebfit, [[1]], [1], 0)
- assert_raises(TypeError, cheb.chebfit, [], [1], 0)
- assert_raises(TypeError, cheb.chebfit, [1], [[[1]]], 0)
- assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0)
- assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0)
- assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]])
- assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1])
+ assert_raises(ValueError, cheb.chebfit, [1], [1], -1)
+ assert_raises(TypeError, cheb.chebfit, [[1]], [1], 0)
+ assert_raises(TypeError, cheb.chebfit, [], [1], 0)
+ assert_raises(TypeError, cheb.chebfit, [1], [[[1]]], 0)
+ assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0)
+ assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0)
+ assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]])
+ assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
@@ -532,7 +532,7 @@ class TestMisc(TestCase):
assert_almost_equal(cheb.chebpts1(2), tgt)
tgt = [-0.86602540378443871, 0, 0.86602540378443871]
assert_almost_equal(cheb.chebpts1(3), tgt)
- tgt = [-0.9238795325, -0.3826834323, 0.3826834323, 0.9238795325]
+ tgt = [-0.9238795325, -0.3826834323, 0.3826834323, 0.9238795325]
assert_almost_equal(cheb.chebpts1(4), tgt)
def test_chebpts2(self):
diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py
index f9134b8c1..cd5a54687 100644
--- a/numpy/polynomial/tests/test_classes.py
+++ b/numpy/polynomial/tests/test_classes.py
@@ -10,12 +10,10 @@ from numbers import Number
import numpy as np
from numpy.polynomial import (
- Polynomial, Legendre, Chebyshev, Laguerre,
- Hermite, HermiteE)
+ Polynomial, Legendre, Chebyshev, Laguerre, Hermite, HermiteE)
from numpy.testing import (
- TestCase, assert_almost_equal, assert_raises,
- assert_equal, assert_, run_module_suite, dec)
-from numpy.testing.noseclasses import KnownFailure
+ assert_almost_equal, assert_raises, assert_equal, assert_,
+ run_module_suite)
from numpy.compat import long
@@ -410,6 +408,9 @@ def check_roots(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
tgt = np.sort(random((5,)))
+ res = np.sort(Poly.fromroots(tgt, domain=d, window=w).roots())
+ assert_almost_equal(res, tgt)
+ # default domain and window
res = np.sort(Poly.fromroots(tgt).roots())
assert_almost_equal(res, tgt)
@@ -468,6 +469,12 @@ def check_deriv(Poly):
p3 = p1.integ(1, k=[1])
assert_almost_equal(p2.deriv(1).coef, p3.coef)
assert_almost_equal(p2.deriv(2).coef, p1.coef)
+ # default domain and window
+ p1 = Poly([1, 2, 3])
+ p2 = p1.integ(2, k=[1, 2])
+ p3 = p1.integ(1, k=[1])
+ assert_almost_equal(p2.deriv(1).coef, p3.coef)
+ assert_almost_equal(p2.deriv(2).coef, p1.coef)
def check_linspace(Poly):
@@ -491,11 +498,18 @@ def check_linspace(Poly):
def check_pow(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
- tgt = Poly([1], domain=d, window=d)
- tst = Poly([1, 2, 3], domain=d, window=d)
+ tgt = Poly([1], domain=d, window=w)
+ tst = Poly([1, 2, 3], domain=d, window=w)
+ for i in range(5):
+ assert_poly_almost_equal(tst**i, tgt)
+ tgt = tgt * tst
+ # default domain and window
+ tgt = Poly([1])
+ tst = Poly([1, 2, 3])
for i in range(5):
assert_poly_almost_equal(tst**i, tgt)
tgt = tgt * tst
+ # check error for invalid powers
assert_raises(ValueError, op.pow, tgt, 1.5)
assert_raises(ValueError, op.pow, tgt, -1)
diff --git a/numpy/polynomial/tests/test_hermite.py b/numpy/polynomial/tests/test_hermite.py
index ac60007d1..e67625a88 100644
--- a/numpy/polynomial/tests/test_hermite.py
+++ b/numpy/polynomial/tests/test_hermite.py
@@ -119,7 +119,6 @@ class TestEvaluation(TestCase):
y = [polyval(x, c) for c in Hlist]
for i in range(10):
msg = "At i=%d" % i
- ser = np.zeros
tgt = y[i]
res = herm.hermval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -389,14 +388,14 @@ class TestFitting(TestCase):
return x*(x - 1)*(x - 2)
# Test exceptions
- assert_raises(ValueError, herm.hermfit, [1], [1], -1)
- assert_raises(TypeError, herm.hermfit, [[1]], [1], 0)
- assert_raises(TypeError, herm.hermfit, [], [1], 0)
- assert_raises(TypeError, herm.hermfit, [1], [[[1]]], 0)
- assert_raises(TypeError, herm.hermfit, [1, 2], [1], 0)
- assert_raises(TypeError, herm.hermfit, [1], [1, 2], 0)
- assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[[1]])
- assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1, 1])
+ assert_raises(ValueError, herm.hermfit, [1], [1], -1)
+ assert_raises(TypeError, herm.hermfit, [[1]], [1], 0)
+ assert_raises(TypeError, herm.hermfit, [], [1], 0)
+ assert_raises(TypeError, herm.hermfit, [1], [[[1]]], 0)
+ assert_raises(TypeError, herm.hermfit, [1, 2], [1], 0)
+ assert_raises(TypeError, herm.hermfit, [1], [1, 2], 0)
+ assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[[1]])
+ assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
diff --git a/numpy/polynomial/tests/test_hermite_e.py b/numpy/polynomial/tests/test_hermite_e.py
index 5341dc7ff..f8601a828 100644
--- a/numpy/polynomial/tests/test_hermite_e.py
+++ b/numpy/polynomial/tests/test_hermite_e.py
@@ -6,7 +6,9 @@ from __future__ import division, absolute_import, print_function
import numpy as np
import numpy.polynomial.hermite_e as herme
from numpy.polynomial.polynomial import polyval
-from numpy.testing import *
+from numpy.testing import (
+ TestCase, assert_almost_equal, assert_raises,
+ assert_equal, assert_, run_module_suite)
He0 = np.array([1])
He1 = np.array([0, 1])
@@ -117,7 +119,6 @@ class TestEvaluation(TestCase):
y = [polyval(x, c) for c in Helist]
for i in range(10):
msg = "At i=%d" % i
- ser = np.zeros
tgt = y[i]
res = herme.hermeval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -388,14 +389,14 @@ class TestFitting(TestCase):
return x*(x - 1)*(x - 2)
# Test exceptions
- assert_raises(ValueError, herme.hermefit, [1], [1], -1)
- assert_raises(TypeError, herme.hermefit, [[1]], [1], 0)
- assert_raises(TypeError, herme.hermefit, [], [1], 0)
- assert_raises(TypeError, herme.hermefit, [1], [[[1]]], 0)
- assert_raises(TypeError, herme.hermefit, [1, 2], [1], 0)
- assert_raises(TypeError, herme.hermefit, [1], [1, 2], 0)
- assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[[1]])
- assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[1, 1])
+ assert_raises(ValueError, herme.hermefit, [1], [1], -1)
+ assert_raises(TypeError, herme.hermefit, [[1]], [1], 0)
+ assert_raises(TypeError, herme.hermefit, [], [1], 0)
+ assert_raises(TypeError, herme.hermefit, [1], [[[1]]], 0)
+ assert_raises(TypeError, herme.hermefit, [1, 2], [1], 0)
+ assert_raises(TypeError, herme.hermefit, [1], [1, 2], 0)
+ assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[[1]])
+ assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
diff --git a/numpy/polynomial/tests/test_laguerre.py b/numpy/polynomial/tests/test_laguerre.py
index b3d8fe5ee..1dc57a960 100644
--- a/numpy/polynomial/tests/test_laguerre.py
+++ b/numpy/polynomial/tests/test_laguerre.py
@@ -116,7 +116,6 @@ class TestEvaluation(TestCase):
y = [polyval(x, c) for c in Llist]
for i in range(7):
msg = "At i=%d" % i
- ser = np.zeros
tgt = y[i]
res = lag.lagval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -386,14 +385,14 @@ class TestFitting(TestCase):
return x*(x - 1)*(x - 2)
# Test exceptions
- assert_raises(ValueError, lag.lagfit, [1], [1], -1)
- assert_raises(TypeError, lag.lagfit, [[1]], [1], 0)
- assert_raises(TypeError, lag.lagfit, [], [1], 0)
- assert_raises(TypeError, lag.lagfit, [1], [[[1]]], 0)
- assert_raises(TypeError, lag.lagfit, [1, 2], [1], 0)
- assert_raises(TypeError, lag.lagfit, [1], [1, 2], 0)
- assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[[1]])
- assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[1, 1])
+ assert_raises(ValueError, lag.lagfit, [1], [1], -1)
+ assert_raises(TypeError, lag.lagfit, [[1]], [1], 0)
+ assert_raises(TypeError, lag.lagfit, [], [1], 0)
+ assert_raises(TypeError, lag.lagfit, [1], [[[1]]], 0)
+ assert_raises(TypeError, lag.lagfit, [1, 2], [1], 0)
+ assert_raises(TypeError, lag.lagfit, [1], [1, 2], 0)
+ assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[[1]])
+ assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py
index e248f005d..8ac1feb58 100644
--- a/numpy/polynomial/tests/test_legendre.py
+++ b/numpy/polynomial/tests/test_legendre.py
@@ -120,7 +120,6 @@ class TestEvaluation(TestCase):
y = [polyval(x, c) for c in Llist]
for i in range(10):
msg = "At i=%d" % i
- ser = np.zeros
tgt = y[i]
res = leg.legval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -390,14 +389,14 @@ class TestFitting(TestCase):
return x*(x - 1)*(x - 2)
# Test exceptions
- assert_raises(ValueError, leg.legfit, [1], [1], -1)
- assert_raises(TypeError, leg.legfit, [[1]], [1], 0)
- assert_raises(TypeError, leg.legfit, [], [1], 0)
- assert_raises(TypeError, leg.legfit, [1], [[[1]]], 0)
- assert_raises(TypeError, leg.legfit, [1, 2], [1], 0)
- assert_raises(TypeError, leg.legfit, [1], [1, 2], 0)
- assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[[1]])
- assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[1, 1])
+ assert_raises(ValueError, leg.legfit, [1], [1], -1)
+ assert_raises(TypeError, leg.legfit, [[1]], [1], 0)
+ assert_raises(TypeError, leg.legfit, [], [1], 0)
+ assert_raises(TypeError, leg.legfit, [1], [[[1]]], 0)
+ assert_raises(TypeError, leg.legfit, [1, 2], [1], 0)
+ assert_raises(TypeError, leg.legfit, [1], [1, 2], 0)
+ assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[[1]])
+ assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py
index 77092cd2f..c806a8497 100644
--- a/numpy/polynomial/tests/test_polynomial.py
+++ b/numpy/polynomial/tests/test_polynomial.py
@@ -420,14 +420,14 @@ class TestMisc(TestCase):
return x*(x - 1)*(x - 2)
# Test exceptions
- assert_raises(ValueError, poly.polyfit, [1], [1], -1)
- assert_raises(TypeError, poly.polyfit, [[1]], [1], 0)
- assert_raises(TypeError, poly.polyfit, [], [1], 0)
- assert_raises(TypeError, poly.polyfit, [1], [[[1]]], 0)
- assert_raises(TypeError, poly.polyfit, [1, 2], [1], 0)
- assert_raises(TypeError, poly.polyfit, [1], [1, 2], 0)
- assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[[1]])
- assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1, 1])
+ assert_raises(ValueError, poly.polyfit, [1], [1], -1)
+ assert_raises(TypeError, poly.polyfit, [[1]], [1], 0)
+ assert_raises(TypeError, poly.polyfit, [], [1], 0)
+ assert_raises(TypeError, poly.polyfit, [1], [[[1]]], 0)
+ assert_raises(TypeError, poly.polyfit, [1, 2], [1], 0)
+ assert_raises(TypeError, poly.polyfit, [1], [1, 2], 0)
+ assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[[1]])
+ assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
diff --git a/numpy/polynomial/tests/test_polyutils.py b/numpy/polynomial/tests/test_polyutils.py
index c77ee2435..974e2e09a 100644
--- a/numpy/polynomial/tests/test_polyutils.py
+++ b/numpy/polynomial/tests/test_polyutils.py
@@ -5,7 +5,9 @@ from __future__ import division, absolute_import, print_function
import numpy as np
import numpy.polynomial.polyutils as pu
-from numpy.testing import *
+from numpy.testing import (
+ TestCase, assert_almost_equal, assert_raises,
+ assert_equal, assert_, run_module_suite)
class TestMisc(TestCase):
@@ -101,3 +103,7 @@ class TestDomain(TestCase):
tgt = [-1 + 1j, 1 - 1j]
res = pu.mapparms(dom1, dom2)
assert_almost_equal(res, tgt)
+
+
+if __name__ == "__main__":
+ run_module_suite()