From 6aa0e0017d7d0cddc006da885946934b06949a91 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 14 Oct 2011 04:55:05 +0200 Subject: 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 --- libslang/src/test/loops.sl | 130 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 libslang/src/test/loops.sl (limited to 'libslang/src/test/loops.sl') 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); + -- cgit v1.2.3