add (copy) regression lama tests

This commit is contained in:
ProgramSnail 2025-06-18 18:27:28 +03:00
parent 91505d247b
commit 30a0b63ba5
240 changed files with 1904 additions and 0 deletions

5
src/test/lama/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
*.html
*.sm
/*.log
*.i
*.s

162
src/test/lama/dune Normal file
View file

@ -0,0 +1,162 @@
; This file was autogenerated
(cram (deps ../src/Driver.exe ../runtime/Std.i))
(cram (applies_to test001)
(deps test001.lama test001.input))
(cram (applies_to test002)
(deps test002.lama test002.input))
(cram (applies_to test003)
(deps test003.lama test003.input))
(cram (applies_to test004)
(deps test004.lama test004.input))
(cram (applies_to test005)
(deps test005.lama test005.input))
(cram (applies_to test006)
(deps test006.lama test006.input))
(cram (applies_to test007)
(deps test007.lama test007.input))
(cram (applies_to test008)
(deps test008.lama test008.input))
(cram (applies_to test009)
(deps test009.lama test009.input))
(cram (applies_to test010)
(deps test010.lama test010.input))
(cram (applies_to test011)
(deps test011.lama test011.input))
(cram (applies_to test012)
(deps test012.lama test012.input))
(cram (applies_to test013)
(deps test013.lama test013.input))
(cram (applies_to test014)
(deps test014.lama test014.input))
(cram (applies_to test015)
(deps test015.lama test015.input))
(cram (applies_to test016)
(deps test016.lama test016.input))
(cram (applies_to test017)
(deps test017.lama test017.input))
(cram (applies_to test018)
(deps test018.lama test018.input))
(cram (applies_to test019)
(deps test019.lama test019.input))
(cram (applies_to test020)
(deps test020.lama test020.input))
(cram (applies_to test021)
(deps test021.lama test021.input))
(cram (applies_to test022)
(deps test022.lama test022.input))
(cram (applies_to test023)
(deps test023.lama test023.input))
(cram (applies_to test024)
(deps test024.lama test024.input))
(cram (applies_to test025)
(deps test025.lama test025.input))
(cram (applies_to test026)
(deps test026.lama test026.input))
(cram (applies_to test027)
(deps test027.lama test027.input))
(cram (applies_to test028)
(deps test028.lama test028.input))
(cram (applies_to test029)
(deps test029.lama test029.input))
(cram (applies_to test034)
(deps test034.lama test034.input))
(cram (applies_to test036)
(deps test036.lama test036.input))
(cram (applies_to test040)
(deps test040.lama test040.input))
(cram (applies_to test041)
(deps test041.lama test041.input))
(cram (applies_to test042)
(deps test042.lama test042.input))
(cram (applies_to test045)
(deps test045.lama test045.input))
(cram (applies_to test046)
(deps test046.lama test046.input))
(cram (applies_to test050)
(deps test050.lama test050.input))
(cram (applies_to test054)
(deps test054.lama test054.input))
(cram (applies_to test059)
(deps test059.lama test059.input))
(cram (applies_to test063)
(deps test063.lama test063.input))
(cram (applies_to test072)
(deps test072.lama test072.input))
(cram (applies_to test073)
(deps test073.lama test073.input))
(cram (applies_to test074)
(deps test074.lama test074.input))
(cram (applies_to test077)
(deps test077.lama test077.input))
(cram (applies_to test078)
(deps test078.lama test078.input))
(cram (applies_to test079)
(deps test079.lama test079.input))
(cram (applies_to test080)
(deps test080.lama test080.input))
(cram (applies_to test081)
(deps test081.lama test081.input))
(cram (applies_to test082)
(deps test082.lama test082.input))
(cram (applies_to test083)
(deps test083.lama test083.input))
(cram (applies_to test084)
(deps test084.lama test084.input))
(cram (applies_to test085)
(deps test085.lama test085.input))
(cram (applies_to test086)
(deps test086.lama test086.input))
(cram (applies_to test088)
(deps test088.lama test088.input))
(cram (applies_to test089)
(deps test089.lama test089.input))
(cram (applies_to test090)
(deps test090.lama test090.input))
(cram (applies_to test091)
(deps test091.lama test091.input))
(cram (applies_to test092)
(deps test092.lama test092.input))
(cram (applies_to test093)
(deps test093.lama test093.input))
(cram (applies_to test094)
(deps test094.lama test094.input))
(cram (applies_to test095)
(deps test095.lama test095.input))
(cram (applies_to test096)
(deps test096.lama test096.input))
(cram (applies_to test097)
(deps test097.lama test097.input))
(cram (applies_to test098)
(deps test098.lama test098.input))
(cram (applies_to test099)
(deps test099.lama test099.input))
(cram (applies_to test100)
(deps test100.lama test100.input))
(cram (applies_to test101)
(deps test101.lama test101.input))
(cram (applies_to test102)
(deps test102.lama test102.input))
(cram (applies_to test103)
(deps test103.lama test103.input))
(cram (applies_to test104)
(deps test104.lama test104.input))
(cram (applies_to test105)
(deps test105.lama test105.input))
(cram (applies_to test106)
(deps test106.lama test106.input))
(cram (applies_to test107)
(deps test107.lama test107.input))
(cram (applies_to test110)
(deps test110.lama test110.input))
(cram (applies_to test111)
(deps test111.lama test111.input))
(cram (applies_to test112)
(deps test112.lama test112.input))
(cram (applies_to test801)
(deps test801.lama test801.input))
(cram (applies_to test802)
(deps test802.lama test802.input))
(cram (applies_to test803)
(deps test803.lama test803.input))

35
src/test/lama/gen.ml Normal file
View file

@ -0,0 +1,35 @@
(* Run as `ocaml gen.ml` *)
let count = 1000
let () =
Out_channel.with_open_text "dune" (fun dunech ->
let dprintfn fmt = Format.kasprintf (Printf.fprintf dunech "%s\n") fmt in
dprintfn "; This file was autogenerated\n";
dprintfn "(cram (deps ../src/Driver.exe ../runtime/Std.i))\n";
for i = 0 to count - 1 do
let cram_buf = Buffer.create 100 in
let cram_printfn fmt =
Format.kasprintf (Printf.bprintf cram_buf "%s\n") fmt
in
let cram_file = ref (Printf.sprintf "test%03d.t" i) in
let lama_file = ref (Printf.sprintf "test%03d.lama" i) in
let input_file = ref (Printf.sprintf "test%03d.input" i) in
let found =
if Sys.file_exists !lama_file then (
cram_printfn
" $ ../src/Driver.exe -i test%03d.lama < \
test%03d.input"
i i;
true)
else false
in
if found then (
dprintfn "(cram (applies_to test%03d)" i;
dprintfn " (deps %s %s))" !lama_file !input_file;
Out_channel.with_open_text !cram_file (fun ch ->
output_string ch (Buffer.contents cram_buf)))
done)

View file

@ -0,0 +1,2 @@
5
6

View file

@ -0,0 +1,3 @@
var x = read (), y = read (), z = x * y * 3;
write (z)

3
src/test/lama/test001.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test001.lama < test001.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1,2 @@
5
6

View file

@ -0,0 +1,6 @@
var x, y, z;
x := read ();
y := read ();
z := y*y;
write (x+z)

3
src/test/lama/test002.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test002.lama < test002.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1,2 @@
10
3

View file

@ -0,0 +1,7 @@
var x, y;
x := read ();
y := read ();
write (x-y);
write (x/y);
write (x%y)

3
src/test/lama/test003.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test003.lama < test003.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1,2 @@
10
5

View file

@ -0,0 +1,6 @@
var x, y, z;
x := read ();
y := read ();
z := ((x + y) + (x - y)) + ((x - y) - (x + y));
write (z)

3
src/test/lama/test004.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test004.lama < test004.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1,2 @@
6
7

View file

@ -0,0 +1,6 @@
var x, y, z;
x := read ();
y := read ();
z := ((x + y) + (x - y)) + ((x - y) - (x / y));
write (z)

3
src/test/lama/test005.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test005.lama < test005.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1,2 @@
-6
7

View file

@ -0,0 +1,16 @@
var x, y, z;
x := read ();
y := read ();
z := x < y;
write (z);
z := x <= y;
write (z);
z := x == y;
write (z);
z := x != y;
write (z);
z := x >= y;
write (z);
z := x > y;
write (z)

3
src/test/lama/test006.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test006.lama < test006.input
Error: could not find an interface file for import "Std"
[255]

View file

View file

@ -0,0 +1,6 @@
var x, y, z;
x := 1;
y := 2;
z := x - y - 3;
write (z)

3
src/test/lama/test007.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test007.lama < test007.input
Error: could not find an interface file for import "Std"
[255]

View file

View file

@ -0,0 +1,4 @@
var z;
z := 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9;
write (z)

3
src/test/lama/test008.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test008.lama < test008.input
Error: could not find an interface file for import "Std"
[255]

View file

View file

@ -0,0 +1,8 @@
var n = 2, k = 10;
(var res = 1;
while k > 0 do
res := res * n;
k := k - 1
od;
write(res))

3
src/test/lama/test009.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test009.lama < test009.input
Error: could not find an interface file for import "Std"
[255]

View file

View file

@ -0,0 +1,20 @@
var i, s;
i := 0;
s := 0;
while i < 100
do
var j = 0;
while j < 100
do
s := s + j;
j := j + 1
od;
s := s + i;
i := i + 1
od;
write (s)

3
src/test/lama/test010.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test010.lama < test010.input
Error: could not find an interface file for import "Std"
[255]

View file

View file

@ -0,0 +1,7 @@
var x;
x:=0;
if x
then write(1)
else write(2)
fi

3
src/test/lama/test011.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test011.lama < test011.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
3

View file

@ -0,0 +1,14 @@
var n;
n := read ();
while n >= 0 do
if n > 1
then
write (0);
if n == 3 then write (0) else write (1) fi
else
write (1);
if n > 0 then write (0) else write (1) fi
fi;
n := n - 1
od

3
src/test/lama/test012.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test012.lama < test012.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
6

View file

@ -0,0 +1,16 @@
var n = read ();
do
if n == 1 then write (0)
elif n == 2 then write (1)
elif n == 3 then write (2)
elif n == 4 then write (3)
else write (10)
fi;
if n >= 5 then write (11) fi;
n := n - 1
while n != 0 od

3
src/test/lama/test013.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test013.lama < test013.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
100

View file

@ -0,0 +1,29 @@
var n;
n := read ();
while n > 0 do
if n < 1000
then
if n < 500
then
if n < 250
then
if n < 125
then
if n < 63
then
if n < 32
then
write (1)
fi
fi
fi
fi
fi
fi;
n := n - 1
od

3
src/test/lama/test014.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test014.lama < test014.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
1000

View file

@ -0,0 +1,22 @@
var s, n, p;
s := 0;
n := read ();
p := 2;
while n > 0 do (
var c = 2, f = 1;
while c*c <= p && f do
f := (p % c) != 0;
c := c + 1
od;
if f != 0 then
if n == 1 then write (p) else skip fi;
n := n - 1
else skip fi;
p := p + 1
)
od

3
src/test/lama/test015.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test015.lama < test015.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
10

View file

@ -0,0 +1,14 @@
var s, n;
n := read ();
s := 1;
do
s := s * n;
n := n - 1
while n != 0 od;
write (s)

3
src/test/lama/test016.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test016.lama < test016.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
20

View file

@ -0,0 +1,17 @@
var n, fib_1, fib_2, fib, i;
n := read ();
i := 2;
fib_1 := 1;
fib_2 := 1;
fib := 1;
while i < n do
fib := fib_1 + fib_2;
fib_2 := fib_1;
fib_1 := fib;
i := i+1
od;
write (fib)

3
src/test/lama/test017.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test017.lama < test017.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
23409

View file

@ -0,0 +1,44 @@
var n, c, p, q, i, m, d;
n := read ();
c := 1;
p := 2;
while c do
var cc = 1;
while cc do
q := 2;
while q * q <= p && cc do
cc := p % q != 0;
q := q + 1
od;
if cc then cc := 0 else p := p + 1; cc := 1 fi
od;
d := p;
i := 0;
q := n / d;
m := n % d;
while q > 0 && m == 0 do
i := i + 1;
d := d * p;
m := n % d;
if m == 0 then q := n / d else skip fi
od;
write (p);
write (i);
n := n / (d / p);
p := p + 1;
c := n != 1
od

3
src/test/lama/test018.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test018.lama < test018.input
Error: could not find an interface file for import "Std"
[255]

View file

View file

@ -0,0 +1,17 @@
var i, s;
i := 0;
s := 0;
for i := 0, i < 100, i := i+1
do
var j;
for j := 0, j < 100, j := j+1
do
s := s + j
od;
s := s + i
od;
write (s)

3
src/test/lama/test019.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test019.lama < test019.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
1000

View file

@ -0,0 +1,22 @@
var s, n, p;
s := 0;
n := read ();
p := 2;
while n > 0 do
var c = 2;
var f = 1;
for c := 2, c*c <= p && f, c := c+1
do
f := p % c != 0
od;
if f != 0 then
if n == 1 then write (p) fi;
n := n - 1
fi;
p := p + 1
od

3
src/test/lama/test020.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test020.lama < test020.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
10

View file

@ -0,0 +1,11 @@
var n, f;
n := read ();
f := 1;
for skip, n >= 1, n := n-1
do
f := f * n
od;
write (f)

3
src/test/lama/test021.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test021.lama < test021.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
20

View file

@ -0,0 +1,16 @@
var n, fib_1, fib_2, fib, i;
n := read ();
fib_1 := 1;
fib_2 := 1;
fib := 1;
for i := 2, i < n, i := i+1
do
fib := fib_1 + fib_2;
fib_2 := fib_1;
fib_1 := fib
od;
write (fib)

3
src/test/lama/test022.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test022.lama < test022.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1,6 @@
5
6
7
8
9
0

View file

@ -0,0 +1,10 @@
var s, n;
s := 0;
do
n := read ();
s := s + n
while n != 0 od;
write (s)

3
src/test/lama/test023.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test023.lama < test023.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,17 @@
fun test1 () {
a := 3
}
fun test2 (b) {
a := b
}
var x, a, b;
x := read ();
test1 ();
write (a);
test2 (8);
write (a)

3
src/test/lama/test024.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test024.lama < test024.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,33 @@
var x, a, b, c;
fun test1 (a) {
write (a)
}
fun test2 (b) {
write (b)
}
fun test3 (c) {
write (c)
}
fun print () {
write (a);
write (b);
write (c)
}
x := read ();
a := 100;
b := 200;
c := 300;
test1 (1);
print ();
test2 (2);
print ();
test3 (3);
print ()

3
src/test/lama/test025.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test025.lama < test025.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,36 @@
var x, a, b, c;
fun test1 (a) {
write (a);
print ()
}
fun test2 (b) {
write (b);
print ()
}
fun test3 (c) {
write (c);
print ()
}
fun print () {
write (a);
write (b);
write (c)
}
x := read ();
a := 100;
b := 200;
c := 300;
test1 (1);
print ();
test2 (2);
print ();
test3 (3);
print ()

3
src/test/lama/test026.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test026.lama < test026.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,32 @@
var x, a, b, c;
fun print () {
write (a);
write (b);
write (c)
}
fun test1 (a) {
write (a);
print ();
write (a);
if a < 4 then
test2 (a+1);
print ()
fi
}
fun test2 (b) {
write (b);
print ();
test1 (b+1);
print ()
}
x := read ();
a := 100;
b := 200;
c := 300;
test1 (1)

3
src/test/lama/test027.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test027.lama < test027.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
7

View file

@ -0,0 +1,18 @@
var n, i, result;
fun fact (n) {
if n <= 1
then result := 1
else
fact (n-1);
result := result * n
fi
}
n := read ();
for i := n, i >= 1, i := i-1 do
fact (i);
write (i);
write (result)
od

3
src/test/lama/test028.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test028.lama < test028.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
9

View file

@ -0,0 +1,21 @@
var i, n, result;
fun fib (n) {
var r;
if n <= 1
then result := 1
else
fib (n-1);
r := result;
fib (n-2);
result := result + r
fi
}
n := read ();
for i := n, i >= 1, i := i-1 do
fib (i);
write (i);
write (result)
od

3
src/test/lama/test029.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test029.lama < test029.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,19 @@
var n, x, i;
fun printString (x) {
for i:=0, i<x.length, i:=i+1 do
write (x[i])
od
}
n := read ();
x := "abcdefgh";
printString (x);
for i:=0, i<x.length, i:=i+1 do
x[i] := x[i]+2
od;
printString (x)

3
src/test/lama/test034.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test034.lama < test034.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,24 @@
var x, y, i, j;
fun printAS (x) {
var i, j;
for i := 0, i<x.length, i:=i+1 do
for j := 0, j<x[i].length, j:=j+1 do
write (x[i][j])
od
od
}
y := read ();
x := ["abcd", "efgh"];
printAS (x);
for i := 0, i<x.length, i:=i+1 do
for j := 0, j<x[i].length, j:=j+1 do
x[i][j] := 'a'
od
od;
printAS (x)

3
src/test/lama/test036.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test036.lama < test036.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1,17 @@
var x;
fun f (x) {
case x of
A -> write (1)
| B -> write (2)
| C -> write (3)
| _ -> write (4)
esac
}
x := read ();
f (A);
f (B);
f (C);
f (D)

3
src/test/lama/test040.t Normal file
View file

@ -0,0 +1,3 @@
$ ../src/Driver.exe -i test040.lama < test040.input
Error: could not find an interface file for import "Std"
[255]

View file

@ -0,0 +1 @@
0

Some files were not shown because too many files have changed in this diff Show more