(self)
| 301 | class TestIntegral: |
| 302 | |
| 303 | def test_polyint(self): |
| 304 | # check exceptions |
| 305 | assert_raises(TypeError, poly.polyint, [0], .5) |
| 306 | assert_raises(ValueError, poly.polyint, [0], -1) |
| 307 | assert_raises(ValueError, poly.polyint, [0], 1, [0, 0]) |
| 308 | assert_raises(ValueError, poly.polyint, [0], lbnd=[0]) |
| 309 | assert_raises(ValueError, poly.polyint, [0], scl=[0]) |
| 310 | assert_raises(TypeError, poly.polyint, [0], axis=.5) |
| 311 | with assert_warns(DeprecationWarning): |
| 312 | poly.polyint([1, 1], 1.) |
| 313 | |
| 314 | # test integration of zero polynomial |
| 315 | for i in range(2, 5): |
| 316 | k = [0]*(i - 2) + [1] |
| 317 | res = poly.polyint([0], m=i, k=k) |
| 318 | assert_almost_equal(res, [0, 1]) |
| 319 | |
| 320 | # check single integration with integration constant |
| 321 | for i in range(5): |
| 322 | scl = i + 1 |
| 323 | pol = [0]*i + [1] |
| 324 | tgt = [i] + [0]*i + [1/scl] |
| 325 | res = poly.polyint(pol, m=1, k=[i]) |
| 326 | assert_almost_equal(trim(res), trim(tgt)) |
| 327 | |
| 328 | # check single integration with integration constant and lbnd |
| 329 | for i in range(5): |
| 330 | scl = i + 1 |
| 331 | pol = [0]*i + [1] |
| 332 | res = poly.polyint(pol, m=1, k=[i], lbnd=-1) |
| 333 | assert_almost_equal(poly.polyval(-1, res), i) |
| 334 | |
| 335 | # check single integration with integration constant and scaling |
| 336 | for i in range(5): |
| 337 | scl = i + 1 |
| 338 | pol = [0]*i + [1] |
| 339 | tgt = [i] + [0]*i + [2/scl] |
| 340 | res = poly.polyint(pol, m=1, k=[i], scl=2) |
| 341 | assert_almost_equal(trim(res), trim(tgt)) |
| 342 | |
| 343 | # check multiple integrations with default k |
| 344 | for i in range(5): |
| 345 | for j in range(2, 5): |
| 346 | pol = [0]*i + [1] |
| 347 | tgt = pol[:] |
| 348 | for k in range(j): |
| 349 | tgt = poly.polyint(tgt, m=1) |
| 350 | res = poly.polyint(pol, m=j) |
| 351 | assert_almost_equal(trim(res), trim(tgt)) |
| 352 | |
| 353 | # check multiple integrations with defined k |
| 354 | for i in range(5): |
| 355 | for j in range(2, 5): |
| 356 | pol = [0]*i + [1] |
| 357 | tgt = pol[:] |
| 358 | for k in range(j): |
| 359 | tgt = poly.polyint(tgt, m=1, k=[k]) |
| 360 | res = poly.polyint(pol, m=j, k=list(range(j))) |
nothing calls this directly
no test coverage detected