Diff for /gforth/test/ttester.fs between versions 1.1 and 1.6

version 1.1, 2007/08/19 21:33:50 version 1.6, 2007/10/26 12:47:41
Line 1 Line 1
 \ From: John Hayes S1I  \ FOR THE ORIGINAL TESTER
 \ Subject: tester.fr  \ FROM: JOHN HAYES S1I
 \ Date: Mon, 27 Nov 95 13:10:09 PST    \ SUBJECT: TESTER.FR
   \ DATE: MON, 27 NOV 95 13:10:09 PST  
 \ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY  \ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY
 \ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS.  \ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS.
 \ VERSION 1.1  \ VERSION 1.1
   
 \ revised by Anton Ertl 2007-08-12, 2007-08-19  \ FOR THE FNEARLY= STUFF:
 \ The original has the following shortcomings:  \ FROM FTESTER.FS WRITTEN BY DAVID N. WILLIAMS, BASED ON THE IDEA OF
   \ APPROXIMATE EQUALITY IN DIRK ZOLLER'S FLOAT.4TH
   \ PUBLIC DOMAIN
   
   \ FOR THE REST:
   \ REVISED BY ANTON ERTL 2007-08-12, 2007-08-19, 2007-08-28
   \ PUBLIC DOMAIN
   
   \ THE ORIGINAL HAS THE FOLLOWING SHORTCOMINGS:
   
   \ - IT DOES NOT WORK AS EXPECTED IF THE STACK IS NON-EMPTY BEFORE THE {.
   
   \ - IT DOES NOT CHECK FP RESULTS IF THE SYSTEM HAS A SEPARATE FP STACK.
   
   \ - THERE IS A CONFLICT WITH THE USE OF } FOR FSL ARRAYS AND { FOR LOCALS.
   
   \ I HAVE REVISED IT TO ADDRESS THESE SHORTCOMINGS.  YOU CAN FIND THE
   \ RESULT AT
   
 \ - It does not work as expected if the stack is non-empty before the {.  \ HTTP://WWW.FORTH200X.ORG/TESTS/TESTER.FS
   \ HTTP://WWW.FORTH200X.ORG/TESTS/TTESTER.FS
   
 \ - It does not check FP results if the system has a separate FP stack.  \ TESTER.FS IS INTENDED TO BE A DROP-IN REPLACEMENT OF THE ORIGINAL.
   
 \ - There is a conflict with the use of } for FSL arrays and { for locals.  \ TTESTER.FS IS A VERSION THAT USES T{ AND }T INSTEAD OF { AND } AND
   \ KEEPS THE BASE AS IT WAS BEFORE LOADING TTESTER.FS
   
 \ I have revised it to address these shortcomings.  You can find the  \ IN SPIRIT OF THE ORIGINAL, I HAVE STRIVED TO AVOID ANY POTENTIAL
 \ result at  \ NON-PORTABILITIES AND STAYED AS MUCH WITHIN THE CORE WORDS AS
   \ POSSIBLE; E.G., FLOATING WORDS ARE USED ONLY IF THE FLOATING WORDSET
 \ http://www.forth200x.org/tests/tester.fs  \ IS PRESENT
 \ http://www.forth200x.org/tests/ttester.fs  
   
 \ tester.fs is intended to be a drop-in replacement of the original.  
 \ ttester.fs is a version that uses T{ and }T instead of { and }.  
   
 \ In spirit of the original, I have strived to avoid any potential  
 \ non-portabilities and stayed as much within the CORE words as  
 \ possible; e.g., FLOATING words are used only if the FLOATING wordset  
 \ is present  
   
 \ There are a few things to be noted:  
   
 \ - Following the despicable practice of the original, this version  
 \ sets the base to HEX for everything that gets loaded later.  
 \ Floating-point input is ambiguous when the base is not decimal, so  
 \ you have to set it to decimal yourself when you want to deal with  
 \ decimal numbers.  
   
 \ - For FP it is often useful to use approximate equality for checking  
 \ the results.  You can turn on approximate matching with SET-NEAR  
 \ (and turn it off (default) with SET-EXACT, and you can tune it by  
 \ setting the variables REL-NEAR and ABS-NEAR.  If you want your tests  
 \ to work with a shared stack, you have to specify the types of the  
 \ elements on the stack by using one of the closing words that specify  
 \ types, e.g. RRRX}T for checking the stack picture ( r r r x ).  
 \ There are such words for all combination of R and X with up to 4  
 \ stack items, and defining more if you need them is straightforward  
 \ (see source).  If your tests are only intended for a separate-stack  
 \ system or if you need only exact matching, you can use the plain }T  
 \ instead.  
   
   \ THERE ARE A FEW THINGS TO BE NOTED:
   
   \ - LOADING TTESTER.FS DOES NOT CHANGE BASE.  LOADING TESTER.FS
   \ CHANGES BASE TO HEX (LIKE THE ORIGINAL TESTER).  FLOATING-POINT
   \ INPUT IS AMBIGUOUS WHEN THE BASE IS NOT DECIMAL, SO YOU HAVE TO SET
   \ IT TO DECIMAL YOURSELF WHEN YOU WANT TO DEAL WITH DECIMAL NUMBERS.
   
   \ - FOR FP IT IS OFTEN USEFUL TO USE APPROXIMATE EQUALITY FOR CHECKING
   \ THE RESULTS.  YOU CAN TURN ON APPROXIMATE MATCHING WITH SET-NEAR
   \ (AND TURN IT OFF (DEFAULT) WITH SET-EXACT, AND YOU CAN TUNE IT BY
   \ SETTING THE VARIABLES REL-NEAR AND ABS-NEAR.  IF YOU WANT YOUR TESTS
   \ TO WORK WITH A SHARED STACK, YOU HAVE TO SPECIFY THE TYPES OF THE
   \ ELEMENTS ON THE STACK BY USING ONE OF THE CLOSING WORDS THAT SPECIFY
   \ TYPES, E.G. RRRX}T FOR CHECKING THE STACK PICTURE ( R R R X ).
   \ THERE ARE SUCH WORDS FOR ALL COMBINATION OF R AND X WITH UP TO 4
   \ STACK ITEMS, AND DEFINING MORE IF YOU NEED THEM IS STRAIGHTFORWARD
   \ (SEE SOURCE).  IF YOUR TESTS ARE ONLY INTENDED FOR A SEPARATE-STACK
   \ SYSTEM OR IF YOU NEED ONLY EXACT MATCHING, YOU CAN USE THE PLAIN }T
   \ INSTEAD.
   
   BASE @
 HEX  HEX
   
 \ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY  \ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY
Line 90  HAS-FLOATING [IF] Line 100  HAS-FLOATING [IF]
     \ SET THE FOLLOWING TO THE RELATIVE AND ABSOLUTE TOLERANCES YOU      \ SET THE FOLLOWING TO THE RELATIVE AND ABSOLUTE TOLERANCES YOU
     \ WANT FOR APPROXIMATE FLOAT EQUALITY, TO BE USED WITH F~ IN      \ WANT FOR APPROXIMATE FLOAT EQUALITY, TO BE USED WITH F~ IN
     \ FNEARLY=.  KEEP THE SIGNS, BECAUSE F~ NEEDS THEM.      \ FNEARLY=.  KEEP THE SIGNS, BECAUSE F~ NEEDS THEM.
     FVARIABLE FSENSITIVITY DECIMAL 1E-12 HEX FSENSITIVITY F!      FVARIABLE REL-NEAR DECIMAL 1E-12 HEX REL-NEAR F!
     : REL-NEAR FSENSITIVITY ;  
     FVARIABLE ABS-NEAR    DECIMAL 0E HEX ABS-NEAR F!      FVARIABLE ABS-NEAR    DECIMAL 0E HEX ABS-NEAR F!
   
     \ WHEN EXACT? IS TRUE, }F USES FEXACTLY=, OTHERWISE FNEARLY=.      \ WHEN EXACT? IS TRUE, }F USES FEXACTLY=, OTHERWISE FNEARLY=.
Line 183  HAS-FLOATING-STACK [IF] Line 192  HAS-FLOATING-STACK [IF]
   
     : F...}T ( -- )      : F...}T ( -- )
         FDEPTH START-FDEPTH @ = 0= IF          FDEPTH START-FDEPTH @ = 0= IF
             S" WRONG NUMBER OF FP RESULTS" ERROR              S" NUMBER OF FLOAT RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR
         THEN          THEN
         FCURSOR @ ACTUAL-FDEPTH @ <> IF          FCURSOR @ START-FDEPTH @ + ACTUAL-FDEPTH @ <> IF
             S" WRONG NUMBER OF FP RESULTS" ERROR              S" NUMBER OF FLOAT RESULTS BEFORE '->' DOES NOT MATCH ...}T SPRECIFICATION: " ERROR
         THEN ;          THEN ;
           
     : FTESTER ( R -- )      : FTESTER ( R -- )
         FDEPTH 0= ACTUAL-FDEPTH @ FCURSOR @ 1+ < OR IF          FDEPTH 0= ACTUAL-FDEPTH @ FCURSOR @ START-FDEPTH @ + 1+ < OR IF
             S" WRONG NUMBER OF FP RESULTS: " ERROR EXIT              S" NUMBER OF FLOAT RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT
         THEN          THEN
         ACTUAL-FRESULTS FCURSOR @ FLOATS + F@ FCONF= 0= IF          ACTUAL-FRESULTS FCURSOR @ FLOATS + F@ FCONF= 0= IF
             S" INCORRECT FP RESULT: " ERROR              S" INCORRECT FP RESULT: " ERROR
Line 205  HAS-FLOATING-STACK [IF] Line 214  HAS-FLOATING-STACK [IF]
     : F} ;      : F} ;
     : F...}T ;      : F...}T ;
   
       DECIMAL
     : COMPUTE-CELLS-PER-FP ( -- U )      : COMPUTE-CELLS-PER-FP ( -- U )
         DEPTH 0E DEPTH >R FDROP R> SWAP - ;          DEPTH 0E DEPTH 1- >R FDROP R> SWAP - ;
       HEX
   
     COMPUTE-CELLS-PER-FP CONSTANT CELLS-PER-FP      COMPUTE-CELLS-PER-FP CONSTANT CELLS-PER-FP
           
     : FTESTER ( R -- )      : FTESTER ( R -- )
         DEPTH CELLS-PER-FP < ACTUAL-DEPTH @ XCURSOR @ CELLS-PER-FP + < OR IF          DEPTH CELLS-PER-FP < ACTUAL-DEPTH @ XCURSOR @ START-DEPTH @ + CELLS-PER-FP + < OR IF
             S" WRONG NUMBER OF RESULTS: " ERROR EXIT              S" NUMBER OF RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT
         THEN          THEN
         ACTUAL-RESULTS XCURSOR @ CELLS + F@ FCONF= 0= IF          ACTUAL-RESULTS XCURSOR @ CELLS + F@ FCONF= 0= IF
             S" INCORRECT FP RESULT: " ERROR              S" INCORRECT FP RESULT: " ERROR
Line 238  HAS-FLOATING-STACK [IF] Line 249  HAS-FLOATING-STACK [IF]
 ' ERROR1 ERROR-XT !  ' ERROR1 ERROR-XT !
   
 : T{            \ ( -- ) SYNTACTIC SUGAR.  : T{            \ ( -- ) SYNTACTIC SUGAR.
    DEPTH START-DEPTH ! F{ ;     DEPTH START-DEPTH ! 0 XCURSOR ! F{ ;
   
 : ->            \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK.  : ->            \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK.
    DEPTH DUP ACTUAL-DEPTH !             \ RECORD DEPTH     DEPTH DUP ACTUAL-DEPTH !             \ RECORD DEPTH
Line 263  HAS-FLOATING-STACK [IF] Line 274  HAS-FLOATING-STACK [IF]
   
 : ...}T ( -- )  : ...}T ( -- )
     DEPTH START-DEPTH @ = 0= IF      DEPTH START-DEPTH @ = 0= IF
         S" WRONG NUMBER OF RESULTS" ERROR          S" NUMBER OF CELL RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR
     THEN      THEN
     XCURSOR @ ACTUAL-DEPTH @ <> IF      XCURSOR @ START-DEPTH @ + ACTUAL-DEPTH @ <> IF
         S" WRONG NUMBER OF RESULTS" ERROR          S" NUMBER OF CELL RESULTS BEFORE '->' DOES NOT MATCH ...}T SPRECIFICATION: " ERROR
     THEN      THEN
     F...}T ;      F...}T ;
   
 : XTESTER ( X -- )  : XTESTER ( X -- )
     DEPTH 0= ACTUAL-DEPTH @ XCURSOR @ 1+ < OR IF      DEPTH 0= ACTUAL-DEPTH @ XCURSOR @ START-DEPTH @ + 1+ < OR IF
         S" WRONG NUMBER OF RESULTS: " ERROR EXIT          S" NUMBER OF CELL RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT
     THEN      THEN
     ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF      ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF
         S" INCORRECT CELL RESULT: " ERROR          S" INCORRECT CELL RESULT: " ERROR
Line 315  HAS-FLOATING-STACK [IF] Line 326  HAS-FLOATING-STACK [IF]
    IF DUP >R TYPE CR R> >IN !     IF DUP >R TYPE CR R> >IN !
    ELSE >IN ! DROP     ELSE >IN ! DROP
    THEN ;     THEN ;
   
   BASE !

Removed from v.1.1  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>