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
19 program t4(input,output);
20 { Tests for the EM-1 compiler }
21 const rcsversion='$Id: t4.p,v 2.4 1994/06/24 12:37:00 ceriel Exp $';
22 type vec = array[1..1000] of integer;
23 spectrum = set of (red,blue,yellow);
25 tp2 = record c1:char;i,j:integer; p:boolean; x:real end;
27 tp2 = record c1:char;i,j:integer; p:boolean end;
29 cmat = array[0..3,0..7] of ^spectrum;
30 single = array [0..0] of integer;
32 node = record val: integer; next: np end;
34 var t,ect,pct:integer;
43 procedure e(n:integer);
46 writeln(' Error', n:3,' in test ', t)
49 function inc(k:integer):integer; begin inc := k+1 end;
50 function twice(k:integer):integer; begin twice := 2*k end;
51 function decr(k:integer):integer; begin decr := k-1 end;
61 for i:=1 to 10 do new(pt1);
62 for i:=1 to 1000 do new(pt3);
65 begin t:= 40; pct:=pct+1;
78 begin t:=41; pct := pct + 1;
79 if red in [] then e(1);
80 if ([] <> []) then e(2);
81 if not ([] = []) then e(3);
82 if not([] <=[]) then e(4);
83 if not ( [] >= []) then e(5);
87 {************************************************************************}
89 { Record variants. These tests are machine dependent }
90 var s:record b:boolean; case t:boolean of false:(c:char);true:(d:cmat) end;
93 false: (x:array[0..20] of integer);
94 true: (x1,x2,x3,a,b,c,d,e,f,g,h,i,j,k,l:char)
99 false: (x:array[0..20] of integer);
100 true: (a,b,c,d,e,f,g,h,i,j,k,l:char)
103 begin t:=42; pct:=pct+1;
104 s.t:=false; s.c:='x'; if s.c <> 'x' then e(1);
105 for i:=0 to 20 do begin w.x[i]:=-1; y.x[i]:=-1 end;
106 w.a:=chr(0); w.f:=chr(0);
107 y.a:=chr(0); y.f:=chr(0);
108 if (ord(w.a) <> 0) or (ord(w.b) <> 255) then e(3);
109 if (ord(w.c) <> 255) or (ord(w.d)<>255) then e(4);
110 if (ord(w.e) <> 255) or (ord(w.f) <> 0) then e(5);
111 if ord(y.a) <> 0 then e(6);
112 if ord(y.f) <> 0 then e(7);
118 {************************************************************************}
120 { Procedure and function parameters }
121 function incr(k:integer):integer; begin incr := k+1 end;
122 function double(k:integer):integer; begin double := 2*k end;
123 function eval(function f(a:integer):integer; a:integer):integer;
124 begin eval:=f(a) end;
125 function apply(function f(a:integer):integer; a:integer):integer;
126 begin apply:=eval(f,a) end;
128 procedure x1(function f(a:integer):integer; a:integer; var r:integer);
129 procedure x2(function g(c:integer):integer; b:integer; var s:integer);
130 begin s:=apply(g,b); end;
131 begin x2(f, a+a, r) end;
133 procedure p0(procedure p(x:integer); i,j:integer);
135 if j=0 then p(i) else p0(p,i+j,j-1)
138 procedure p1(a,b,c,d:integer);
140 procedure p2(x:integer);
149 begin t:=43; pct := pct+1;
151 if incr(0) <> 1 then e(1);
152 if decr(i) <> 9 then e(2);
153 if double(i+j) <> 60 then e(3);
154 if incr(double(j)) <> 41 then e(4);
155 if decr(double(incr(double(i)))) <> 41 then e(5);
156 if incr(incr(incr(incr(incr(5))))) <> 10 then e(6);
157 if eval(incr,i) <> 11 then e(7);
158 if eval(decr,3) <> 2 then e(8);
159 if incr(eval(double,15)) <> 31 then e(9);
160 if apply(incr,3) <> 4 then e(10);
162 x1(double,i,j); if j <> 40 then e(11);
163 x1(incr,i+3,j); if j <> 27 then e(12);
168 if inc(incr(twice(double(inc(incr(twice(double(j)))))))) <> 26 then e(13);
172 {************************************************************************}
175 type ww2 = array[-10..+10] of tp2;
176 arra = array[-10..+10] of integer;
177 reca = record k:single; s:spectrum end;
180 var l1:integer; xr:real; xb:boolean; xc:char; xar:cmat; xnode:pa;
182 var l1:integer; xb:boolean; xc:char; xar:cmat; xnode:pa;
184 vec1: arra; vec2: ww2;
185 s2:spectrum; rec1: reca;
189 procedure tst4401(pl1:integer; pxr:real; pxb:boolean; pxc:char;
191 procedure tst4401(pl1:integer; pxb:boolean; pxc:char;
193 pxar:cmat; pxnode:pa; pxtp2:tp2;
194 pvec1:arra; pvec2:ww2; prec1:reca;
195 ps1,ps2:spectrum; psin:single; i,j:integer);
196 begin t:=4401; pct:=pct+1;
197 if pl1<>29 then e(1);
199 if pxr<>-0.31 then e(2);
201 if pxb <> false then e(3);
202 if pxc <> 'k' then e(4);
203 if (pxar[1,1]^<>[red,blue]) or (pxar[2,2]^ <> [yellow]) then e(5);
204 if (pxnode^.val <> 105) or (pxnode^.next^.val <> 106) then e(6);
206 if (pxtp2.c1 <> 'w') or (pxtp2.x <> 20.3) then e(7);
208 if (pxtp2.c1 <> 'w') then e(7);
210 if pvec1[10] <> -996 then e(8);
212 if pvec2[zero].x <> -300 then e(9);
214 if (prec1.k[zero] <> -421) or (prec1.s <> []) then e(10);
215 if (ps1<>[]) or (ps2<>[red]) then e(11);
216 if psin[zero] <> -421 then e(12);
217 if i <> -421 then e(13);
218 if j <> 106 then e(14);
220 pl1:=0; pxc:=' '; pxb:=true;
221 pxar[1,1]^:=[]; pxar[2,2]^:=[];
222 pxnode^.val:=0; pxnode^.next^.val:=1;
229 psin[0]:=0; i:=0; j:=0;
232 begin t:=44; pct:=pct+1;
235 l1:=29; xr:=-0.31; xb:=false; xc:='k';
237 l1:=29; xb:=false; xc:='k';
239 new(xar[1,1]); xar[1,1]^ := [red,blue];
240 new(xar[2,2]); xar[2,2]^ := [yellow];
241 new(xar[1,2]); xar[1,2]^ := [yellow];
242 new(xnode); xnode^.val :=105;
243 new(xnode^.next); xnode^.next^.val :=106;
245 r1.c1:='w'; r1.x:=20.3;
246 vec1[10] := -996; vec2[zero].x := -300;
251 rec1.k[zero]:=-421; rec1.s :=[];
255 tst4401(l1, xr, xb, xc, xar, xnode, r1, vec1, vec2, rec1,
257 tst4401(l1, xb, xc, xar, xnode, r1, vec1, vec2, rec1,
259 [], s2, rec1.k, rec1.k[zero], xnode^.next^.val);;
264 if xr<> -0.31 then e(2);
266 if xb <> false then e(3);
267 if xc <> 'k' then e(4);
268 if (xar[1,1]^ <> []) or (xar[2,2]^ <> []) then e(5);
269 if xar[1,2]^ <> [yellow] then e(6);
270 if (xnode^.val <> 0) or (xnode^.next^.val <> 1) then e(7);
272 if (r1.c1 <> 'w') or (r1.x <> 20.3) then e(8);
274 if (r1.c1 <> 'w') then e(8);
276 if vec1[10] <> -996 then e(9);
278 if vec2[zero].x <> -300 then e(10);
280 if (rec1.k[zero] <> -421) or (rec1.s <> []) then e(11);
281 if s2 <> [red] then e(12);
285 {************************************************************************}
288 type ww2 = array[-10..+10] of tp2;
289 arra = array[-10..+10] of integer;
290 reca = record k:single; s:spectrum end;
293 var l1:integer; xr:real; xb:boolean; xc:char; xar:cmat; xnode:pa;
295 var l1:integer; xb:boolean; xc:char; xar:cmat; xnode:pa;
297 vec1: arra; vec2: ww2;
298 s1,s2:spectrum; rec1: reca;
302 procedure tst4501(var pl1:integer; var pxr:real; var pxb:boolean; var pxc:char;
304 procedure tst4501(var pl1:integer; var pxb:boolean; var pxc:char;
306 var pxar:cmat; var pxnode:pa; var pxtp2:tp2;
307 var pvec1:arra; var pvec2:ww2; var prec1:reca;
308 var ps1,ps2:spectrum; var psin:single; var i,j:integer);
309 begin t:=4501; pct:=pct+1;
310 if pl1<>29 then e(1);
312 if pxr<>-0.31 then e(2);
314 if pxb <> false then e(3);
315 if pxc <> 'k' then e(4);
316 if (pxar[1,1]^<>[red,blue]) or (pxar[2,2]^ <> [yellow]) then e(5);
317 if (pxnode^.val <> 105) or (pxnode^.next^.val <> 106) then e(6);
319 if (pxtp2.c1 <> 'w') or (pxtp2.x <> 20.3) then e(7);
321 if (pxtp2.c1 <> 'w') then e(7);
323 if pvec1[10] <> -996 then e(8);
325 if pvec2[zero].x <> -300 then e(9);
327 if (prec1.k[zero] <> -421) or (prec1.s <> []) then e(10);
328 if (ps1<>[]) or (ps2<>[red]) then e(11);
329 if psin[zero] <> -421 then e(12);
330 if i <> -421 then e(13);
331 if j <> 106 then e(14);
334 pl1:=0; pxr:=0; pxc:=' '; pxb:=true;
336 pl1:=0; pxc:=' '; pxb:=true;
338 pxar[1,1]^:=[]; pxar[2,2]^:=[];
339 pxnode^.val:=0; pxnode^.next^.val:=1;
349 psin[0]:=0; i:=223; j:=445;
352 begin t:=45; pct:=pct+1;
355 l1:=29; xr:=-0.31; xb:=false; xc:='k';
357 l1:=29; xb:=false; xc:='k';
359 new(xar[1,1]); xar[1,1]^ := [red,blue];
360 new(xar[2,2]); xar[2,2]^ := [yellow];
361 new(xar[1,2]); xar[1,2]^ := [yellow];
362 new(xnode); xnode^.val :=105;
363 new(xnode^.next); xnode^.next^.val :=106;
365 r1.c1:='w'; r1.x:=20.3;
366 vec1[10] := -996; vec2[zero].x := -300;
371 rec1.k[zero]:=-421; rec1.s :=[];
375 tst4501(l1, xr, xb, xc, xar, xnode, r1, vec1, vec2, rec1,
377 tst4501(l1, xb, xc, xar, xnode, r1, vec1, vec2, rec1,
379 s1, s2, rec1.k, rec1.k[zero], xnode^.next^.val);;
386 if xb <> true then e(3);
387 if xc <> ' ' then e(4);
388 if (xar[1,1]^ <> []) or (xar[2,2]^ <> []) then e(5);
389 if xar[1,2]^ <> [yellow] then e(6);
390 if (xnode^.val <> 0) or (xnode^.next^.val <> 445) then e(7);
392 if (r1.c1 <> ' ') or (r1.x <> 0) then e(8);
394 if (r1.c1 <> ' ') then e(8);
396 if vec1[10] <> 0 then e(9);
398 if vec2[zero].x <> 0 then e(10);
400 if (rec1.k[zero] <> 223) or (rec1.s <> []) then e(11);
401 if (s1 <> []) or (s2 <> [red]) then e(12);
407 begin ect:=0; pct:=0;
408 tst40; tst41; tst42; tst43; tst44; tst45;
409 write('Program t4:',pct:3,' tests completed.');
410 writeln('Number of errors = ',ect:1);