copapy/tests/test_coparun_module.py

39 lines
764 B
Python
Raw Normal View History

2025-10-18 21:20:40 +00:00
from copapy import cpvalue, Target, NumLike
import pytest
2025-10-07 21:20:43 +00:00
2025-10-04 21:20:25 +00:00
2025-10-18 21:20:40 +00:00
def function(c1: NumLike) -> list[NumLike]:
2025-10-14 21:21:23 +00:00
i1 = c1 / 4 + c1 / -4 - c1 // 4 * c1 // -4 + (c1 * -1) // 4
2025-10-04 21:20:25 +00:00
2025-10-14 21:21:23 +00:00
r1 = i1 / 32.4 + 54 * c1
r2 = 65 * c1 + 8
r3 = c1 > r2
return [r1, r2, r3]
def test_compile():
2025-10-18 21:20:40 +00:00
c1 = cpvalue(16)
2025-10-07 21:20:43 +00:00
2025-10-08 20:47:49 +00:00
ret = function(c1)
tg = Target()
2025-10-05 21:09:43 +00:00
print('* compile and copy ...')
2025-10-04 21:20:25 +00:00
tg.compile(ret)
2025-10-05 21:09:43 +00:00
#time.sleep(5)
print('* run and copy ...')
2025-10-07 20:56:04 +00:00
tg.run()
2025-10-05 21:09:43 +00:00
#print('* finished')
2025-10-08 20:47:49 +00:00
ret_ref = function(16)
2025-10-04 21:20:25 +00:00
for test, ref, name in zip(ret, ret_ref, ['i1', 'i2', 'r1', 'r2']):
2025-10-08 20:21:33 +00:00
val = tg.read_value(test)
print('+', name, val, ref)
2025-10-18 21:20:40 +00:00
assert val == pytest.approx(ref, 1e-5), name
if __name__ == "__main__":
test_compile()