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