diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-07-29 09:25:40 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2017-07-29 09:33:11 -0600 |
commit | 3b8d3bd155def203da0136b223ec7fabac425337 (patch) | |
tree | 783eb546b58a168960a8faf5ed7ee23ef2871f94 /numpy/polynomial/tests/test_chebyshev.py | |
parent | d7b1349fac9cdb2e41b6337bec1b5b33915a01eb (diff) | |
download | numpy-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_chebyshev.py')
-rw-r--r-- | numpy/polynomial/tests/test_chebyshev.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py index 74701af1a..1a34f42b0 100644 --- a/numpy/polynomial/tests/test_chebyshev.py +++ b/numpy/polynomial/tests/test_chebyshev.py @@ -471,24 +471,29 @@ class TestFitting(object): assert_almost_equal(coef1, coef2) -class TestInterp(object): +class TestInterpolate(object): - @staticmethod - def f(x): + def f(self, x): return x * (x - 1) * (x - 2) def test_raises(self): - assert_raises(ValueError, cheb.chebinterp, self.f, -1, [-1, 1]) - assert_raises(ValueError, cheb.chebinterp, self.f, 10.1, [-1, 1]) + assert_raises(ValueError, cheb.chebinterpolate, self.f, -1) + assert_raises(TypeError, cheb.chebinterpolate, self.f, 10.) def test_dimensions(self): - for i in range(1, 5): - assert_(cheb.chebinterp(self.f, i, [-1, 1]).shape == (i+1,)) + for deg in range(1, 5): + assert_(cheb.chebinterpolate(self.f, deg).shape == (deg + 1,)) + + def test_approximation(self): + + def powx(x, p): + return x**p - def test_approx(self): - assert_almost_equal(cheb.chebinterp(lambda x: [1, 1, 1, 1], 3, [-1, 1]), np.array([1, 0, 0, 0])) - assert_almost_equal(cheb.chebinterp(lambda x: x, 3, [-1, 1]), np.array([0, 1, 0, 0])) - assert_almost_equal(cheb.chebinterp(self.f, 3, [-1, 1]), np.array([-3/2, 11/4, -3/2, 1/4])) + x = np.linspace(-1, 1, 10) + for deg in range(0, 10): + for p in range(0, deg + 1): + c = cheb.chebinterpolate(powx, deg, (p,)) + assert_almost_equal(cheb.chebval(x, c), powx(x, p), decimal=12) class TestCompanion(object): |