From 7a212fff3ece55f0353a8a9fe95a0f635f2fbcba Mon Sep 17 00:00:00 2001 From: Bob Zieman Date: Wed, 19 Feb 1992 08:21:23 +0000 Subject: [PATCH] Initial revision --- src/util/calcTest.c | 173 ++++++++++++++++++++++++++++ src/util/in.calcTest | 264 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 437 insertions(+) create mode 100644 src/util/calcTest.c create mode 100644 src/util/in.calcTest diff --git a/src/util/calcTest.c b/src/util/calcTest.c new file mode 100644 index 000000000..9e9a06e7f --- /dev/null +++ b/src/util/calcTest.c @@ -0,0 +1,173 @@ +/* calcTest.c */ +/* share/src/util ??? $Id$ */ + +/* calcTest.c - calcPerform Test Program + * + * Author: Janet Anderson + * Date: 02-05-92 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: + * ----------------- + * .01 02-10-92 jba initial version + * + */ + +#ifdef vxWorks +#include +#include +#include +#else +#include +#include +#endif + +#ifndef ERROR +#define ERROR -1 +#endif +#ifndef OK +#define OK 0 +#endif + +#define PUT 0 +#define GET 1 +#define MAXLINE 150 + +char errmsg[MAXLINE]; + +long calcPerform(); +long postfix(); +void calcTest(); +long doTestLine(); + +#ifndef vxWorks +main() +{ + + calcTest(); + +} +#endif + +void calcTest() +{ + char str[MAXLINE]; + + char testId[MAXLINE]; + char expression[MAXLINE]; + char parmList[MAXLINE]; + char value[MAXLINE]; + char verify[MAXLINE]; + int count; + long status; + double parm[12]; + short i; + + /* get test line */ + while ( gets(str)) { + + /* print and skip null lines and comment lines */ + if ( str[0]==NULL || str[0] == '!' ) { + printf("%s\n",str); + continue; + } + + /* parse input line for fields */ + count=sscanf(str,"%s \"%[^\"]\" \"%[^\"]\" %s %s", + testId,expression,parmList,value,verify); + + /* check field count */ + if ( count != 5 ) { + printf("\n%s\n",str); + printf ("***** ERROR ***** field count %d is less than 5\n",count); + continue; + } + + /* parse parmList for parameters */ + status=sscanf(parmList,"%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", + &parm[0],&parm[1],&parm[2],&parm[3],&parm[4],&parm[5], + &parm[6],&parm[7],&parm[8],&parm[9],&parm[10],&parm[11]); + if( status == EOF ){ + printf("\n%s\n",str); + printf ("***** ERROR ***** Error in parameter list %s \n",parmList); + continue; + } + + /* zero out rest of parameters */ + for (i=status; i<12; i++) parm[i]=0.; + + + /* execute test line */ + status=doTestLine(expression,parm,value,verify); + if ( status ){ + printf("\n%s\n",str); + printf ("***** ERROR ***** status=%d %s\n",status,errmsg); + } + + } + printf ("\ncalcTest ALL DONE\n\n\n"); +} + +long doTestLine(expression,parm,value,verify) +char expression[]; +double parm[12]; +char value[]; +char verify[]; +{ + long status=0; + short error_number=0; + char rpbuf[80]; + char valString[80]; + double val; + + /* convert an algebraic expression to symbolic postfix */ + status=postfix(expression,rpbuf,&error_number); + if(status || error_number) { + sprintf(errmsg,"postfix error: status=%ld error_number=%d \n",status,error_number); + return ERROR; + } + + /* perform calculation */ + status=calcPerform(parm,&val,rpbuf); + if(status) { + sprintf(errmsg,"calcPerform error: status=%ld \n",status); + return ERROR; + } + + /* convert calcPerform result to string */ + sprintf(valString,"%-g",val); + + /* verify calcPerform result*/ + if (*verify == 'V'){ + + status=strcmp(value,valString); + if (status) { + sprintf(errmsg,"verify failed: calcPerform result: val=%s",valString); + return ERROR; + } + } + else printf("calcPerform result: %s\n",valString); + + return OK; +} + diff --git a/src/util/in.calcTest b/src/util/in.calcTest new file mode 100644 index 000000000..13229c9a7 --- /dev/null +++ b/src/util/in.calcTest @@ -0,0 +1,264 @@ +! ***************************************************** +! TEST OF +! calcPerform +! +! ------------- TEST CALCULATION ALGORITHM ------------- +! +! ***************************************************** +! +! ld = + +calcTest "(a+b+c)>=d" "1 2 3 4 5 6 7 8 9 10 11 12" 1 VERIFY +calcTest "(a+b+c)>=(d+e)" "1 2 3 4 5 6 7 8 9 10 11 12" 0 VERIFY + +! --------------------------------------Greater than > + +calcTest "(e+f+g)>(h+i)" "1 2 3 4 5 6 7 8 9 10 11 12" 1 VERIFY +calcTest "(e+f+g)>(h+i+k)" "1 2 3 4 5 6 7 8 9 10 11 12" 0 VERIFY + +! --------------------------------------Less than or equal to <= + +calcTest "(e+f+g)<=(i+k)" "1 2 3 4 5 6 7 8 9 10 11 12" 1 VERIFY +calcTest "(e+f+g+h)<=(i+k)" "1 2 3 4 5 6 7 8 9 10 11 12" 0 VERIFY + +! --------------------------------------Less than < +calcTest "(a+b)