MCPcopy Index your code
hub / github.com/numpy/numpy / test_hermint

Method test_hermint

numpy/polynomial/tests/test_hermite.py:227–308  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

225class TestIntegral:
226
227 def test_hermint(self):
228 # check exceptions
229 assert_raises(TypeError, herm.hermint, [0], .5)
230 assert_raises(ValueError, herm.hermint, [0], -1)
231 assert_raises(ValueError, herm.hermint, [0], 1, [0, 0])
232 assert_raises(ValueError, herm.hermint, [0], lbnd=[0])
233 assert_raises(ValueError, herm.hermint, [0], scl=[0])
234 assert_raises(TypeError, herm.hermint, [0], axis=.5)
235
236 # test integration of zero polynomial
237 for i in range(2, 5):
238 k = [0] * (i - 2) + [1]
239 res = herm.hermint([0], m=i, k=k)
240 assert_almost_equal(res, [0, .5])
241
242 # check single integration with integration constant
243 for i in range(5):
244 scl = i + 1
245 pol = [0] * i + [1]
246 tgt = [i] + [0] * i + [1 / scl]
247 hermpol = herm.poly2herm(pol)
248 hermint = herm.hermint(hermpol, m=1, k=[i])
249 res = herm.herm2poly(hermint)
250 assert_almost_equal(trim(res), trim(tgt))
251
252 # check single integration with integration constant and lbnd
253 for i in range(5):
254 scl = i + 1
255 pol = [0] * i + [1]
256 hermpol = herm.poly2herm(pol)
257 hermint = herm.hermint(hermpol, m=1, k=[i], lbnd=-1)
258 assert_almost_equal(herm.hermval(-1, hermint), i)
259
260 # check single integration with integration constant and scaling
261 for i in range(5):
262 scl = i + 1
263 pol = [0] * i + [1]
264 tgt = [i] + [0] * i + [2 / scl]
265 hermpol = herm.poly2herm(pol)
266 hermint = herm.hermint(hermpol, m=1, k=[i], scl=2)
267 res = herm.herm2poly(hermint)
268 assert_almost_equal(trim(res), trim(tgt))
269
270 # check multiple integrations with default k
271 for i in range(5):
272 for j in range(2, 5):
273 pol = [0] * i + [1]
274 tgt = pol[:]
275 for k in range(j):
276 tgt = herm.hermint(tgt, m=1)
277 res = herm.hermint(pol, m=j)
278 assert_almost_equal(trim(res), trim(tgt))
279
280 # check multiple integrations with defined k
281 for i in range(5):
282 for j in range(2, 5):
283 pol = [0] * i + [1]
284 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