Better test30

This commit is contained in:
Dmitry Boulytchev 2020-08-04 15:11:14 +03:00
parent c29ab4901f
commit c3671a0a38
2 changed files with 44 additions and 9 deletions

View file

@ -1 +1 @@
let version = "Version 1.00, c73f43e81, Thu Jul 23 12:52:42 2020 +0300" let version = "Version 1.00, c29ab4901, Sun Aug 2 23:56:21 2020 +0300"

View file

@ -76,7 +76,9 @@ fun eq (x, y) {
eqrec (x, y) eqrec (x, y)
} }
fun genCyclicArrays (n) { fun genCyclicArrays (n, eq, cross) {
local f = ref (true);
fun genrec (n, stacka, stackb, depth) { fun genrec (n, stacka, stackb, depth) {
fun peek (k, stack) { fun peek (k, stack) {
case stack of case stack of
@ -115,17 +117,27 @@ fun genCyclicArrays (n) {
if depth == 0 if depth == 0
then then
a[i] := a; a[i] := a;
b[i] := b b[i] := if cross then a else b fi
else else
case random (depth) of case random (depth) of
r -> a [i] := peek (r, stacka); r -> a [i] := peek (r, stacka);
b [i] := peek (r, stackb) b [i] := if cross then a[i] else peek (r, stackb) fi
esac esac
fi fi;
if 1 - eq && deref (f) then b[i] := 0; f ::= true fi
else else
case genrec (a[i], [a, stacka], [b, stackb], depth + 1) of case genrec (a[i], [a, stacka], [b, stackb], depth + 1) of
[ai, bi] -> a [i] := ai; [ai, bi] -> a [i] := ai;
b [i] := bi b [i] := bi;
if 1 - eq && deref (f) then
case b[i] of
#unboxed -> b[i] := b[i] + 1
| _ -> b[i] := 0
esac;
f ::= true
fi
esac esac
fi fi
od; od;
@ -139,9 +151,32 @@ fun genCyclicArrays (n) {
disableGC (); disableGC ();
for local i=0;, i<100, i:=i+1 for local i=0;, i<25, i:=i+1
do do
case genCyclicArrays (1000) of case genCyclicArrays (1000, true, false) of
[a, b] -> printf ("%d\n", eq (a, b)) [a, _] -> printf ("%d\n", eq (a, a) == true)
| [a, b] -> printf ("%d\n", eq (a, b) == true)
esac
od;
for local i=0;, i<25, i:=i+1
do
case genCyclicArrays (1000, true, true) of
[a, _] -> printf ("%d\n", eq (a, a) == true)
| [a, b] -> printf ("%d\n", eq (a, b) == true)
esac
od;
for local i=0;, i<25, i:=i+1
do
case genCyclicArrays (1000, false, false) of
[a, b] -> printf ("%d\n", eq (a, b) == false)
esac
od;
for local i=0;, i<25, i:=i+1
do
case genCyclicArrays (1000, false, true) of
[a, b] -> printf ("%d\n", eq (a, b) == false)
esac esac
od od