IF testing THEN {
s ← FS.StreamOpen["HeapImpl.testlog", $create];
q ← CreateQueue[RefIntCompareProc];
IF NOT q.Empty[] THEN s.PutF["Created queue not empty.\n"];
InsertInt[q,1]; InsertInt[q,2]; InsertInt[q,3];
i ← q.GetSize[];
IF NOT i = 3 THEN s.PutF["Size reported was: %g\n", IO.int[i]];
i ← NARROW[q.PeekNextEvent[], REF INT]^;
IF NOT i = 3 THEN s.PutF["Peek was: %g\n", IO.int[i]];
i ← NARROW[q.NextEvent[], REF INT]^;
IF NOT i = 3 THEN s.PutF["First return was: %g\n", IO.int[i]];
InsertInt[q,4]; InsertInt[q,5];
i ← NARROW[q.NextEvent[], REF INT]^;
IF NOT i = 5 THEN s.PutF["Second return was: %g\n", IO.int[i]];
i ← NARROW[q.NextEvent[], REF INT]^;
IF NOT i = 4 THEN s.PutF["Third return was: %g\n", IO.int[i]];
i ← NARROW[q.NextEvent[], REF INT]^;
IF NOT i = 2 THEN s.PutF["Fourth return was: %g\n", IO.int[i]];
i ← NARROW[q.NextEvent[], REF INT]^;
IF NOT i = 1 THEN s.PutF["Fifth return was: %g\n", IO.int[i]];
FOR j: INT IN [1..100000] DO
InsertInt[q,j]
ENDLOOP;
FOR j: INT DECREASING IN [1..100000] DO
i ← NARROW[q.NextEvent[], REF INT]^;
IF NOT i=j THEN {s.PutF["Error i was: %g, j was: %g\n", IO.int[i], IO.int[j] ]; EXIT};
ENDLOOP;
s.Close[];
}