GListTest.mesa
Copyright © 1986 by Xerox Corporation. All rights reversed.
Created by Bertrand Serlet, May 21, 1986 4:57:39 pm PDT
Bertrand Serlet, May 22, 1986 11:56:48 am PDT
DIRECTORY Basics, BasicTime, Commander, GList, IO, SafeStorage;
GListTest: CEDAR PROGRAM
IMPORTS Basics, BasicTime, Commander, GList, IO, SafeStorage =
BEGIN OPEN GList;
Foo: TYPE = REF FooRec;
FooRec: TYPE = RECORD [int: INT, bool: BOOLTRUE];
Foos: TYPE = LIST OF Foo;
foo1: Foo ← NEW [FooRec ← [int: 1]];
foo2: Foo ← NEW [FooRec ← [int: 2]];
foo3: Foo ← NEW [FooRec ← [int: 3]];
foos1: Foos ← LIST [foo1, foo2];
Compare: CompareProc = {
f1: Foo ← NARROW [ref1];
f2: Foo ← NARROW [ref2];
RETURN [Basics.CompareINT[f1.int, f2.int]];
};
Test: Commander.CommandProc = {
time: BasicTime.Pulses;
foos, foos2: Foos;
IO.PutF[cmd.out, "Testing constructors; "];
IF EqLists[foos1, NIL] THEN ERROR;
IF NOT EqLists[foos1, foos1] THEN ERROR;
IF Member[foo3, foos1] THEN ERROR;
IF NOT Member[foo2, foos1] THEN ERROR;
foos ← CONS [foo3, foos1];
IF Length[foos]#3 THEN ERROR;
foos ← NARROW [Append[foos, foos1]];
IF Length[foos]#5 THEN ERROR;
foos ← NARROW [Copy[foos]];
IF Length[foos]#5 THEN ERROR;
foos ← NARROW [Reverse[foos]];
foos is foo2 foo1 foo2 foo1 foo3
IF Length[foos]#5 THEN ERROR;
foos ← NARROW [Remove[foo1, foos]];
IF Length[foos]#3 THEN ERROR;
foos ← NARROW [Remove[foo1, foos]];
IF Length[foos]#3 THEN ERROR;
foos ← NARROW [Union[foos1, foos]];
IF Length[foos]#4 THEN ERROR;
foos ← NARROW [Intersection[foos1, foos]];
IF Length[foos]#2 THEN ERROR;
foos ← NARROW [ListDifference[foos1, foos]];
IF Length[foos]#0 THEN ERROR;
IO.PutF[cmd.out, "Testing destructive constructors; "];
foos ← NARROW [Copy[foos1]];
foos ← NARROW [Nconc[foos, Copy[foos]]];
IF Length[foos]#4 THEN ERROR;
foos ← NARROW [Nconc[foos, foos2 ← LIST [foo1]]];
IF Length[foos]#5 THEN ERROR;
foos ← NARROW [DReverse[foos]];
IF Length[foos]#5 THEN ERROR;
foos ← NARROW [DRemove[foo1, foos]];
IF Length[foos]#4 THEN ERROR;
foos ← NARROW [DSubst[foo1, foo2, foos]];
IF Length[foos]#4 THEN ERROR;
IF foos1.first#foo1 THEN ERROR;
foos ← NARROW [NthTail[foos, 2]];
IF Length[foos]#2 THEN ERROR;
IF NthElement[foos, 2]#foo1 THEN ERROR;
foos ← NARROW [Copy[Append[foos1, foos1]]];
foos ← NARROW [Subst[foo1, foo2, foos]];
foos2 ← LIST [foo1, foo1, foo1, foo1];
IF NOT EqLists[foos, foos2] THEN ERROR;
IO.PutF[cmd.out, "Testing sorts; "];
foos ← NARROW [Copy[Append[foos1, foos1]]];
foos ← NARROW [Sort[foos, Compare]];
foos2 ← LIST [foo1, foo1, foo2, foo2];
IF NOT EqLists[foos, foos2] THEN ERROR;
foos ← NARROW [UniqueSort[foos, Compare]];
IF NOT EqLists[foos, foos1] THEN ERROR;
IO.PutF[cmd.out, "Timing; "];
foos2 ← foos ← NIL;
THROUGH [1 .. 4000] DO foos ← CONS [foo1, foos] ENDLOOP;
SafeStorage.ReclaimCollectibleObjects[TRUE];
SafeStorage.ReclaimCollectibleObjects[TRUE];
time ← BasicTime.GetClockPulses[];
UNTIL foos = NIL DO
foos2 ← CONS [foos.first, foos2];
foos ← foos.rest;
ENDLOOP;
time ← BasicTime.GetClockPulses[] - time;
IO.PutF[cmd.out, "Typed Reverse %g us ; ", IO.int[BasicTime.PulsesToMicroseconds[time]]];
foos2 ← foos ← NIL;
THROUGH [1 .. 4000] DO foos ← CONS [foo1, foos] ENDLOOP;
SafeStorage.ReclaimCollectibleObjects[TRUE];
SafeStorage.ReclaimCollectibleObjects[TRUE];
time ← BasicTime.GetClockPulses[];
foos2 ← NARROW [Reverse[foos]];
time ← BasicTime.GetClockPulses[] - time;
IO.PutF[cmd.out, "GList Reverse %g us ; ", IO.int[BasicTime.PulsesToMicroseconds[time]]];
IO.PutF[cmd.out, "Test done\n"];
};
Commander.Register["GListTest", Test, "Tests GList"];
END.