1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
{$mode macpas}
{$r-}
procedure error(l: longint);
begin
writeln('error near ',l);
halt(1);
end;
procedure test8bit;
type
ta = -1..0;
tb = packed array[0..999] of ta;
tc = array[0..124] of byte;
const
results: array[0..9] of ta = (-1,0,-1,-1,-1,0,-1,-1,-1,0);
var
a: ta;
b: tb;
i,j: longint;
begin
fillchar(b,sizeof(b),0);
for i := low(results) to high(results) do
begin
b[i] := results[i];
for j := succ(i) to high(results) do
if b[j] <> 0 then
error(201);
if b[i] <> results[i] then
error(202);
end;
if (b[0] <> results[0]) then
error(1);
if (b[1] <> results[1]) then
error(2);
if (b[2] <> results[2]) then
error(3);
if (b[3] <> results[3]) then
error(4);
if (b[4] <> results[4]) then
error(5);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(7);
end;
procedure test8to16bit;
type
ta = -3..3;
tb = packed array[0..1000] of ta;
const
results: array[0..5] of ta = (2,-2,1,-1,-3,1);
var
a: ta;
b: tb;
i,j: longint;
begin
fillchar(b,sizeof(b),0);
for i := low(results) to high(results) do
begin
b[i] := results[i];
for j := succ(i) to high(results) do
if b[j] <> 0 then
error(211);
if b[i] <> results[i] then
error(212);
end;
if (b[0] <> results[0]) then
error(11);
if (b[1] <> results[1]) then
error(12);
if (b[2] <> results[2]) then
error(13);
if (b[3] <> results[3]) then
error(14);
if (b[4] <> results[4]) then
error(15);
if (b[5] <> results[5]) then
error(155);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(17);
end;
procedure test16bit;
type
ta = -255..255;
tb = packed array[0..799] of ta;
tc = array[0..899] of byte;
const
results: array[0..4] of ta = (256-356,39,256-485,100,256-500);
var
a: ta;
b: tb;
i,j: longint;
begin
fillchar(b,sizeof(b),$ff);
for i := low(results) to high(results) do
begin
b[i] := results[i];
for j := succ(i) to high(results) do
if b[j] <> -1 then
error(221);
if b[i] <> results[i] then
error(222);
end;
if (b[0] <> results[0]) then
error(21);
if (b[1] <> results[1]) then
error(22);
if (b[2] <> results[2]) then
error(23);
if (b[3] <> results[3]) then
error(24);
if (b[4] <> results[4]) then
error(25);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(27);
end;
procedure test16to24bit;
type
ta = -1023..1023;
tb = packed array[0..799] of ta;
tc = array[0..1099] of byte;
const
results: array[0..4] of ta = (1000,67-1023,853,512-1023,759);
var
a: ta;
b: tb;
i,j: longint;
begin
fillchar(b,sizeof(b),0);
for i := low(results) to high(results) do
begin
b[i] := results[i];
for j := succ(i) to high(results) do
if b[j] <> 0 then
error(231);
if b[i] <> results[i] then
error(232);
end;
if (b[0] <> results[0]) then
error(31);
if (b[1] <> results[1]) then
error(32);
if (b[2] <> results[2]) then
error(33);
if (b[3] <> results[3]) then
error(34);
if (b[4] <> results[4]) then
error(35);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(37);
end;
procedure test32bit;
type
ta = -((1 shl 18)-1)..(1 shl 18) - 1;
tb = packed array[0..799] of ta;
tc = array[0..1899] of byte;
const
results: array[0..4] of ta = ($0002F687,$00032222-(1 shl 18),$000178EE,$000057970-(1 shl 18),$0007E1D2-(1 shl 18));
var
a: ta;
b: tb;
i,j: longint;
begin
fillchar(b,sizeof(b),$00);
for i := low(results) to high(results) do
begin
b[i] := results[i];
for j := succ(i) to high(results) do
if b[j] <> 0 then
error(241);
if b[i] <> results[i] then
error(242);
end;
if (b[0] <> results[0]) then
error(41);
if (b[1] <> results[1]) then
error(42);
if (b[2] <> results[2]) then
error(43);
if (b[3] <> results[3]) then
error(44);
if (b[4] <> results[4]) then
error(45);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(47);
end;
procedure test32to40bit;
type
ta = -$3fffffff..$3fffffff;
tb = packed array[0..799] of ta;
tc = array[0..3099] of byte;
const
results: array[0..4] of ta = ($3fffffff-$71567851,$3fffffff-$56789ABD,$3fffffff-$50F11178,$39D68DDC,$3fffffff-$6C7A5A7);
var
a: ta;
b: tb;
i,j: longint;
begin
fillchar(b,sizeof(b),0);
for i := low(results) to high(results) do
begin
b[i] := results[i];
for j := succ(i) to high(results) do
if b[j] <> 0 then
error(251);
if b[i] <> results[i] then
error(252);
end;
if (b[0] <> results[0]) then
error(51);
if (b[1] <> results[1]) then
error(52);
if (b[2] <> results[2]) then
error(53);
if (b[3] <> results[3]) then
error(54);
if (b[4] <> results[4]) then
error(55);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(57);
end;
begin
test8bit;
test8to16bit;
test16bit;
test16to24bit;
test32bit;
test32to40bit;
end.
|