From 0d1d0a03c99f595f800bc186603ca05b316ef4e1 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Thu, 23 Oct 2025 12:48:13 +0200 Subject: [PATCH] Test for iif function added --- tests/test_prog_flow.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_prog_flow.py diff --git a/tests/test_prog_flow.py b/tests/test_prog_flow.py new file mode 100644 index 0000000..b863210 --- /dev/null +++ b/tests/test_prog_flow.py @@ -0,0 +1,31 @@ +from copapy import cpvalue, Target, iif +import pytest +import copapy + + +def test_compile(): + c_i = cpvalue(9) + c_f = cpvalue(2.5) + # c_b = cpvalue(True) + + ret_test = (iif(c_f > 5, c_f, -1), iif(c_i > 5, c_f, 8.8), iif(c_i > 2, c_i, 1)) + ret_ref = (iif(2.5 > 5, 2.5, -1), iif(9 > 5, 2.5, 8.8), iif(9 > 2, 9, 1)) + + tg = Target() + print('* compile and copy ...') + tg.compile(ret_test) + print('* run and copy ...') + tg.run() + print('* finished') + + for test, ref in zip(ret_test, ret_ref): + assert isinstance(test, copapy.CPNumber) + val = tg.read_value(test) + print('+', val, ref, type(val), test.dtype) + #for t in (int, float, bool): + # assert isinstance(val, t) == isinstance(ref, t), f"Result type does not match for {val} and {ref}" + assert val == pytest.approx(ref, 0.001), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType] + + +if __name__ == "__main__": + test_compile()