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: BOOL _ TRUE]; 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]]; 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. ΪGListTest.mesa Copyright c 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 foos is foo2 foo1 foo2 foo1 foo3 ΚL– "Cedar" style˜codešœ™Kšœ Οmœ1™