summaryrefslogtreecommitdiff
path: root/test/test_function.py
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2014-09-29 12:55:56 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2014-09-29 12:55:56 +0200
commite4f1c09672068e4778f7b5f3e27b47ff8986863c (patch)
treea6550b5f2683d1e9537a5fb250e3513a85719697 /test/test_function.py
parentfa6b1e375eb8a4b93582d2935352447849e66203 (diff)
+mul_scalar, tests restructured and cosmetics
Diffstat (limited to 'test/test_function.py')
-rw-r--r--test/test_function.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/test_function.py b/test/test_function.py
index 014ecac..7420011 100644
--- a/test/test_function.py
+++ b/test/test_function.py
@@ -29,6 +29,13 @@ def test_pwc():
assert_almost_equal(f.abs_avrg(), (1.0+0.5+0.5*1.5+1.5*0.75)/4.0,
decimal=16)
+
+def test_pwc_add():
+ # some random data
+ x = [0.0, 1.0, 2.0, 2.5, 4.0]
+ y = [1.0, -0.5, 1.5, 0.75]
+ f = spk.PieceWiseConstFunc(x, y)
+
f1 = copy(f)
x = [0.0, 0.75, 2.0, 2.5, 2.7, 4.0]
y = [0.5, 1.0, -0.25, 0.0, 1.5]
@@ -48,6 +55,17 @@ def test_pwc():
assert_array_almost_equal(f1.x, f2.x, decimal=16)
assert_array_almost_equal(f1.y, 2*f2.y, decimal=16)
+def test_pwc_mul():
+ x = [0.0, 1.0, 2.0, 2.5, 4.0]
+ y = [1.0, -0.5, 1.5, 0.75]
+ f = spk.PieceWiseConstFunc(x, y)
+
+ f.mul_scalar(1.5)
+ assert_array_almost_equal(f.x, x, decimal=16)
+ assert_array_almost_equal(f.y, 1.5*np.array(y), decimal=16)
+ f.mul_scalar(1.0/5.0)
+ assert_array_almost_equal(f.y, 1.5/5.0*np.array(y), decimal=16)
+
def test_pwl():
x = [0.0, 1.0, 2.0, 2.5, 4.0]
@@ -67,6 +85,13 @@ def test_pwl():
abs_avrg_expected = (1.25 + 0.45 + 0.75 + 1.5*0.5) / 4.0
assert_almost_equal(f.abs_avrg(), abs_avrg_expected, decimal=16)
+
+def test_pwl_add():
+ x = [0.0, 1.0, 2.0, 2.5, 4.0]
+ y1 = [1.0, -0.5, 1.5, 0.75]
+ y2 = [1.5, -0.4, 1.5, 0.25]
+ f = spk.PieceWiseLinFunc(x, y1, y2)
+
f1 = copy(f)
x = [0.0, 0.75, 2.0, 2.5, 2.7, 4.0]
y1 = [0.5, 1.0, -0.25, 0.0, 1.5]
@@ -94,5 +119,19 @@ def test_pwl():
assert_array_almost_equal(f1.y2, 2*f2.y2, decimal=16)
+def test_pwc_mul():
+ x = [0.0, 1.0, 2.0, 2.5, 4.0]
+ y1 = [1.0, -0.5, 1.5, 0.75]
+ y2 = [1.5, -0.4, 1.5, 0.25]
+ f = spk.PieceWiseLinFunc(x, y1, y2)
+
+ f.mul_scalar(1.5)
+ assert_array_almost_equal(f.x, x, decimal=16)
+ assert_array_almost_equal(f.y1, 1.5*np.array(y1), decimal=16)
+ assert_array_almost_equal(f.y2, 1.5*np.array(y2), decimal=16)
+ f.mul_scalar(1.0/5.0)
+ assert_array_almost_equal(f.y1, 1.5/5.0*np.array(y1), decimal=16)
+ assert_array_almost_equal(f.y2, 1.5/5.0*np.array(y2), decimal=16)
+
if __name__ == "__main__":
test_pwc()