3 (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
5 This product is part of the Amsterdam Compiler Kit.
7 Permission to use, sell, duplicate or disclose this software must be
8 obtained in writing. Requests for such permissions may be sent to
10 Dr. Andrew S. Tanenbaum
18 {$i64 : sets of integers contain 64 bits}
19 program t3(input,output,f1,f2,f3,f4,f5,f6);
21 { The Berkeley and EM-1 compilers both can handle this program }
23 const rcsversion='$Id: t3.p,v 2.4 1994/06/24 12:36:57 ceriel Exp $';
24 type wavelength = (red,blue,yellow,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,
26 spectrum= set of wavelength;
30 tp3= packed record c1:char; i:integer; p:boolean; x:real end;
31 tp4= record c1:char; i:integer; p:boolean; x:real end;
33 tp3= packed record c1:char; i:integer; p:boolean; end;
34 tp4= record c1:char; i:integer; p:boolean; end;
37 vec1 = array [-10..+10] of integer;
40 vrec = record case t:boolean of false:(r:real); true:(b:bit) end;
42 vrec = record case t:boolean of false:(); true:(b:bit) end;
45 var t,pct,ect:integer;
55 c: array [1..20] of char;
60 letters,cset:set of char;
70 procedure e(n:integer);
73 writeln(' Error', n:3,' in test ', t)
83 {************************************************************************}
86 var i:integer; c1:char;
87 begin t:=34; pct := pct + 1;
89 if not eof(f1) then e(1);
90 write(f1,'abc',20+7:2,'a':2); writeln(f1);
92 i:=-3000; write(f1,i:5);
94 if eof(f1) or eoln(f1) then e(2);
95 for i:=1 to 17 do read(f1,c[i]);
96 if(c[1]<>'a') or (c[3]<>'c') or (c[5]<>'7') or (c[8]<>' ') or
97 (c[12]<>'-') or (c[13]<>'3') or (c[16]<>'0') then e(3);
98 if not eof(f1) then e(4);
100 for i:= 32 to 127 do write(f1,chr(i));
101 reset(f1); p:= false;
102 for i:= 32 to 127 do begin read(f1,c1); if ord(c1) <> i then p:=true end;
105 for c1 := 'a' to 'z' do write(f1,c1);
106 reset(f1); p:= false;
107 for c1 := 'a' to 'z' do begin read(f1,c2); if c2 <> c1 then p:=true end;
113 begin t:=36; pct:=pct+1;
114 rewrite(f2); rewrite(f3); rewrite(f4); rewrite(f5); rewrite(f6);
115 colors := []; f2^ := colors; put(f2);
116 colors := [red]; f2^ := colors; put(f2);
117 colors := [red,blue]; f2^ := colors; put(f2);
118 colors := [yellow,blue]; f2^ := colors; put(f2);
120 colors := f2^; get(f2); if colors <> [] then e(4);
121 colors := f2^; get(f2); if colors <> [red] then e(5);
122 colors := f2^; get(f2); if colors <> [blue,red] then e(6);
123 colors := f2^; get(f2); if colors <> [blue,yellow] then e(7);
126 r3.c1:='w'; r3.i:= -100; r3.x:=303.56; r3.p:=true; f3^:=r3; put(f3);
127 r3.c1:='y'; r3.i:= -35; r3.x:=26.32; f3^:=r3; put(f3);
128 r3.c1:='q'; r3.i:= +29; r3.x:=10.00; f3^:=r3; put(f3);
129 r3.c1:='j'; r3.i:= 8; r3.x:=10000; f3^:=r3; put(f3);
131 r3.c1:='w'; r3.i:= -100; r3.p:=true; f3^:=r3; put(f3);
132 r3.c1:='y'; r3.i:= -35; f3^:=r3; put(f3);
133 r3.c1:='q'; r3.i:= +29; f3^:=r3; put(f3);
134 r3.c1:='j'; r3.i:= 8; f3^:=r3; put(f3);
137 for i:= 1 to 1000 do begin f3^ := r3; put(f3) end;
142 if (r3.c1<>'w') or (r3.i<>-100) or (r3.x<>303.56) then e(8);
144 if (r3.c1<>'y') or (r3.i<> -35) or (r3.x<> 26.32) then e(9);
146 if (r3.c1<>'q') or (r3.i<> 29) or (r3.x<> 10.00) then e(10);
148 if (r3.c1<>'j') or (r3.i<> 8) or (r3.x<> 10000) then e(11);
151 if (r3.c1<>'w') or (r3.i<>-100) then e(8);
153 if (r3.c1<>'y') or (r3.i<> -35) then e(9);
155 if (r3.c1<>'q') or (r3.i<> 29) then e(10);
157 if (r3.c1<>'j') or (r3.i<> 8) then e(11);
162 r4.c1:='w'; r4.i:= -100; r4.x:=303.56; r4.p:=true; f4^:=r4; put(f4);
163 r4.c1:='y'; r4.i:= -35; r4.x:=26.32; f4^:=r4; put(f4);
164 r4.c1:='q'; r4.i:= +29; r4.x:=10.00; f4^:=r4; put(f4);
165 r4.c1:='j'; r4.i:= 8; r4.x:=10000; f4^:=r4; put(f4);
167 r4.c1:='w'; r4.i:= -100; r4.p:=true; f4^:=r4; put(f4);
168 r4.c1:='y'; r4.i:= -35; f4^:=r4; put(f4);
169 r4.c1:='q'; r4.i:= +29; f4^:=r4; put(f4);
170 r4.c1:='j'; r4.i:= 8; f4^:=r4; put(f4);
173 for i:= 1 to 1000 do begin f4^ := r4; put(f4) end;
178 if (r4.c1<>'w') or (r4.i<>-100) or (r4.x<>303.56) then e(12);
180 if (r4.c1<>'y') or (r4.i<> -35) or (r4.x<> 26.32) then e(13);
182 if (r4.c1<>'q') or (r4.i<> 29) or (r4.x<> 10.00) then e(13);
184 if (r4.c1<>'j') or (r4.i<> 8) or (r4.x<> 10000) then e(14);
187 if (r4.c1<>'w') or (r4.i<>-100) then e(12);
189 if (r4.c1<>'y') or (r4.i<> -35) then e(13);
191 if (r4.c1<>'q') or (r4.i<> 29) then e(13);
193 if (r4.c1<>'j') or (r4.i<> 8) then e(14);
198 begin for i:= -10 to +10 do a1[i] := i*j; f5^ := a1; put(f5); end;
201 begin a1:=f5^; get(f5); for i:= -10 to +10 do if a1[i]<> i*j then e(14) end;
205 for i:= 1 to 1000 do begin vr.r:=i+0.5; f6^:=vr; put(f6) ; p:=true; end;
208 begin vr:=f6^; get(f6); if vr.r <> i+0.5 then p:=true end;
213 if not eof(f6) then e(16);
214 for i:= 1 to 1000 do begin vr.b:=i mod 2; f6^:=vr; put(f6) end;
216 if eof(f6) then e(17);
219 begin vr:=f6^; get(f6); if vr.b <> i mod 2 then p:=true end;
220 if not eof(f6) then e(18);
227 if ord(f1^) <> 32 then e(20);
231 x:=0.0625; write(f1,x:6:4, x:6:2);
232 reset(f1); read(f1,y); if y <> 0.0625 then e(21);
233 reset(f1); for i:= 1 to 12 do begin c[i]:= f1^; get(f1) end;
234 if (c[1]<>'0') or (c[2]<>'.') or (c[4]<>'6') then e(22);
235 if (c[7]<>' ') or (c[9]<>'0') or (c[10]<>'.') or (c[12]<>'6') then e(23);
240 {************************************************************************}
244 g2: file of spectrum;
248 begin t:=35; pct := pct + 1;
249 rewrite(g1); rewrite(g2); rewrite(g3); rewrite(g4);
250 if (not (eof(g1) and eof(g4))) then e(1);
251 writeln(g1,'abc', 20+7:2,'a':2);
254 if eof(g1) or eoln(g1) then e(2);
255 read(g1,c[1]); read(g1,c[2]); read(g1,c[3],c[4],c[5],c[6],c[7]);
256 if (c[1]<>'a') or (c[3]<>'c') or (c[4]<>'2') or (c[7]<>'a') then e(3);
257 if not eoln(g1) then e(4)
259 for i:=1 to 2 do read(g1,c[8+i]);
260 if c[10]<>'y' then e(5);
261 if eof(g1) or eoln(g1) then e(6);
262 colors := []; g2^ := colors; put(g2);
263 colors := [pink]; g2^ := colors; put(g2);
264 colors := [pink,green]; g2^ := colors; put(g2);
265 colors := [orange,green]; g2^ := colors; put(g2);
267 colors := g2^; get(g2); if colors <> [] then e(7);
268 colors := g2^; get(g2); if colors <> [pink] then e(8);
269 colors := g2^; get(g2); if colors <> [green,pink] then e(9);
270 colors := g2^; get(g2); if colors <> [green,orange] then e(10);
273 r4.c1:='w'; r4.i:= -100; r4.x:=303.56; g3^:=r4; put(g3);
274 r4.c1:='y'; r4.i:= -35; r4.x:=26.32; g3^:=r4; put(g3);
275 r4.c1:='q'; r4.i:= +29; r4.x:=10.00; g3^:=r4; put(g3);
276 r4.c1:='j'; r4.i:= 8; r4.x:=10000; g3^:=r4; put(g3);
278 r4.c1:='w'; r4.i:= -100; g3^:=r4; put(g3);
279 r4.c1:='y'; r4.i:= -35; g3^:=r4; put(g3);
280 r4.c1:='q'; r4.i:= +29; g3^:=r4; put(g3);
281 r4.c1:='j'; r4.i:= 8; g3^:=r4; put(g3);
284 for i:= 1 to 1000 do begin g3^ := r4; put(g3) end;
286 if eof(g3) then e(11);
290 if (r4.c1<>'w') or (r4.i<>-100) or (r4.x<>303.56) then e(12);
292 if (r4.c1<>'y') or (r4.i<> -35) or (r4.x<> 26.32) then e(13);
294 if (r4.c1<>'q') or (r4.i<> 29) or (r4.x<> 10.00) then e(14);
296 if (r4.c1<>'j') or (r4.i<> 8) or (r4.x<> 10000) then e(15);
299 if (r4.c1<>'w') or (r4.i<>-100) then e(12);
301 if (r4.c1<>'y') or (r4.i<> -35) then e(13);
303 if (r4.c1<>'q') or (r4.i<> 29) then e(14);
305 if (r4.c1<>'j') or (r4.i<> 8) then e(15);
310 begin for i:= -10 to +10 do a1[i] := i*j; g4^ := a1; put(g4) end;
313 begin a1:=g4^; get(g4); for i:= -10 to +10 do if a1[i]<>i*j then e(16) end;
314 if not eof(g2) then e(17);
315 colors:=[q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11];
319 {***********************************************************************}
321 { Intermediate level files }
323 g2: file of spectrum;
329 begin t:=3701; pct := pct + 1;
330 rewrite(g1); rewrite(g2); rewrite(g3); rewrite(g4);
331 if (not (eof(g1) and eof(g4))) then e(1);
332 writeln(g1,'abc', 20+7:2,'a':2);
335 if eof(g1) or eoln(g1) then e(2);
336 read(g1,c[1]); read(g1,c[2]); read(g1,c[3],c[4],c[5],c[6],c[7]);
337 if (c[1]<>'a') or (c[3]<>'c') or (c[4]<>'2') or (c[7]<>'a') then e(3);
338 if not eoln(g1) then e(4)
340 for i:=1 to 2 do read(g1,c[8+i]);
341 if c[10]<>'y' then e(5);
342 if eof(g1) or eoln(g1) then e(6);
343 colors := []; g2^ := colors; put(g2);
344 colors := [pink]; g2^ := colors; put(g2);
345 colors := [pink,green]; g2^ := colors; put(g2);
346 colors := [orange,green]; g2^ := colors; put(g2);
348 colors := g2^; get(g2); if colors <> [] then e(7);
349 colors := g2^; get(g2); if colors <> [pink] then e(8);
350 colors := g2^; get(g2); if colors <> [green,pink] then e(9);
351 colors := g2^; get(g2); if colors <> [green,orange] then e(10);
354 r4.c1:='w'; r4.i:= -100; r4.x:=303.56; g3^:=r4; put(g3);
355 r4.c1:='y'; r4.i:= -35; r4.x:=26.32; g3^:=r4; put(g3);
356 r4.c1:='q'; r4.i:= +29; r4.x:=10.00; g3^:=r4; put(g3);
357 r4.c1:='j'; r4.i:= 8; r4.x:=10000; g3^:=r4; put(g3);
359 r4.c1:='w'; r4.i:= -100; g3^:=r4; put(g3);
360 r4.c1:='y'; r4.i:= -35; g3^:=r4; put(g3);
361 r4.c1:='q'; r4.i:= +29; g3^:=r4; put(g3);
362 r4.c1:='j'; r4.i:= 8; g3^:=r4; put(g3);
365 for i:= 1 to 1000 do begin g3^ := r4; put(g3) end;
367 if eof(g3) then e(11);
371 if (r4.c1<>'w') or (r4.i<>-100) or (r4.x<>303.56) then e(12);
373 if (r4.c1<>'y') or (r4.i<> -35) or (r4.x<> 26.32) then e(13);
375 if (r4.c1<>'q') or (r4.i<> 29) or (r4.x<> 10.00) then e(14);
377 if (r4.c1<>'j') or (r4.i<> 8) or (r4.x<> 10000) then e(15);
380 if (r4.c1<>'w') or (r4.i<>-100) then e(12);
382 if (r4.c1<>'y') or (r4.i<> -35) then e(13);
384 if (r4.c1<>'q') or (r4.i<> 29) then e(14);
386 if (r4.c1<>'j') or (r4.i<> 8) then e(15);
390 begin for i:= -10 to +10 do a1[i] := i*j; g4^ := a1; put(g4) end;
393 begin a1:=g4^; get(g4); for i:= -10 to +10 do if a1[i]<>i*j then e(16) end;
396 begin t:=37; pct := pct+1;
399 if not eof(g2) then e(1);
404 {***********************************************************************}
406 { Advanced set theory }
407 begin t:=38; pct := pct + 1;
408 if [50] >= [49,51] then e(1);
409 if [10] <= [9,11] then e(2);
410 if not ([50] <= [49..51]) then e(3);
411 i:=1; j:=2; k:=3; l:=5;
412 if [i] + [j] <> [i,j] then e(4);
413 if [i] + [j] <> [i..j] then e(5);
414 if [j..i] <> [] then e(6);
415 if [j..l] + [j..k] <> [2,3,4,5] then e(7);
416 if ([1..k, l..8] + [10]) * [k..7, 2, l] <> [2,3,l..7] then e(8);
417 if [i..9] - [j..l] <> [1,l+1..k*k] then e(9);
418 if [k..j] <> [i..j] * [k..l] then e(10);
419 if not ([k..10] <= [i..15]) then e(11);
420 if not ([k-1..k*l] <= [i..15]) then e(12);
422 letters := ['a','b', 'z'];
423 if letters <> ['a', 'b', 'z'] then e(13);
424 cset := ['a'] + ['b', 'c', 'z'] - ['c','d'];
425 if cset <> letters then e(14);
427 if cset <> ['a', 'b', 'c', 'd', 'e'] then e(15);
428 cset := ['a'..'z', '0'..'9', '+','-','*','/','.',':','(',')','{','}'];
429 if not ('+' in cset) or not ('.' in cset) or not ('}' in cset) then e(16);
430 letters := ['a'..'z' , '0'..'9'];
431 if letters >= cset then e(17);
435 {***********************************************************************}
438 begin ect:=0; pct:=0;
439 tst34; tst35; tst36; tst37; tst38;
440 write('Program t3:',pct:3,' tests completed.');
441 writeln('Number of errors = ',ect:1);