mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
65 lines
900 B
Text
65 lines
900 B
Text
|
|
import Data;
|
||
|
|
|
||
|
|
fun normalize (x) {
|
||
|
|
if x == 0 then 0
|
||
|
|
elif x < 0 then -1
|
||
|
|
else 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
fun not (x) {
|
||
|
|
0 - x
|
||
|
|
}
|
||
|
|
|
||
|
|
fun test (a, b) {
|
||
|
|
local f = normalize (a =?= b);
|
||
|
|
|
||
|
|
printf ("%s =?= %s = %d\n", a.string, b.string, f);
|
||
|
|
printf ("symmetricity: %s\n", if normalize (b =?= a) == not (f) then "ok" else "fail" fi)
|
||
|
|
}
|
||
|
|
|
||
|
|
test (1, 1);
|
||
|
|
test (1, 10);
|
||
|
|
|
||
|
|
test ("abc", "abc");
|
||
|
|
test ("abc", "def");
|
||
|
|
|
||
|
|
test (1, "abc");
|
||
|
|
|
||
|
|
test (S (1), S (1));
|
||
|
|
test (S (2), S (1));
|
||
|
|
test (S (1, 2, 3), S (1, 3, 2));
|
||
|
|
test (S (1, 2, 3), D (5, 6));
|
||
|
|
|
||
|
|
test (1, S (5));
|
||
|
|
test ("abs", S (5, 6));
|
||
|
|
test ([1, 2, 3], S (1, 2, 3));
|
||
|
|
test ("abc", [1, 2, 3]);
|
||
|
|
test (1, [1, 2, 3]);
|
||
|
|
|
||
|
|
{
|
||
|
|
local a = [1], b = [1];
|
||
|
|
|
||
|
|
a [0] := a;
|
||
|
|
b [0] := b;
|
||
|
|
|
||
|
|
printf ("%d\n", a =?= b);
|
||
|
|
|
||
|
|
a[0] := b;
|
||
|
|
b[0] := a;
|
||
|
|
|
||
|
|
printf ("%d\n", a =?= b);
|
||
|
|
|
||
|
|
a := S (1);
|
||
|
|
b := S (1);
|
||
|
|
|
||
|
|
a[0] := a;
|
||
|
|
b[0] := b;
|
||
|
|
|
||
|
|
printf ("%d\n", a =?= b);
|
||
|
|
|
||
|
|
a[0] := b;
|
||
|
|
b[0] := a;
|
||
|
|
|
||
|
|
printf ("%d\n", a =?= b)
|
||
|
|
}
|