Post Reply 
FORTH for the SHARP PC-E500 (S)
11-13-2021, 12:07 PM
Post: #55
RE: FORTH for the SHARP PC-E500 (S)
Test Suite & Date calculation
I was curious whether the test suite works with Forth500. (https://forth-standard.org/standard/testsuite)
And the answer is yes, absolutely no problem. The zip archive attached below contains the file TTESTER.FTH. It starts with the lines
Code:
    \ TTESTER.FTH
    .( Loading TTESTER... )
    ANEW _TTESTER_
so that after INCLUDE COM: a message appears in the display and you can later delete the test suite from the dictionary with FORGET _TTESTER_ . This is followed by the source code of the test suite (with fewer comment blocks) and three examples at the end of TTESTER.FTH:
Code:
    T{ 1 2 3 swap -> 1 3 2 }T
    T{ 1 2 3 swap -> 1 2 2 }T
    T{ 1 2 3 swap -> 1 2 }T
The two reported errors indicate the successful completion of loading.

The first time I saw lines with T{ }T when calculating dates in Forth on this page:
https://forth-ev.de/wiki/examples:daymonthyear
But this page shows an example for Gforth and in Gforth a cell has 32 bits. For the Forth500 with its 16 bits per cell, double values ​​and double functions must therefore be used in many places. Thanks to the test suite and the many test cases, I was able to check the conversion to double. The result is the DATE.FTH file in the attached zip archive. At the end of DATE.FTH there are two examples:
Code:
    2021 12 25 ymd2day 2dup day2dow weekday CR
    2021 11 13 ymd2day D- D.
The display shows after successful loading:
Saturday
42
The first day of Christmas is a Saturday and there are still 42 days until then.

The file DATETEST.FTH contains the many test cases. If you load TTESTER.FTH and DATE.FTH beforehand (regardless of the order) then the test cases will be executed with INCLUDE COM: when DATETEST.FTH is loaded. Loading takes 100 seconds and immediately afterwards "passed successful" appears on the display. The test cases are therefore executed during loading!

The function (ymd2day) on the website is not entirely correct. The error-free version is shown on page 16 of this pdf
https://forth-ev.de/wiki/res/lib/exe/fet...018-04.pdf
(ymd2day) contains an additional 1+ at the end. That the day2dow function contains a 1+ instead of a 2+ is more a matter of taste.

It would be interesting to know whether the code coverage as described in this article for Gforth can also be determined with Forth500. But this requires a number of very special functions that are not part of the standard, such as current-sourceview...


Attached File(s)
.zip  Test Suite & Date calculation.zip (Size: 4.67 KB / Downloads: 3)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
FORTH for the SHARP PC-E500 (S) - Helix - 09-06-2021, 11:41 PM
RE: FORTH for the SHARP PC-E500 (S) - Klaus Overhage - 11-13-2021 12:07 PM



User(s) browsing this thread: 1 Guest(s)