diff options
author | elioat <{ID}+{username}@users.noreply.github.com> | 2025-01-02 09:19:14 -0500 |
---|---|---|
committer | elioat <{ID}+{username}@users.noreply.github.com> | 2025-01-02 09:19:14 -0500 |
commit | fbb6bb910bd7d8bddb52c06cfe72b97d44bb2813 (patch) | |
tree | 24c566bad1c6a0c4c6b095fce1e76cb8a9720f15 /awk/forth/test.forth | |
parent | 2c154a34f478285680efeee7c15ba02116ee882d (diff) | |
download | tour-fbb6bb910bd7d8bddb52c06cfe72b97d44bb2813.tar.gz |
*
Diffstat (limited to 'awk/forth/test.forth')
-rw-r--r-- | awk/forth/test.forth | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/awk/forth/test.forth b/awk/forth/test.forth index 2d4197b..d746e66 100644 --- a/awk/forth/test.forth +++ b/awk/forth/test.forth @@ -1,84 +1,84 @@ ( Basic Forth test suite ) -testing Basic stack operations +testing "Basic stack operations" 5 dup . . test 5 test 5 -testing Addition +testing "Addition" 3 4 + test 7 -testing Subtraction +testing "Subtraction" 10 3 - test 7 -testing Multiplication +testing "Multiplication" 6 7 * test 42 -testing Division +testing "Division" 20 4 / test 5 -testing Stack manipulation - rot +testing "Stack manipulation - rot" 1 2 3 rot test 1 -testing Stack manipulation - drop +testing "Stack manipulation - drop" 1 2 3 drop test 2 -testing Stack manipulation - nip +testing "Stack manipulation - nip" 1 2 3 nip test 3 -testing Stack manipulation - tuck +testing "Stack manipulation - tuck" 1 2 tuck test 2 -testing Stack manipulation - over +testing "Stack manipulation - over" 1 2 over test 1 -testing Variables +testing "Variables" variable x 5 x ! x @ test 5 10 x ! x ? ( should print 10 ) -testing Negate +testing "Negate" 5 negate test -5 -testing Absolute value +testing "Absolute value" -7 abs test 7 -testing Maximum +testing "Maximum" 3 8 max test 8 -testing Minimum +testing "Minimum" 3 8 min test 3 -testing Modulo +testing "Modulo" 17 5 mod test 2 -testing Equality +testing "Equality" 5 5 = test 1 5 6 = test 0 -testing Word definition +testing "Word definition" : square dup * ; 5 square test 25 -testing Complex word definition +testing "Complex word definition" variable counter : increment-counter counter @ 1 + counter ! ; 5 counter ! increment-counter counter @ test 6 -testing Basic conditional - if/then +testing "Basic conditional - if/then" : test-if-1 ( n -- n ) dup 5 > if ." Greater than 5" then ; 6 test-if-1 test 6 ( should print "Greater than 5" and leave 6 ) 4 test-if-1 test 4 ( should print nothing and leave 4 ) -testing Basic conditional - if/else/then +testing "Basic conditional - if/else/then" : test-if-2 ( n -- n ) dup 5 > if ." Greater" else ." Less=" then ; 6 test-if-2 test 6 ( should print "Greater" and leave 6 ) 4 test-if-2 test 4 ( should print "Less=" and leave 4 ) 5 test-if-2 test 5 ( should print "Less=" and leave 5 ) -testing Nested conditionals +testing "Nested conditionals" : test-if-3 ( n -- n ) dup 10 > if dup 20 > if @@ -90,7 +90,7 @@ testing Nested conditionals 15 test-if-3 test 15 ( should print ">10 " and leave 15 ) 5 test-if-3 test 5 ( should print nothing and leave 5 ) -testing Conditional with stack operations +testing "Conditional with stack operations" : test-if-4 ( n -- n n ) dup 5 > if dup @@ -98,7 +98,7 @@ testing Conditional with stack operations 6 test-if-4 swap test 6 test 6 ( should leave 6 6 ) 4 test-if-4 test 4 ( should leave just 4 ) -testing Complex nested conditionals +testing "Complex nested conditionals" : test-if-5 ( n -- n ) dup 0 < if ." negative " @@ -118,12 +118,12 @@ testing Complex nested conditionals 75 test-if-5 test 75 ( should print "medium " ) 25 test-if-5 test 25 ( should print "small " ) -testing Conditionals in word definitions +testing "Conditionals in word definitions" : abs-test ( n -- |n| ) dup 0 < if negate then ; -5 abs-test test 5 5 abs-test test 5 -testing Complex conditional word +testing "Complex conditional word" : max-test ( n1 n2 -- max ) 2dup > if drop @@ -134,10 +134,10 @@ testing Complex conditional word 3 5 max-test test 5 ( Try to use if outside of a definition - should error ) -testing Compile-only words +testing "Compile-only words" 5 4 > if 42 then ( should print error about compile-only word ) -testing Comparison operators +testing "Comparison operators" 5 3 > test 1 ( 5 > 3 is true ) 3 5 > test 0 ( 3 > 5 is false ) 3 5 < test 1 ( 3 < 5 is true ) @@ -145,7 +145,7 @@ testing Comparison operators 5 5 < test 0 ( 5 < 5 is false ) 5 5 > test 0 ( 5 > 5 is false ) -testing Comparison in conditionals +testing "Comparison in conditionals" : test-compare ( n -- ) dup 5 > if ." Greater than 5" else dup 5 < if ." Less than 5" else |