D2IntervalsTest.mesa
Copyright © 1985 by Xerox Corporation. All rights reversed.
Created by Bertrand Serlet, March 12, 1986 11:08:26 pm PST
Bertrand Serlet, March 12, 1986 11:34:01 pm PST
DIRECTORY
D2Intervals, Random;
Test program to shake a little bit the implementation
D2IntervalsTest: CEDAR PROGRAM
IMPORTS D2Intervals, Random SHARES D2Intervals = BEGIN
OPEN D2Intervals;
Int: TYPE = INT ← 0;
ValueRect: PROC [table: Table, value: REF] RETURNS [rect: Rect] = {
sizeOfValues: REF INTNARROW [table.userData];
pos: REF LIST OF INTNARROW [value];
posx: INT ← pos.first;
posy: INT ← pos.rest.first;
rect ← [[posx-sizeOfValues^, posx+sizeOfValues^], [posy-sizeOfValues^, posy+sizeOfValues^]];
};
Test: PROC [numberOfValues: NAT, rangeMax: NAT] RETURNS [table: Table, results: LIST OF INTNIL, rects: LIST OF Rect ← NIL] = {
sizeOfValues: NAT ← 2;
rs: Random.RandomStream ← Random.Create[rangeMax, rangeMax];
last: REF;
posx, posy: INT;
count: INT ← 0;
Count: PROC [table: Table, v: Value] RETURNS [BOOLFALSE] = {count ← count+1};
Each: PROC [table: Table, value: Value] RETURNS [BOOLFALSE] = {rects ← CONS [ValueRect[table, value], rects]};
MakeError: PROC [table: Table, v: Value] RETURNS [BOOLFALSE] = {ERROR};
table ← Create[range: [[-sizeOfValues, rangeMax+sizeOfValues], [-sizeOfValues, rangeMax+sizeOfValues]], valueRect: ValueRect, userData: NEW [INT ← sizeOfValues]];
THROUGH [0 .. numberOfValues] DO
posx ← Random.NextInt[rs];
posy ← Random.NextInt[rs];
Insert[table, (last ← NEW [LIST OF INTLIST [posx, posy]])];
ENDLOOP;
IF table.size#numberOfValues+1 THEN ERROR;
Delete[table, last];
IF table.size#numberOfValues THEN ERROR;
Delete[table, last];
IF table.size#numberOfValues THEN ERROR;
FOR i: NAT IN [0 .. table.data.hashSize) DO
results ← CONS [IF table.data[i]#NIL THEN table.data[i].size ELSE -1, results];
ENDLOOP;
[] ← Enumerate[table, Count];
IF count#numberOfValues THEN ERROR;
[] ← Enumerate[table, Each, [[rangeMax/2-10*sizeOfValues, rangeMax/2+10*sizeOfValues], [rangeMax/2-10*sizeOfValues, rangeMax/2+10*sizeOfValues]]];
[] ← Enumerate[table, MakeError, [[-sizeOfValues-10, -sizeOfValues-5], [-sizeOfValues-10, -sizeOfValues-5]]];
};
END.