(self)
| 226 | class TestIntegral: |
| 227 | |
| 228 | def test_legint(self): |
| 229 | # check exceptions |
| 230 | assert_raises(TypeError, leg.legint, [0], .5) |
| 231 | assert_raises(ValueError, leg.legint, [0], -1) |
| 232 | assert_raises(ValueError, leg.legint, [0], 1, [0, 0]) |
| 233 | assert_raises(ValueError, leg.legint, [0], lbnd=[0]) |
| 234 | assert_raises(ValueError, leg.legint, [0], scl=[0]) |
| 235 | assert_raises(TypeError, leg.legint, [0], axis=.5) |
| 236 | |
| 237 | # test integration of zero polynomial |
| 238 | for i in range(2, 5): |
| 239 | k = [0] * (i - 2) + [1] |
| 240 | res = leg.legint([0], m=i, k=k) |
| 241 | assert_almost_equal(res, [0, 1]) |
| 242 | |
| 243 | # check single integration with integration constant |
| 244 | for i in range(5): |
| 245 | scl = i + 1 |
| 246 | pol = [0] * i + [1] |
| 247 | tgt = [i] + [0] * i + [1 / scl] |
| 248 | legpol = leg.poly2leg(pol) |
| 249 | legint = leg.legint(legpol, m=1, k=[i]) |
| 250 | res = leg.leg2poly(legint) |
| 251 | assert_almost_equal(trim(res), trim(tgt)) |
| 252 | |
| 253 | # check single integration with integration constant and lbnd |
| 254 | for i in range(5): |
| 255 | scl = i + 1 |
| 256 | pol = [0] * i + [1] |
| 257 | legpol = leg.poly2leg(pol) |
| 258 | legint = leg.legint(legpol, m=1, k=[i], lbnd=-1) |
| 259 | assert_almost_equal(leg.legval(-1, legint), i) |
| 260 | |
| 261 | # check single integration with integration constant and scaling |
| 262 | for i in range(5): |
| 263 | scl = i + 1 |
| 264 | pol = [0] * i + [1] |
| 265 | tgt = [i] + [0] * i + [2 / scl] |
| 266 | legpol = leg.poly2leg(pol) |
| 267 | legint = leg.legint(legpol, m=1, k=[i], scl=2) |
| 268 | res = leg.leg2poly(legint) |
| 269 | assert_almost_equal(trim(res), trim(tgt)) |
| 270 | |
| 271 | # check multiple integrations with default k |
| 272 | for i in range(5): |
| 273 | for j in range(2, 5): |
| 274 | pol = [0] * i + [1] |
| 275 | tgt = pol[:] |
| 276 | for k in range(j): |
| 277 | tgt = leg.legint(tgt, m=1) |
| 278 | res = leg.legint(pol, m=j) |
| 279 | assert_almost_equal(trim(res), trim(tgt)) |
| 280 | |
| 281 | # check multiple integrations with defined k |
| 282 | for i in range(5): |
| 283 | for j in range(2, 5): |
| 284 | pol = [0] * i + [1] |
| 285 | tgt = pol[:] |
nothing calls this directly
no test coverage detected