--- gforth/test/ttester.fs 2007/08/28 19:15:03 1.4 +++ gforth/test/ttester.fs 2007/11/03 09:25:35 1.10 @@ -41,11 +41,10 @@ \ 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. +\ - 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 @@ -101,8 +100,7 @@ HAS-FLOATING [IF] \ SET THE FOLLOWING TO THE RELATIVE AND ABSOLUTE TOLERANCES YOU \ WANT FOR APPROXIMATE FLOAT EQUALITY, TO BE USED WITH F~ IN \ FNEARLY=. KEEP THE SIGNS, BECAUSE F~ NEEDS THEM. - FVARIABLE FSENSITIVITY DECIMAL 1E-12 HEX FSENSITIVITY F! - : REL-NEAR FSENSITIVITY ; + FVARIABLE REL-NEAR DECIMAL 1E-12 HEX REL-NEAR F! FVARIABLE ABS-NEAR DECIMAL 0E HEX ABS-NEAR F! \ WHEN EXACT? IS TRUE, }F USES FEXACTLY=, OTHERWISE FNEARLY=. @@ -176,13 +174,13 @@ HAS-FLOATING-STACK [IF] : F-> ( ... -- ... ) FDEPTH DUP ACTUAL-FDEPTH ! 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 ; : F} ( ... -- ... ) FDEPTH ACTUAL-FDEPTH @ = IF FDEPTH START-FDEPTH @ > IF - FDEPTH START-FDEPTH @ DO + FDEPTH START-FDEPTH @ - 0 DO ACTUAL-FRESULTS I FLOATS + F@ FCONF= INVERT IF S" INCORRECT FP RESULT: " ERROR LEAVE THEN @@ -193,20 +191,19 @@ HAS-FLOATING-STACK [IF] THEN ; : F...}T ( -- ) - FDEPTH START-FDEPTH @ = 0= IF - S" WRONG NUMBER OF FP RESULTS" ERROR - THEN - FCURSOR @ ACTUAL-FDEPTH @ <> IF - S" WRONG NUMBER OF FP RESULTS" ERROR - THEN ; + FCURSOR @ START-FDEPTH @ + ACTUAL-FDEPTH @ <> IF + S" NUMBER OF FLOAT RESULTS BEFORE '->' DOES NOT MATCH ...}T SPRECIFICATION: " ERROR + ELSE FDEPTH START-FDEPTH @ = 0= IF + S" NUMBER OF FLOAT RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR + THEN THEN ; + : FTESTER ( R -- ) - FDEPTH 0= ACTUAL-FDEPTH @ FCURSOR @ 1+ < OR IF - S" WRONG NUMBER OF FP RESULTS: " ERROR EXIT - THEN - ACTUAL-FRESULTS FCURSOR @ FLOATS + F@ FCONF= 0= IF + FDEPTH 0= ACTUAL-FDEPTH @ FCURSOR @ START-FDEPTH @ + 1+ < OR IF + S" NUMBER OF FLOAT RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR + ELSE ACTUAL-FRESULTS FCURSOR @ FLOATS + F@ FCONF= 0= IF S" INCORRECT FP RESULT: " ERROR - THEN + THEN THEN 1 FCURSOR +! ; [ELSE] @@ -224,12 +221,11 @@ HAS-FLOATING-STACK [IF] COMPUTE-CELLS-PER-FP CONSTANT CELLS-PER-FP : FTESTER ( R -- ) - DEPTH CELLS-PER-FP < ACTUAL-DEPTH @ XCURSOR @ CELLS-PER-FP + < OR IF - S" WRONG NUMBER OF RESULTS: " ERROR EXIT - THEN - ACTUAL-RESULTS XCURSOR @ CELLS + F@ FCONF= 0= IF + DEPTH CELLS-PER-FP < ACTUAL-DEPTH @ XCURSOR @ START-DEPTH @ + CELLS-PER-FP + < OR IF + S" NUMBER OF RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT + ELSE ACTUAL-RESULTS XCURSOR @ CELLS + F@ FCONF= 0= IF S" INCORRECT FP RESULT: " ERROR - THEN + THEN THEN CELLS-PER-FP XCURSOR +! ; [THEN] @@ -256,7 +252,7 @@ HAS-FLOATING-STACK [IF] : -> \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK. DEPTH DUP ACTUAL-DEPTH ! \ RECORD DEPTH 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 F-> ; @@ -264,7 +260,7 @@ HAS-FLOATING-STACK [IF] \ (ACTUAL) CONTENTS. DEPTH ACTUAL-DEPTH @ = IF \ IF DEPTHS MATCH 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 <> IF S" INCORRECT RESULT: " ERROR LEAVE THEN LOOP @@ -275,21 +271,19 @@ HAS-FLOATING-STACK [IF] F} ; : ...}T ( -- ) - DEPTH START-DEPTH @ = 0= IF - S" WRONG NUMBER OF RESULTS" ERROR - THEN - XCURSOR @ ACTUAL-DEPTH @ <> IF - S" WRONG NUMBER OF RESULTS" ERROR - THEN + XCURSOR @ START-DEPTH @ + ACTUAL-DEPTH @ <> IF + S" NUMBER OF CELL RESULTS BEFORE '->' DOES NOT MATCH ...}T SPECIFICATION: " ERROR + ELSE DEPTH START-DEPTH @ = 0= IF + S" NUMBER OF CELL RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR + THEN THEN F...}T ; : XTESTER ( X -- ) - DEPTH 0= ACTUAL-DEPTH @ XCURSOR @ 1+ < OR IF - S" WRONG NUMBER OF RESULTS: " ERROR EXIT - THEN - ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF + DEPTH 0= ACTUAL-DEPTH @ XCURSOR @ START-DEPTH @ + 1+ < OR IF + S" NUMBER OF CELL RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT + ELSE ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF S" INCORRECT CELL RESULT: " ERROR - THEN + THEN THEN 1 XCURSOR +! ; : X}T XTESTER ...}T ; @@ -329,4 +323,4 @@ HAS-FLOATING-STACK [IF] ELSE >IN ! DROP THEN ; -BASE ! \ No newline at end of file +BASE !