copapy/tests/test_coparun_module.py

39 lines
810 B
Python

from copapy import variable, Target, NumLike
import pytest
def function(c1: NumLike) -> list[NumLike]:
i1 = c1 / 4 + c1 / -4 - c1 // 4 * c1 // -4 + (c1 * -1) // 4
r1 = i1 / 32.4 + 54 * c1
r2 = 65 * c1 + 8
r3 = c1 > r2
return [r1, r2, r3]
def test_compile():
c1 = variable(16)
ret = function(c1)
tg = Target()
print('* compile and copy ...')
tg.compile(ret)
#time.sleep(5)
print('* run and copy ...')
tg.run()
#print('* finished')
ret_ref = function(16)
for test, ref, name in zip(ret, ret_ref, ['i1', 'i2', 'r1', 'r2']):
val = tg.read_value(test)
print('+', name, val, ref)
assert val == pytest.approx(ref, 1e-5), name # pyright: ignore[reportUnknownMemberType]
if __name__ == "__main__":
test_compile()