[3] urlhttp://www.taygeta.com/forth.html
[4] http://soton.mpeforth.com/flag/anstests/index.html
T{
" (T-open brace) followed by a code sequence to test.
This is followed by "->
", the expected results, and
"}T
" (close brace-T). For example, the following:
T{
" records the stack depth prior to the test code
so that they can be eliminated from the test.
The "->
" records the stack depth and moves the entire stack
contents to an array. In the example test, the recorded stack depth
is one and the saved array contains one value, two.
The "}T
" compares the current stack depth to the saved
stack depth. If they are equal each value on the stack is removed
from the stack and compared to its corresponding value in the array.
If the depths are not equal or if the stack comparison fails, an error
is reported. For example:
T{ 1 2 3 SWAP -> 1 3 2 }T INCORRECT RESULT:
T{ 1 2 3 SWAP -> 1 2 3 }T WRONG NUMBER OF RESULTS:
T{ 1 2 SWAP -> 1 }T HAS-FLOATING
and
HAS-FLOATING-STACK
contain the results of its efforts, so
the behavior of the code can be modified by the user if necessary.
Then there are the perennial issues of floating point value
comparisons. Exact equality is specified by SET-EXACT
(the default). If approximate equality tests are desired, execute
SET-NEAR
. Then the
FVARIABLEs REL-NEAR
(default 1E-12) and
ABS-NEAR
(default 0E) contain the values to be used in
comparisons by the (internal) word FNEARLY=
.
When there is not a separate floating point stack, and you want to use
approximate equality for FP values, it is necessary to identify which
stack items are floating point quantities. This can be done by
replacing the closing }T
with a version that specifies
this, such as RRXR}T
which identifies the stack picture
(r r x r). The harness provides such words for all
combinations of R and X with up to four stack items. They can be
used with either an integrated or a separate floating point stacks.
Adding more if you need them is straightforward; see the examples in
the source. Here is an example which also illustrates controlling
the precision of comparisons:
ERROR
is vectored, through the
ERROR-XT
variable, so that its action can be changed by
the user (for example, to add a counter for the number of errors).
The default action ERROR1
can be used as a factor in the
display of error reports.
( Start with a clean slate )
( Test if any bits are set; Answer in base 1 )
( Zero is all bits clear )
( Other numbers have at least one bit )
0S
and 1S
) which will be used in the
further test.
It is now possible to complete the testing of
F.6.1.0720 AND,
F.6.1.1980 OR, and
F.6.1.2490 XOR.
MSB
must have at least one bit set:
IFSYM
will ignore the rest of the line when it is performed
on a system with floored division and perform the line on a system
with symmetric division. IFFLOORED
is the direct inverse,
ignoring the rest of the line on systems with symmetric division and
processing it on systems with floored division.
The remaining division operators are tested by defining a version of
the operator using words which have already been tested (S>D,
M*, FM/MOD and SM/REM). The test definition
handles the special case of differing signes. As the test definitions
use the words which have just been tested, the tests must be performed
in the order:
F.6.1.0240 /MOD,
F.6.1.0230 /,
F.6.1.1890 MOD,
F.6.1.0100 */, and
F.6.1.0110 */MOD.
FBUF
is changed by the
F.6.1.1540 FILL test, this must be executed before the
F.6.1.1900 MOVE test.
\ First defintion
\ Second defintion
: GP4 <# 1 0 #S #> S" 1" S= ;
"
ABORT "
;
T{ s$ EVALUATE si_inc @ -> 0 2345 15 }T
Testing nesting "
$$UndefedWord$$
is undefined.
t10
is necessary for the second
ABORT" test as the data stack is restored to a
depth of 2 when THROW is executed. The 77 ensures
the top of stack value is known for the results check.
: t10 77 SWAP ABORT" This should not be displayed" ; fatest1.txt
", "fatest2.txt
" and
"fatest3.txt
".
The test F.11.6.1.1010 CREATE-FILE also tests CLOSE-FILE,
F.11.6.1.2485 WRITE-LINE also tests W/O and OPEN-FILE,
F.11.6.1.2090 READ-LINE includes a test for R/O,
F.11.6.1.2142 REPOSITION-FILE includes tests for R/W,
WRITE-FILE, READ-FILE,
FILE-POSITION, and S".
The F.11.6.1.1522 FILE-SIZE test includes a test for BIN.
The test F.11.6.1.2147 RESIZE-FILE should then be run followed by
the F.11.6.1.1190 DELETE-FILE test.
The F.11.6.1.0080 ( test should be next, followed by
F.11.6.1.2218 SOURCE-ID the test which test the extended versions of
( and SOURCE-ID respectively.
Finally F.11.6.2.2130 RENAME-FILE tests the extended words
RENAME-FILE, FILE-STATUS, and FLUSH-FILE.
setpad
must be called again as the pad may move
T{ fn2 R/W BIN CREATE-FILE SWAP fid2 ! -> 0 }T setpad
required-helper1.fs
and
required-helper2.fs
.
Both of which hold the text:
As for the test themselves:
T{ 0 EXACT?
is TRUE.
Uncomment the following line if your system needs it to
be FALSE atan2()
": SET-EXACT
T{ -0E FTRUNC F0= -> <TRUE> }T get-orderlist
defined to access it.
hi
and wld
substitutions %hi%
" with "hello
" %wld%
" with "world
"
\ "%hi%,%wld%
" changed to "hello,world
" hi
and wld
substitutions %hi%,%wld%
" should be changed to "world,hello
" %
character itself subbuff
, sub5
and sub6
from F.17.6.2.2255 SUBSTITUTE.
T{ sub6 subbuff UNESCAPE sub5 COMPARE -> 0 }T