diff options
| author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2011-10-14 04:55:05 +0200 |
|---|---|---|
| committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2011-10-14 04:55:05 +0200 |
| commit | 6aa0e0017d7d0cddc006da885946934b06949a91 (patch) | |
| tree | 66b688ec32e2f91266db760b1762f2a50cc52036 /libslang/src/test/loops.sl | |
| parent | a966db5b71328f6adf9dd767e64b322a3bd7ed9c (diff) | |
| download | erlang-slang-fork-6aa0e0017d7d0cddc006da885946934b06949a91.tar.gz | |
include libslang-1.4.9 and automatically build it and link erlang-slang against it
few (erlang) people will still have libslang-1.4.9 installed or spend time
to get it to link against the driver
Diffstat (limited to 'libslang/src/test/loops.sl')
| -rw-r--r-- | libslang/src/test/loops.sl | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/libslang/src/test/loops.sl b/libslang/src/test/loops.sl new file mode 100644 index 0000000..ac22611 --- /dev/null +++ b/libslang/src/test/loops.sl @@ -0,0 +1,130 @@ +_debug_info = 1; () = evalfile ("inc.sl"); + +print ("Testing looping constructs ..."); + +define identity (x) +{ + return x; +} + +define test_do_while (count_fun) +{ + variable i = 0; + variable count = 0; + do + { + if (i == 3) + continue; + i++; + } + while (@count_fun (&count) < 6); + if ((count != 6) or (i != 3)) + failed ("do_while 1: %S", count_fun); + + i = 0; + count = 0; + do + { + if (i == 3) + break; + i++; + } + while (@count_fun (&count) < 6); + if ((count != 3) or (i != 3)) + failed ("do_while 2: %S", count_fun); +} + +define test_while (count_fun) +{ + variable i = 0; + variable count = 0; + + while (@count_fun (&count) < 6) + { + if (i == 3) + continue; + i++; + } + if ((count != 6) or (i != 3)) + failed ("while 1: %S", count_fun); + + i = 0; + count = 0; + while (@count_fun (&count) < 6) + { + if (i == 3) + break; + i++; + } + if ((count != 4) or (i != 3)) + failed ("while 2: %S", count_fun); +} + +define test_for (count_fun) +{ + variable i = 0; + variable count = 0; + + for (count = 0; @count_fun (&count) < 6; ) + { + if (i == 3) + continue; + i++; + } + if ((count != 6) or (i != 3)) + failed ("while 1: %S", count_fun); + + i = 0; + for (count = 0; @count_fun (&count) < 6; ) + { + if (i == 3) + break; + i++; + } + if ((count != 4) or (i != 3)) + failed ("while 2: %S", count_fun); +} + +define add_one (x) +{ + @x = @x + 1; + return @x; +} + +define add_one_with_call (x) +{ + @x = @x+1; + return identity (@x); +} + +define add_one_with_loop (x) +{ + variable i = 0; + while (1) + { + @x = @x + 1; + i++; + if (i == 3) + break; + } + @x = @x - 2; + return @x; +} + + +test_do_while (&add_one); +test_do_while (&add_one_with_call); +test_do_while (&add_one_with_loop); + +test_while (&add_one); +test_while (&add_one_with_call); +test_while (&add_one_with_loop); + +test_for (&add_one); +test_for (&add_one_with_call); +test_for (&add_one_with_loop); + +print ("Ok\n"); + +exit (0); + |
