mirror of https://github.com/Nonannet/copapy.git
tests updated
This commit is contained in:
parent
7da48a7126
commit
8915201280
|
|
@ -70,12 +70,12 @@ def test_trig_precision():
|
||||||
tg.compile(ret_test)
|
tg.compile(ret_test)
|
||||||
tg.run()
|
tg.run()
|
||||||
|
|
||||||
for i, (test, ref) in enumerate(zip(ret_test, ret_refe)):
|
for i, (v, test, ref) in enumerate(zip(test_vals, ret_test, ret_refe)):
|
||||||
func_name = ['sin', 'cos', 'tan'][i % 3]
|
func_name = ['sin', 'cos', 'tan'][i % 3]
|
||||||
assert isinstance(test, cp.variable)
|
assert isinstance(test, cp.variable)
|
||||||
val = tg.read_value(test)
|
val = tg.read_value(test)
|
||||||
print(f"+ Result of {func_name}: {val}; reference: {ref}")
|
print(f"+ Result of {func_name}: {val}; reference: {ref}")
|
||||||
assert val == pytest.approx(ref, abs=1e-5), f"Result of {func_name} for input {test_vals[i // 3]} does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType]
|
assert val == pytest.approx(ref, abs=1e-3), f"Result of {func_name} for input {test_vals[i // 3]} does not match: {val} and reference: {ref} (value: {v})" # pyright: ignore[reportUnknownMemberType]
|
||||||
#if not val == pytest.approx(ref, abs=1e-5): # pyright: ignore[reportUnknownMemberType]
|
#if not val == pytest.approx(ref, abs=1e-5): # pyright: ignore[reportUnknownMemberType]
|
||||||
# warnings.warn(f"Result of {func_name} for input {test_vals[i // 3]} does not match: {val} and reference: {ref}", UserWarning)
|
# warnings.warn(f"Result of {func_name} for input {test_vals[i // 3]} does not match: {val} and reference: {ref}", UserWarning)
|
||||||
|
|
||||||
|
|
@ -88,11 +88,34 @@ def test_arcus_trig_precision():
|
||||||
ret_test = [r for v in test_vals for r in (cp.asin(variable(v)),
|
ret_test = [r for v in test_vals for r in (cp.asin(variable(v)),
|
||||||
cp.acos(variable(v)),
|
cp.acos(variable(v)),
|
||||||
cp.atan(variable(v)),
|
cp.atan(variable(v)),
|
||||||
cp.atan2(variable(v), variable(3)),)]
|
cp.atan2(variable(v), variable(3)),
|
||||||
|
cp.atan2(variable(v), variable(-3)),)]
|
||||||
ret_refe = [r for v in test_vals for r in (ma.asin(v),
|
ret_refe = [r for v in test_vals for r in (ma.asin(v),
|
||||||
ma.acos(v),
|
ma.acos(v),
|
||||||
ma.atan(v),
|
ma.atan(v),
|
||||||
ma.atan2(v, 3),)]
|
ma.atan2(v, 3),
|
||||||
|
ma.atan2(v, -3),)]
|
||||||
|
|
||||||
|
tg = Target()
|
||||||
|
tg.compile(ret_test)
|
||||||
|
tg.run()
|
||||||
|
|
||||||
|
for i, (test, ref) in enumerate(zip(ret_test, ret_refe)):
|
||||||
|
func_name = ['asin', 'acos', 'atan', 'atan2[1]', 'atan2[2]'][i % 5]
|
||||||
|
assert isinstance(test, cp.variable)
|
||||||
|
val = tg.read_value(test)
|
||||||
|
print(f"+ Result of {func_name}: {val}; reference: {ref}")
|
||||||
|
#assert val == pytest.approx(ref, abs=1e-5), f"Result of {func_name} for input {test_vals[i // 5]} does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType]
|
||||||
|
if not val == pytest.approx(ref, abs=1e-5): # pyright: ignore[reportUnknownMemberType]
|
||||||
|
warnings.warn(f"Result of {func_name} for input {test_vals[i // 5]} does not match: {val} and reference: {ref}", UserWarning)
|
||||||
|
|
||||||
|
|
||||||
|
def test_arcus_trig_crash():
|
||||||
|
|
||||||
|
v = 0.0
|
||||||
|
|
||||||
|
ret_test = [cp.asin(variable(v))]
|
||||||
|
ret_refe = [ma.asin(v)]
|
||||||
|
|
||||||
tg = Target()
|
tg = Target()
|
||||||
tg.compile(ret_test)
|
tg.compile(ret_test)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import warnings
|
||||||
import re
|
import re
|
||||||
import struct
|
import struct
|
||||||
import pytest
|
import pytest
|
||||||
|
import copapy as cp
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
# On Windows wsl and qemu-user is required:
|
# On Windows wsl and qemu-user is required:
|
||||||
|
|
@ -87,8 +88,8 @@ def test_compile():
|
||||||
c_f = variable(1.111)
|
c_f = variable(1.111)
|
||||||
c_b = variable(True)
|
c_b = variable(True)
|
||||||
|
|
||||||
ret_test = function1(c_i) + function1(c_f) + function2(c_i) + function2(c_f) + function3(c_i) + function4(c_i) + function5(c_b) + [variable(9) % 2] + iiftests(c_i) + iiftests(c_f)
|
ret_test = function1(c_i) + function1(c_f) + function2(c_i) + function2(c_f) + function3(c_i) + function4(c_i) + function5(c_b) + [variable(9) % 2] + iiftests(c_i) + iiftests(c_f) + [cp.asin(c_i/10)]
|
||||||
ret_ref = function1(9) + function1(1.111) + function2(9) + function2(1.111) + function3(9) + function4(9) + function5(True) + [9 % 2] + iiftests(9) + iiftests(1.111)
|
ret_ref = function1(9) + function1(1.111) + function2(9) + function2(1.111) + function3(9) + function4(9) + function5(True) + [9 % 2] + iiftests(9) + iiftests(1.111) + [cp.asin(9/10)]
|
||||||
|
|
||||||
out = [Write(r) for r in ret_test]
|
out = [Write(r) for r in ret_test]
|
||||||
|
|
||||||
|
|
@ -128,8 +129,13 @@ def test_compile():
|
||||||
warnings.warn("aarch64 runner not found, aarch64 test skipped!", UserWarning)
|
warnings.warn("aarch64 runner not found, aarch64 test skipped!", UserWarning)
|
||||||
return
|
return
|
||||||
|
|
||||||
command = ['build/runner/coparun-aarch64', 'build/runner/test-arm64.copapy'] + ['build/runner/test-arm64.copapy.bin']
|
command = qemu_command + ['build/runner/coparun-aarch64', 'build/runner/test-arm64.copapy'] + ['build/runner/test-arm64.copapy.bin']
|
||||||
result = run_command(qemu_command + command)
|
#try:
|
||||||
|
result = run_command(command)
|
||||||
|
#except FileNotFoundError:
|
||||||
|
# warnings.warn(f"Test skipped, executable not found.", UserWarning)
|
||||||
|
# return
|
||||||
|
|
||||||
print('* Output from runner:\n--')
|
print('* Output from runner:\n--')
|
||||||
print(result)
|
print(result)
|
||||||
print('--')
|
print('--')
|
||||||
|
|
@ -153,9 +159,9 @@ def test_compile():
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Unknown type: {test.dtype}")
|
raise Exception(f"Unknown type: {test.dtype}")
|
||||||
print('+', val, ref, test.dtype, f" addr={address}")
|
print('+', val, ref, test.dtype, f" addr={address}")
|
||||||
#for t in (int, float, bool):
|
for t in (int, float, bool):
|
||||||
# assert isinstance(val, t) == isinstance(ref, t), f"Result type does not match for {val} and {ref}"
|
assert isinstance(val, t) == isinstance(ref, t), f"Result type does not match for {val} and {ref}"
|
||||||
#assert val == pytest.approx(ref, 1e-5), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType]
|
assert val == pytest.approx(ref, 1e-5), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -77,15 +77,34 @@ def test_compile():
|
||||||
t4 = ((t3 * t1) * 2).sum()
|
t4 = ((t3 * t1) * 2).sum()
|
||||||
t5 = ((t3 * t1) * 2).magnitude()
|
t5 = ((t3 * t1) * 2).magnitude()
|
||||||
|
|
||||||
|
|
||||||
c_i = variable(9)
|
c_i = variable(9)
|
||||||
c_f = variable(1.111)
|
c_f = variable(1.111)
|
||||||
c_b = variable(True)
|
c_b = variable(True)
|
||||||
|
|
||||||
ret_test = function1(c_i) + function1(c_f) + function2(c_i) + function2(c_f) + function3(c_i) + function4(c_i) + function5(c_b) + [c_i % 2, sin(c_f)] + iiftests(c_i) + iiftests(c_f)
|
#ret_test = function1(c_i) + function1(c_f) + function2(c_i) + function2(c_f) + function3(c_i) + function4(c_i) + function5(c_b) + [c_i % 2, sin(c_f)] + iiftests(c_i) + iiftests(c_f)
|
||||||
ret_ref = function1(9) + function1(1.111) + function2(9) + function2(1.111) + function3(9) + function4(9) + function5(True) + [9 % 2, sin(1.111)] + iiftests(9) + iiftests(1.111)
|
#ret_ref = function1(9) + function1(1.111) + function2(9) + function2(1.111) + function3(9) + function4(9) + function5(True) + [9 % 2, sin(1.111)] + iiftests(9) + iiftests(1.111)
|
||||||
|
|
||||||
out = [Write(r) for r in ret_test + [t2, t4, t5]]
|
#ret_test = [cp.sin(c_i), cp.asin(variable(0.0))]
|
||||||
|
#ret_ref = [cp.sin(9), cp.asin(0.0)]
|
||||||
|
|
||||||
|
ret_test: list[variable[float]] = []
|
||||||
|
ret_ref: list[float] = []
|
||||||
|
#sval = variable(8.0)
|
||||||
|
#tval = 8.0
|
||||||
|
#for i in range(20):
|
||||||
|
# tval = (10-i) / 12
|
||||||
|
# sval = cp.asin(variable(tval))
|
||||||
|
# tval = cp.asin(tval)
|
||||||
|
# ret_test.append(sval)
|
||||||
|
# ret_ref.append(tval)
|
||||||
|
|
||||||
|
#ret_test = [cp.sin(c_i)]
|
||||||
|
#ret_ref = [cp.sin(9)]
|
||||||
|
|
||||||
|
ret_test = [cp.get_42(c_i)]
|
||||||
|
ret_ref = [cp.get_42(9)]
|
||||||
|
|
||||||
|
out = [Write(r) for r in ret_test]
|
||||||
|
|
||||||
#ret_test += [c_i, v2]
|
#ret_test += [c_i, v2]
|
||||||
#ret_ref += [9, 4.44, -4.44]
|
#ret_ref += [9, 4.44, -4.44]
|
||||||
|
|
@ -111,8 +130,8 @@ def test_compile():
|
||||||
|
|
||||||
dw.write_com(_binwrite.Command.END_COM)
|
dw.write_com(_binwrite.Command.END_COM)
|
||||||
|
|
||||||
print('* Data to runner:')
|
#print('* Data to runner:')
|
||||||
dw.print()
|
#dw.print()
|
||||||
|
|
||||||
dw.to_file('build/runner/test-x86.copapy')
|
dw.to_file('build/runner/test-x86.copapy')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue