summaryrefslogtreecommitdiff
path: root/numpy/polynomial/tests/test_classes.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-07-29 09:25:40 -0600
committerCharles Harris <charlesr.harris@gmail.com>2017-07-29 09:33:11 -0600
commit3b8d3bd155def203da0136b223ec7fabac425337 (patch)
tree783eb546b58a168960a8faf5ed7ee23ef2871f94 /numpy/polynomial/tests/test_classes.py
parentd7b1349fac9cdb2e41b6337bec1b5b33915a01eb (diff)
downloadnumpy-3b8d3bd155def203da0136b223ec7fabac425337.tar.gz
MAINT: Rename chebinterp to chebinterpolation and add test.
* Rename chebinterp to chebinterpolation as suggested. * Make some fixes to the Chebyshev class function. * Refactor TestInterpolation. * Add test for the Chebyshev.interpolation class function.
Diffstat (limited to 'numpy/polynomial/tests/test_classes.py')
-rw-r--r--numpy/polynomial/tests/test_classes.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py
index 46d721df4..2ec8277ff 100644
--- a/numpy/polynomial/tests/test_classes.py
+++ b/numpy/polynomial/tests/test_classes.py
@@ -583,5 +583,30 @@ def check_ufunc_override(Poly):
assert_raises(TypeError, np.add, x, p)
+class TestInterpolate(object):
+
+ def f(self, x):
+ return x * (x - 1) * (x - 2)
+
+ def test_raises(self):
+ assert_raises(ValueError, Chebyshev.interpolate, self.f, -1)
+ assert_raises(TypeError, Chebyshev.interpolate, self.f, 10.)
+
+ def test_dimensions(self):
+ for deg in range(1, 5):
+ assert_(Chebyshev.interpolate(self.f, deg).degree() == deg)
+
+ def test_approximation(self):
+
+ def powx(x, p):
+ return x**p
+
+ x = np.linspace(0, 2, 10)
+ for deg in range(0, 10):
+ for t in range(0, deg + 1):
+ p = Chebyshev.interpolate(powx, deg, domain=[0, 2], args=(t,))
+ assert_almost_equal(p(x), powx(x, t), decimal=12)
+
+
if __name__ == "__main__":
run_module_suite()