# Testing¶

For quite some time it is a good practice to write test cases for software for and during the development. With them a developer can be sure that the words do what they are supposed to do. Forth has a long tradition in this area starting with the ANSI standard from 1994. John Hayes wrote a tester and defined a test case synatx which got into widespead use since then.

Amforth has adapted its code with the file lib/ans94/tester-amforth.frt. The changes from the original are rather minor: Turn all keywords into lowercase.

## Prepare for Tests¶

The tester requires only marker which is defined in file:lib/ans94/core/marker.frt. There are no further dependencies.

## Using Test Cases¶

The tester uses 4 words:

is a “talking comment” to make the output somehow look nice.
t{
starts a new test. Prepare the stack and call your function, then
->
indicates that the test code is complete. Add the remaining stack after this word.
}t
completes the test by comparing the stack with the expected stack. If everything is well, the ok prompt will appear.

A test summary is not printed, but that could

Write a file with your new library function, e.g.

\ function.frt
\ define some new function
: plus  + ;


Then write the test cases, e.g.

\ function-test.frt

\ load the tester from lib/ans94/tester
#include tester-amforth.frt

\ load the code under test
#include function.frt

\ run the tests
TESTING the tester -----------------------------------------

t{ 1 1 +    -> 2 }t
t{ 1 1 plus -> 2 }t
t{ 1 1 plus -> 3 }t \ incorrect
t{ 1 2 plus -> 3 }t \ tester contiues
t{ $FFFF 1 plus -> 0 }t t{ 1 2 3 4 plus -> 1 2 7 }t  Now load the file function-test.frt to the controller and watch the show. TESTING the tester ----------------------------------------- ok > t{ 1 1 + -> 2 }t ok > t{ 1 1 plus -> 2 }t ok > t{ 1 1 plus -> 3 }t INCORRECT RESULT: t{ 1 1 plus -> 3 }t ok > t{ 1 2 plus -> 3 }t ok > t{$FFFF 1 plus -> 0 }t
ok


With the command -ans-tester everythings gets unloaded and is ready for the next run.

## Acknowlegment¶

This recipe is based upon an email from Erich Wälde on the amforth-devel mailing list.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.3346560299396515, "perplexity": 4836.53754366377}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-09/segments/1487501171281.53/warc/CC-MAIN-20170219104611-00469-ip-10-171-10-108.ec2.internal.warc.gz"}