diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2018-09-19 16:53:50 -0700 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2018-09-19 16:58:11 -0700 |
commit | 50b85d976f2f5ec7e40faec1ede047cf45b10bc1 (patch) | |
tree | 98f7f1b61cc2ee68c8c6dab1a5a0d651d6fd38b4 /test | |
parent | 5178df8d74bcdde310f8007ac891dd8a1bf4a9d2 (diff) |
Fix incorrect integrals in PieceWiseLinFunc (#38)
Integrals of piece-wise linear functions were incorrect if the
requested interval lies completely between two support points.
This has been fixed, and a unit test exercising this behavior
was added.
Fixes #38
Diffstat (limited to 'test')
-rw-r--r-- | test/test_function.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/test/test_function.py b/test/test_function.py index ddeb4b1..6c04839 100644 --- a/test/test_function.py +++ b/test/test_function.py @@ -136,7 +136,7 @@ def test_pwc_integral(): # test part interval, spanning an edge assert_equal(f1.integral((0.5,1.5)), 0.5*1.0 + 0.5*-0.5) # test part interval, just over two edges - assert_almost_equal(f1.integral((1.0-1e-16,2+1e-16)), 1.0*-0.5, decimal=16) + assert_almost_equal(f1.integral((1.0-1e-16,2+1e-16)), 1.0*-0.5, decimal=14) # test part interval, between two edges assert_equal(f1.integral((1.0,2.0)), 1.0*-0.5) assert_equal(f1.integral((1.2,1.7)), (1.7-1.2)*-0.5) @@ -212,6 +212,18 @@ def test_pwl(): a = f.avrg([1.0, 4.0]) assert_almost_equal(a, (-0.45 + 0.75 + 1.5*0.5) / 3.0, decimal=16) + # interval between support points + a = f.avrg([1.1, 1.5]) + assert_almost_equal(a, (-0.5+0.1*0.1 - 0.45) * 0.5, decimal=14) + + # starting at a support point + a = f.avrg([1.0, 1.5]) + assert_almost_equal(a, (-0.5 - 0.45) * 0.5, decimal=14) + + # start and end at support point + a = f.avrg([1.0, 2.0]) + assert_almost_equal(a, (-0.5 - 0.4) * 0.5, decimal=14) + # averaging over multiple intervals a = f.avrg([(0.5, 1.5), (1.5, 2.5)]) assert_almost_equal(a, (1.375*0.5 - 0.45 + 0.75)/2.0, decimal=16) |