### Diff for /gforth/test/ttester.fs between versions 1.4 and 1.12

version 1.4, 2007/08/28 19:15:03 version 1.12, 2008/11/08 18:28:22
Line 41 Line 41

\ There are a few things to be noted:  \ There are a few things to be noted:

\ sets the base to HEX for everything that gets loaded later.  \ changes BASE to HEX (like the original tester).  Floating-point
\ Floating-point input is ambiguous when the base is not decimal, so  \ input is ambiguous when the base is not decimal, so you have to set
\ you have to set it to decimal yourself when you want to deal with  \ it to decimal yourself when you want to deal with decimal numbers.
\ decimal numbers.

\ - For FP it is often useful to use approximate equality for checking  \ - For FP it is often useful to use approximate equality for checking
\ the results.  You can turn on approximate matching with SET-NEAR  \ the results.  You can turn on approximate matching with SET-NEAR
Line 101  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 176  HAS-FLOATING-STACK [IF] Line 174  HAS-FLOATING-STACK [IF]
: F-> ( ... -- ... )      : F-> ( ... -- ... )
FDEPTH DUP ACTUAL-FDEPTH !          FDEPTH DUP ACTUAL-FDEPTH !
START-FDEPTH @ > IF          START-FDEPTH @ > IF
FDEPTH START-FDEPTH @ DO ACTUAL-FRESULTS I FLOATS + F! LOOP              FDEPTH START-FDEPTH @ - 0 DO ACTUAL-FRESULTS I FLOATS + F! LOOP
THEN ;          THEN ;

: F} ( ... -- ... )      : F} ( ... -- ... )
FDEPTH ACTUAL-FDEPTH @ = IF          FDEPTH ACTUAL-FDEPTH @ = IF
FDEPTH START-FDEPTH @ > IF              FDEPTH START-FDEPTH @ > IF
FDEPTH START-FDEPTH @ DO                  FDEPTH START-FDEPTH @ - 0 DO
ACTUAL-FRESULTS I FLOATS + F@ FCONF= INVERT IF                      ACTUAL-FRESULTS I FLOATS + F@ FCONF= INVERT IF
S" INCORRECT FP RESULT: " ERROR LEAVE                          S" INCORRECT FP RESULT: " ERROR LEAVE
THEN                      THEN
Line 193  HAS-FLOATING-STACK [IF] Line 191  HAS-FLOATING-STACK [IF]
THEN ;          THEN ;

: F...}T ( -- )      : F...}T ( -- )
FDEPTH START-FDEPTH @ = 0= IF          FCURSOR @ START-FDEPTH @ + ACTUAL-FDEPTH @ <> IF
S" WRONG NUMBER OF FP RESULTS" ERROR              S" NUMBER OF FLOAT RESULTS BEFORE '->' DOES NOT MATCH ...}T SPECIFICATION: " ERROR
THEN          ELSE FDEPTH START-FDEPTH @ = 0= IF
FCURSOR @ ACTUAL-FDEPTH @ <> IF              S" NUMBER OF FLOAT RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR
S" WRONG NUMBER OF FP RESULTS" ERROR          THEN 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
THEN          ELSE 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
THEN          THEN THEN
1 FCURSOR +! ;          1 FCURSOR +! ;

[ELSE]  [ELSE]
Line 216  HAS-FLOATING-STACK [IF] Line 213  HAS-FLOATING-STACK [IF]
: F} ;      : F} ;
: F...}T ;      : F...}T ;

HAS-FLOATING [IF]
DECIMAL      DECIMAL
: COMPUTE-CELLS-PER-FP ( -- U )      : COMPUTE-CELLS-PER-FP ( -- U )
DEPTH 0E DEPTH 1- >R FDROP R> SWAP - ;          DEPTH 0E DEPTH 1- >R FDROP R> SWAP - ;
HEX      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          ELSE 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
THEN          THEN THEN
CELLS-PER-FP XCURSOR +! ;          CELLS-PER-FP XCURSOR +! ;
[THEN]          [THEN]
[THEN]

: EMPTY-STACK   \ ( ... -- ) EMPTY STACK: HANDLES UNDERFLOWED STACK TOO.  : EMPTY-STACK   \ ( ... -- ) EMPTY STACK: HANDLES UNDERFLOWED STACK TOO.
DEPTH START-DEPTH @ < IF      DEPTH START-DEPTH @ < IF
Line 256  HAS-FLOATING-STACK [IF] Line 254  HAS-FLOATING-STACK [IF]
: ->            \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK.  : ->            \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK.
DEPTH DUP ACTUAL-DEPTH !             \ RECORD DEPTH     DEPTH DUP ACTUAL-DEPTH !             \ RECORD DEPTH
START-DEPTH @ > IF           \ IF THERE IS SOMETHING ON STACK     START-DEPTH @ > IF           \ IF THERE IS SOMETHING ON STACK
DEPTH START-DEPTH @ DO ACTUAL-RESULTS I CELLS + ! LOOP \ SAVE THEM         DEPTH START-DEPTH @ - 0 DO ACTUAL-RESULTS I CELLS + ! LOOP \ SAVE THEM
THEN     THEN
F-> ;     F-> ;

Line 264  HAS-FLOATING-STACK [IF] Line 262  HAS-FLOATING-STACK [IF]
\ (ACTUAL) CONTENTS.                  \ (ACTUAL) CONTENTS.
DEPTH ACTUAL-DEPTH @ = IF            \ IF DEPTHS MATCH     DEPTH ACTUAL-DEPTH @ = IF            \ IF DEPTHS MATCH
DEPTH START-DEPTH @ > IF          \ IF THERE IS SOMETHING ON THE STACK        DEPTH START-DEPTH @ > IF          \ IF THERE IS SOMETHING ON THE STACK
DEPTH START-DEPTH @ DO         \ FOR EACH STACK ITEM           DEPTH START-DEPTH @ - 0 DO     \ FOR EACH STACK ITEM
ACTUAL-RESULTS I CELLS + @  \ COMPARE ACTUAL WITH EXPECTED              ACTUAL-RESULTS I CELLS + @  \ COMPARE ACTUAL WITH EXPECTED
<> IF S" INCORRECT RESULT: " ERROR LEAVE THEN              <> IF S" INCORRECT RESULT: " ERROR LEAVE THEN
LOOP           LOOP
Line 275  HAS-FLOATING-STACK [IF] Line 273  HAS-FLOATING-STACK [IF]
F} ;     F} ;

: ...}T ( -- )  : ...}T ( -- )
DEPTH START-DEPTH @ = 0= IF      XCURSOR @ START-DEPTH @ + ACTUAL-DEPTH @ <> IF
S" WRONG NUMBER OF RESULTS" ERROR          S" NUMBER OF CELL RESULTS BEFORE '->' DOES NOT MATCH ...}T SPECIFICATION: " ERROR
THEN      ELSE DEPTH START-DEPTH @ = 0= IF
XCURSOR @ ACTUAL-DEPTH @ <> IF          S" NUMBER OF CELL RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR
S" WRONG NUMBER OF RESULTS" ERROR      THEN 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      ELSE ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF
ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF
S" INCORRECT CELL RESULT: " ERROR          S" INCORRECT CELL RESULT: " ERROR
THEN      THEN THEN
1 XCURSOR +! ;      1 XCURSOR +! ;

: X}T XTESTER ...}T ;  : X}T XTESTER ...}T ;
: R}T FTESTER ...}T ;
: XX}T XTESTER XTESTER ...}T ;  : XX}T XTESTER XTESTER ...}T ;
: XXX}T XTESTER XTESTER XTESTER ...}T ;
: XXXX}T XTESTER XTESTER XTESTER XTESTER ...}T ;

HAS-FLOATING [IF]
: R}T FTESTER ...}T ;
: XR}T FTESTER XTESTER ...}T ;  : XR}T FTESTER XTESTER ...}T ;
: RX}T XTESTER FTESTER ...}T ;  : RX}T XTESTER FTESTER ...}T ;
: RR}T FTESTER FTESTER ...}T ;  : RR}T FTESTER FTESTER ...}T ;
: XXX}T XTESTER XTESTER XTESTER ...}T ;
: XXR}T FTESTER XTESTER XTESTER ...}T ;  : XXR}T FTESTER XTESTER XTESTER ...}T ;
: XRX}T XTESTER FTESTER XTESTER ...}T ;  : XRX}T XTESTER FTESTER XTESTER ...}T ;
: XRR}T FTESTER FTESTER XTESTER ...}T ;  : XRR}T FTESTER FTESTER XTESTER ...}T ;
Line 306  HAS-FLOATING-STACK [IF] Line 305  HAS-FLOATING-STACK [IF]
: RXR}T FTESTER XTESTER FTESTER ...}T ;  : RXR}T FTESTER XTESTER FTESTER ...}T ;
: RRX}T XTESTER FTESTER FTESTER ...}T ;  : RRX}T XTESTER FTESTER FTESTER ...}T ;
: RRR}T FTESTER FTESTER FTESTER ...}T ;  : RRR}T FTESTER FTESTER FTESTER ...}T ;
: XXXX}T XTESTER XTESTER XTESTER XTESTER ...}T ;
: XXXR}T FTESTER XTESTER XTESTER XTESTER ...}T ;  : XXXR}T FTESTER XTESTER XTESTER XTESTER ...}T ;
: XXRX}T XTESTER FTESTER XTESTER XTESTER ...}T ;  : XXRX}T XTESTER FTESTER XTESTER XTESTER ...}T ;
: XXRR}T FTESTER FTESTER XTESTER XTESTER ...}T ;  : XXRR}T FTESTER FTESTER XTESTER XTESTER ...}T ;
Line 322  HAS-FLOATING-STACK [IF] Line 320  HAS-FLOATING-STACK [IF]
: RRXR}T FTESTER XTESTER FTESTER FTESTER ...}T ;  : RRXR}T FTESTER XTESTER FTESTER FTESTER ...}T ;
: RRRX}T XTESTER FTESTER FTESTER FTESTER ...}T ;  : RRRX}T XTESTER FTESTER FTESTER FTESTER ...}T ;
: RRRR}T FTESTER FTESTER FTESTER FTESTER ...}T ;  : RRRR}T FTESTER FTESTER FTESTER FTESTER ...}T ;
[THEN]

: TESTING       \ ( -- ) TALKING COMMENT.  : TESTING       \ ( -- ) TALKING COMMENT.
SOURCE VERBOSE @     SOURCE VERBOSE @
Line 329  HAS-FLOATING-STACK [IF] Line 328  HAS-FLOATING-STACK [IF]
ELSE >IN ! DROP     ELSE >IN ! DROP
THEN ;     THEN ;

BASE !

BASE !

 Removed from v.1.4 changed lines Added in v.1.12

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