Tests for "while" and "do-while" loop generation

This commit is contained in:
Konstantin Anisimov
2016-11-02 16:17:04 +03:00
committed by vvlevchenko
parent bfb6e448c5
commit 152e738e23
5 changed files with 44 additions and 0 deletions
@@ -0,0 +1,11 @@
extern void *resolve_symbol(const char*);
int
run_test() {
int (*cycle)(int) = resolve_symbol("kfun:cycle");
if (cycle(1) != 2) return 1;
if (cycle(0) != 1) return 1;
return 0;
}
@@ -0,0 +1,7 @@
fun cycle(cnt: Int): Int {
var sum = 1
while (sum == cnt) {
sum = sum + 1
}
return sum
}
@@ -0,0 +1,11 @@
extern void *resolve_symbol(const char*);
int
run_test() {
int (*cycle_do)(int) = resolve_symbol("kfun:cycle_do");
if (cycle_do(3) != 5) return 1;
if (cycle_do(0) != 3) return 1;
return 0;
}
@@ -0,0 +1,7 @@
fun cycle_do(cnt: Int): Int {
var sum = 1
do {
sum = sum + 2
} while (sum == cnt)
return sum
}