summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2015-01-19 22:32:42 +0100
committerMario Mulansky <mario.mulansky@gmx.net>2015-01-19 22:32:42 +0100
commit6c0f966649c8dedd4115d6809e569732ee5709c9 (patch)
treee85e90e0dc29bbdae414f4eaae356d22b259695b /test
parent66968eedd276eb5d661b25d92775203546a3d646 (diff)
interval averages for discrete functions
Diffstat (limited to 'test')
-rw-r--r--test/test_function.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_function.py b/test/test_function.py
index ba87db8..da3d851 100644
--- a/test/test_function.py
+++ b/test/test_function.py
@@ -203,6 +203,33 @@ def test_pwl_avrg():
assert_array_almost_equal(f_avrg.y2, y2_expected, decimal=16)
+def test_df():
+ # testing discrete function
+ x = [0.0, 1.0, 2.0, 2.5, 4.0]
+ y = [0.0, 1.0, 1.0, 0.0, 1.0]
+ mp = [1.0, 2.0, 1.0, 2.0, 1.0]
+ f = spk.DiscreteFunction(x, y, mp)
+ xp, yp = f.get_plottable_data()
+
+ xp_expected = [0.0, 1.0, 2.0, 2.5, 4.0]
+ yp_expected = [0.0, 0.5, 1.0, 0.0, 1.0]
+ assert_array_almost_equal(xp, xp_expected, decimal=16)
+ assert_array_almost_equal(yp, yp_expected, decimal=16)
+
+ avrg_expected = 2.0 / 5.0
+ assert_almost_equal(f.avrg(), avrg_expected, decimal=16)
+
+ # interval averaging
+ a = f.avrg([0.5, 2.4])
+ assert_almost_equal(a, 2.0/3.0, decimal=16)
+ a = f.avrg([1.5, 3.5])
+ assert_almost_equal(a, 1.0/3.0, decimal=16)
+ a = f.avrg((0.9, 3.5))
+ assert_almost_equal(a, 2.0/5.0, decimal=16)
+ a = f.avrg([1.1, 4.0])
+ assert_almost_equal(a, 1.0/3.0, decimal=16)
+
+
if __name__ == "__main__":
test_pwc()
test_pwc_add()