2025-10-04 21:07:37 +00:00
|
|
|
from copapy import const, Target
|
2025-10-04 21:20:25 +00:00
|
|
|
from pytest import approx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def function(c1, c2):
|
|
|
|
|
i1 = c1 * 3.3 + 5
|
|
|
|
|
i2 = c2 * 5 + c1
|
|
|
|
|
r1 = i1 + i2 * 55 / 4
|
|
|
|
|
r2 = 4 * i2 + 5
|
|
|
|
|
|
|
|
|
|
return i1, i2, r1, r2
|
2025-10-03 21:09:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_compile():
|
|
|
|
|
|
|
|
|
|
c1 = const(4)
|
2025-10-04 21:20:25 +00:00
|
|
|
c2 = const(2)
|
|
|
|
|
|
|
|
|
|
ret = function(c1, c2)
|
2025-10-03 21:09:25 +00:00
|
|
|
|
2025-10-03 21:26:51 +00:00
|
|
|
tg = Target()
|
2025-10-04 21:20:25 +00:00
|
|
|
tg.compile(ret)
|
2025-10-03 21:26:51 +00:00
|
|
|
tg.run()
|
2025-10-03 21:09:25 +00:00
|
|
|
|
2025-10-04 21:20:25 +00:00
|
|
|
ret_ref = function(4, 2)
|
|
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
for test, ref, name in zip(ret, ret_ref, ['i1', 'i2', 'r1', 'r2']):
|
|
|
|
|
assert tg.read_value(test) == approx(ref, 1e-5), name
|
2025-10-03 21:09:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
test_compile()
|