arithmetic test

This commit is contained in:
Vasily Levchenko
2016-10-11 10:24:51 +03:00
parent b038dbc724
commit 3a738b2ad3
3 changed files with 24 additions and 1 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
TESTS := sum \
sum_foo_bar
sum_foo_bar \
arithmetic
BIN_TESTS=$(foreach t, ${TESTS},${t}_test)
@@ -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;
}
@@ -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