C02/test/slibtest.c02

182 lines
4.1 KiB
Plaintext

/*********************************
* SLIBTEST - Test Module stdlib *
*********************************/
//Specify System Header using -H option
#include <stddef.h02>
#include <stdlib.h02>
char aa, yy, xx;
void prtcma(aa) {putchr(','); prbyte(aa);}
void prtexp(aa) {putstr(", EXPECTED "); prbyte(aa);}
void prtlin() {putstr(); newlin();}
void prtok() {prtlin(" OK");}
void prtopr(aa,yy,xx) {prbyte(aa); putchr(yy); prbyte(xx); putchr('=');}
main:
tstabs: //Test abs()
char onum, anum, cnum;
putstr("ABS()");
onum = 0;
do { //test abs() positive numbers
anum = abs(onum);
if (onum <> anum) goto abserr;
onum++;
} while (onum < $80);
do { //test abs() negative numbers
anum = abs(onum);
cnum = -onum;
if (anum <> cnum) goto abserr;
onum++;
} while (onum);
prtok();
tstmnx: //Test min() and max()
char lnum, rnum, nnum, xnum;
putstr("MAX(), MIN()");
lnum = 0; do {
rnum = 0; do {
xnum = max(lnum,rnum);
nnum = min(lnum,rnum);
if (lnum > rnum) {
if (xnum <> lnum) maxerr();
if (nnum <> rnum) minerr();
} else {
if (xnum <> rnum) maxerr();
if (nnum <> lnum) minerr();
}
} while (rnum);
} while (lnum);
prtok();
tstmlt: //Test mult()
char mltplr, mltpnd, acmlsb, acmmsb, acmlst;
char prodct, ovrflw;
putstr("MULT()");
mltplr = 1;
do {
if (!mltplr & $F) putchr('.');
mltpnd = 1; acmlst = 0;
acmlsb = 0; acmmsb = 0;
do {
acmlsb = acmlsb + mltplr;
if (acmlsb<acmlst) acmmsb++;
acmlst = acmlsb;
prodct,ovrflw = mult(mltplr,mltpnd);
if (prodct <> acmlsb) goto mlterr;
mltpnd++;
} while (mltpnd);
mltplr++;
} while (mltplr);
prtok();
tstdiv: //Test div()
char maxmpd, divdnd, divisr, quotnt;
putstr("DIV()");
mltplr = 255;
maxmpd = 1;
while (mltplr) {
for (mltpnd=1; mltpnd < maxmpd; mltpnd++) {
prodct = mult(mltplr, mltpnd);
quotnt = div(prodct, mltpnd);
if (quotnt <> mltplr) goto diverr;
}
mltplr>>;
maxmpd<<;
}
prtok();
tstrnd: //Test rand() and rands()
char countr, rndnum, rndtbl[255];
putstr("RAND()");
rands(1); //Seed Random Number Generator;
countr = 0;
do {rndtbl[countr] = 0; countr++;} while (countr);
do {
rndnum = rand();
if (rndtbl[rndnum] > 0) goto rnderr;
rndtbl[rndnum] = $FF;
countr++;
} while (countr < 255);
prtok();
tstros: //Test rotatl(), rotatr(), swap()
char lbyte, rbyte, obyte, sbyte, tbyte, scount;
tstc2a: //Test ctoa();
char srcchr, dstchr, tststr[4];
putstr("ATOC(), CTOA()");
srcchr = 0; do {
ctoa(srcchr, &tststr);
dstchr = atoc(&tststr);
if (srcchr <> dstchr) goto c2aerr;
srcchr++;
} while (srcchr);
prtok();
goto exit;
abserr:
putstr("ABS("); prbyte(onum); putstr(")="); prbyte(anum); prtcma(cnum); newlin();
goto exit;
maxerr:
putstr("MAX("); prbyte(lnum); prtcma(rnum); putstr(")="); prbyte(xnum); newlin();
goto exit;
minerr:
putstr("MIN("); prbyte(lnum); prtcma(rnum); putstr(")="); prbyte(nnum); newlin();
goto exit;
mlterr:
newlin(); prtopr(mltplr,'*',mltpnd); prbyte(prodct); prtcma(acmlsb); newlin();
goto exit;
diverr:
newlin(); prtopr(quotnt,'/',mltplr); prbyte(quotnt);
prtexp(mltplr); newlin();
goto exit;
rnderr:
newlin(); putstr("RAND()="); prbyte(rndnum); prtcma(countr); newlin();
goto exit;
rtlerr:
newlin(); putstr("ROTATL("); prbyte(obyte); prtcma(scount); putstr(")=");
prbyte(rbyte); prtcma(tbyte); newlin();
goto exit;
rtrerr:
newlin(); putstr("ROTATR("); prbyte(obyte); prtcma(scount); putstr(")=");
prbyte(rbyte); prtcma(tbyte); newlin();
goto exit;
shlerr:
newlin(); putstr("SHIFTL("); prbyte(obyte); prtcma(scount); putstr(")=");
prbyte(lbyte); prtcma(sbyte); newlin();
goto exit;
shrerr:
newlin(); putstr("SHIFTR("); prbyte(obyte); prtcma(scount); putstr(")=");
prbyte(lbyte); prtcma(sbyte); newlin();
goto exit;
swperr:
newlin(); putstr("SWAP("); prbyte(obyte); putstr(")=");
prbyte(sbyte); prtcma(tbyte); newlin();
goto exit;
c2aerr:
newlin(); putstr("CTOA("); prbyte(srcchr); putstr(")="); putstr(tststr); newlin();
goto exit;