MCPcopy Create free account
hub / github.com/numpy/numpy / test_legint

Method test_legint

numpy/polynomial/tests/test_legendre.py:209–290  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

207class TestIntegral:
208
209 def test_legint(self):
210 # check exceptions
211 assert_raises(TypeError, leg.legint, [0], .5)
212 assert_raises(ValueError, leg.legint, [0], -1)
213 assert_raises(ValueError, leg.legint, [0], 1, [0, 0])
214 assert_raises(ValueError, leg.legint, [0], lbnd=[0])
215 assert_raises(ValueError, leg.legint, [0], scl=[0])
216 assert_raises(TypeError, leg.legint, [0], axis=.5)
217
218 # test integration of zero polynomial
219 for i in range(2, 5):
220 k = [0]*(i - 2) + [1]
221 res = leg.legint([0], m=i, k=k)
222 assert_almost_equal(res, [0, 1])
223
224 # check single integration with integration constant
225 for i in range(5):
226 scl = i + 1
227 pol = [0]*i + [1]
228 tgt = [i] + [0]*i + [1/scl]
229 legpol = leg.poly2leg(pol)
230 legint = leg.legint(legpol, m=1, k=[i])
231 res = leg.leg2poly(legint)
232 assert_almost_equal(trim(res), trim(tgt))
233
234 # check single integration with integration constant and lbnd
235 for i in range(5):
236 scl = i + 1
237 pol = [0]*i + [1]
238 legpol = leg.poly2leg(pol)
239 legint = leg.legint(legpol, m=1, k=[i], lbnd=-1)
240 assert_almost_equal(leg.legval(-1, legint), i)
241
242 # check single integration with integration constant and scaling
243 for i in range(5):
244 scl = i + 1
245 pol = [0]*i + [1]
246 tgt = [i] + [0]*i + [2/scl]
247 legpol = leg.poly2leg(pol)
248 legint = leg.legint(legpol, m=1, k=[i], scl=2)
249 res = leg.leg2poly(legint)
250 assert_almost_equal(trim(res), trim(tgt))
251
252 # check multiple integrations with default k
253 for i in range(5):
254 for j in range(2, 5):
255 pol = [0]*i + [1]
256 tgt = pol[:]
257 for k in range(j):
258 tgt = leg.legint(tgt, m=1)
259 res = leg.legint(pol, m=j)
260 assert_almost_equal(trim(res), trim(tgt))
261
262 # check multiple integrations with defined k
263 for i in range(5):
264 for j in range(2, 5):
265 pol = [0]*i + [1]
266 tgt = pol[:]

Callers

nothing calls this directly

Calls 3

assert_raisesFunction · 0.90
assert_almost_equalFunction · 0.90
trimFunction · 0.70

Tested by

no test coverage detected