2025-10-23 15:23:12 +00:00
|
|
|
from copapy import variable, Target
|
2025-10-20 20:23:31 +00:00
|
|
|
import pytest
|
|
|
|
|
import copapy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_compile():
|
2025-10-23 15:23:12 +00:00
|
|
|
c_i = variable(9)
|
|
|
|
|
c_f = variable(2.5)
|
|
|
|
|
# c_b = variable(True)
|
2025-10-20 20:23:31 +00:00
|
|
|
|
2025-10-23 22:36:22 +00:00
|
|
|
ret_test = (c_f ** c_f, c_i ** c_i)#, c_i & 3)
|
|
|
|
|
ret_ref = (2.5 ** 2.5, 9 ** 9)#, 9 & 3)
|
2025-10-20 20:23:31 +00:00
|
|
|
|
|
|
|
|
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}"
|
2025-10-23 21:24:57 +00:00
|
|
|
assert val == pytest.approx(ref, 2), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType]
|
2025-10-20 20:23:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
test_compile()
|