diff --git a/backend.native/tests/Makefile b/backend.native/tests/Makefile index eeb38de1d92..f23c927b4e7 100644 --- a/backend.native/tests/Makefile +++ b/backend.native/tests/Makefile @@ -1,5 +1,6 @@ TESTS := sum \ - sum_foo_bar + sum_foo_bar \ + arithmetic BIN_TESTS=$(foreach t, ${TESTS},${t}_test) diff --git a/backend.native/tests/codegen/function/arithmetic-test.c b/backend.native/tests/codegen/function/arithmetic-test.c new file mode 100644 index 00000000000..202f0130638 --- /dev/null +++ b/backend.native/tests/codegen/function/arithmetic-test.c @@ -0,0 +1,17 @@ +extern void *resolve_symbol(const char*); + +int +run_test() { + int (*square)(int) = resolve_symbol("kfun:square"); + int (*sum_of_squares)(int, int) = resolve_symbol("kfun:sumOfSquares"); + int (*diff_of_squares)(int, int) = resolve_symbol("kfun:diffOfSquares"); + int (*mod)(int, int) = resolve_symbol("kfun:mod"); + int (*div)(int, int) = resolve_symbol("kfun:remainder"); + + if (square(2) != 4) return 1; + if (sum_of_squares(2, 4) != 20) return 1; + if (diff_of_squares(2, 4) != -12) return 1; + if (mod(5, 2) != 2) return 1; + if (div(5, 2) != 1) return 1; + return 0; +} diff --git a/backend.native/tests/codegen/function/arithmetic.kt b/backend.native/tests/codegen/function/arithmetic.kt new file mode 100644 index 00000000000..d043e45024d --- /dev/null +++ b/backend.native/tests/codegen/function/arithmetic.kt @@ -0,0 +1,5 @@ +fun square(a:Int):Int = a * a +fun sumOfSquares(a:Int, b:Int):Int = square(a) + square(b) +fun diffOfSquares(a:Int, b:Int):Int = square(a) - square(b) +fun mod(a:Int,b:Int):Int = a / b +fun remainder(a:Int, b:Int):Int = a % b \ No newline at end of file