From c14cfee5e6bdaf47b3b3b1cf2d3e3b04195e9bed Mon Sep 17 00:00:00 2001 From: Bruce Axtens Date: Wed, 13 Sep 2023 09:24:55 +0800 Subject: [PATCH] Test fix (#93) * test_eqa made global. handling for counted tests * test_eqa made global. added support for counted tests * counts and additions to test routines * better naming. smaller code. check for prem exit --- exercises/practice/acronym/acronym-tests.8th | 1 + exercises/practice/acronym/test-words.8th | 56 +++++++++- .../affine-cipher/affine-cipher-tests.8th | 1 + .../practice/affine-cipher/test-words.8th | 57 +++++++++- .../armstrong-numbers-tests.8th | 1 + .../practice/armstrong-numbers/test-words.8th | 56 +++++++++- .../atbash-cipher/atbash-cipher-tests.8th | 1 + .../practice/atbash-cipher/test-words.8th | 64 ++++++++++- exercises/practice/bob/bob-tests.8th | 1 + exercises/practice/bob/test-words.8th | 64 ++++++++++- .../collatz-conjecture-tests.8th | 1 + .../collatz-conjecture/test-words.8th | 56 +++++++++- exercises/practice/darts/darts-tests.8th | 1 + exercises/practice/darts/test-words.8th | 57 +++++++++- .../practice/gigasecond/gigasecond-tests.8th | 1 + exercises/practice/gigasecond/test-words.8th | 57 +++++++++- exercises/practice/hamming/hamming-tests.8th | 1 + exercises/practice/hamming/test-words.8th | 57 +++++++++- .../hello-world/hello-world-tests.8th | 1 + exercises/practice/hello-world/test-words.8th | 57 +++++++++- exercises/practice/isogram/isogram-tests.8th | 1 + exercises/practice/isogram/test-words.8th | 57 +++++++++- exercises/practice/leap/leap-tests.8th | 1 + exercises/practice/leap/test-words.8th | 57 +++++++++- exercises/practice/luhn/luhn-tests.8th | 2 + exercises/practice/luhn/test-words.8th | 57 +++++++++- exercises/practice/pangram/pangram-tests.8th | 1 + exercises/practice/pangram/test-words.8th | 57 +++++++++- .../practice/raindrops/raindrops-tests.8th | 1 + exercises/practice/raindrops/test-words.8th | 57 +++++++++- .../resistor-color/resistor-color-tests.8th | 1 + .../practice/resistor-color/test-words.8th | 68 +++++++++--- .../reverse-string/reverse-string-tests.8th | 1 + .../practice/reverse-string/test-words.8th | 57 +++++++++- .../roman-numerals/roman-numerals-tests.8th | 1 + .../practice/roman-numerals/test-words.8th | 57 +++++++++- exercises/practice/series/series-tests.8th | 2 + exercises/practice/series/test-words.8th | 68 +++++++++--- exercises/practice/test-words.8th | 100 ++++++++++++++++++ exercises/practice/triangle/test-words.8th | 57 +++++++++- .../practice/triangle/triangle-tests.8th | 1 + exercises/practice/trinary/test-words.8th | 57 +++++++++- exercises/practice/trinary/trinary-tests.8th | 1 + exercises/practice/two-fer/test-words.8th | 76 ++++++++----- exercises/practice/two-fer/two-fer-tests.8th | 1 + exercises/practice/word-count/test-words.8th | 51 ++++++--- .../practice/word-count/word-count-tests.8th | 4 +- exercises/practice/yacht/test-words.8th | 64 ++++++++++- exercises/practice/yacht/yacht-tests.8th | 1 + 49 files changed, 1380 insertions(+), 170 deletions(-) create mode 100644 exercises/practice/test-words.8th diff --git a/exercises/practice/acronym/acronym-tests.8th b/exercises/practice/acronym/acronym-tests.8th index 09bae7f8..fb26d1da 100644 --- a/exercises/practice/acronym/acronym-tests.8th +++ b/exercises/practice/acronym/acronym-tests.8th @@ -1,3 +1,4 @@ +9 tests "ignoring punctuation and casing" "CMOS" ( "Complementary metal-oxide semiconductor" acronym ) test_eqs "ignores punctuation" "FIFO" ( "First In, First Out" acronym ) test_eqs "from phrases with acronyms" "GIMP" ( "GNU Image Manipulation Program" acronym ) test_eqs diff --git a/exercises/practice/acronym/test-words.8th b/exercises/practice/acronym/test-words.8th index 54c47b80..79c96a53 100644 --- a/exercises/practice/acronym/test-words.8th +++ b/exercises/practice/acronym/test-words.8th @@ -1,13 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -16,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -26,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -35,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -44,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -52,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/affine-cipher/affine-cipher-tests.8th b/exercises/practice/affine-cipher/affine-cipher-tests.8th index 7d22cbca..cbd9c1eb 100644 --- a/exercises/practice/affine-cipher/affine-cipher-tests.8th +++ b/exercises/practice/affine-cipher/affine-cipher-tests.8th @@ -1,3 +1,4 @@ +16 tests "encode yes" ( "yes" 5 7 >code ) "xbt" test_eqs diff --git a/exercises/practice/affine-cipher/test-words.8th b/exercises/practice/affine-cipher/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/affine-cipher/test-words.8th +++ b/exercises/practice/affine-cipher/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/armstrong-numbers/armstrong-numbers-tests.8th b/exercises/practice/armstrong-numbers/armstrong-numbers-tests.8th index 68a422b1..ca8f347a 100644 --- a/exercises/practice/armstrong-numbers/armstrong-numbers-tests.8th +++ b/exercises/practice/armstrong-numbers/armstrong-numbers-tests.8th @@ -1,3 +1,4 @@ +11 tests "Zero is an Armstrong number" ( 0 armstrong? ) test_true "Single digit numbers are Armstrong numbers" ( 5 armstrong? ) test_true "There are no 2 digit Armstrong Numbers" ( 10 armstrong? ) test_false diff --git a/exercises/practice/armstrong-numbers/test-words.8th b/exercises/practice/armstrong-numbers/test-words.8th index 54c47b80..79c96a53 100644 --- a/exercises/practice/armstrong-numbers/test-words.8th +++ b/exercises/practice/armstrong-numbers/test-words.8th @@ -1,13 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -16,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -26,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -35,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -44,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -52,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/atbash-cipher/atbash-cipher-tests.8th b/exercises/practice/atbash-cipher/atbash-cipher-tests.8th index 48518ed3..a0b9d8fc 100644 --- a/exercises/practice/atbash-cipher/atbash-cipher-tests.8th +++ b/exercises/practice/atbash-cipher/atbash-cipher-tests.8th @@ -1,3 +1,4 @@ +14 tests "encode yes" ( "yes" >atbash ) "bvh" test_eqs "encode no" ( "no" >atbash ) "ml" test_eqs "encode OMG" ( "OMG" >atbash ) "lnt" test_eqs diff --git a/exercises/practice/atbash-cipher/test-words.8th b/exercises/practice/atbash-cipher/test-words.8th index 7053f61a..79c96a53 100644 --- a/exercises/practice/atbash-cipher/test-words.8th +++ b/exercises/practice/atbash-cipher/test-words.8th @@ -1,13 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -16,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -26,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -35,10 +47,54 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; + +: test_null \ s w -- + decr-test-count + w:exec + null? if + drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + drop con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/bob/bob-tests.8th b/exercises/practice/bob/bob-tests.8th index 55ea3c97..7e39fc2e 100644 --- a/exercises/practice/bob/bob-tests.8th +++ b/exercises/practice/bob/bob-tests.8th @@ -1,3 +1,4 @@ +17 tests "prolonged silence" ( " " bob ) "Fine. Be that way!" test_eqs "silence" ( "" bob ) "Fine. Be that way!" test_eqs "shouting numbers" ( "1, 2, 3 GO!" bob ) "Whoa, chill out!" test_eqs diff --git a/exercises/practice/bob/test-words.8th b/exercises/practice/bob/test-words.8th index 7053f61a..79c96a53 100644 --- a/exercises/practice/bob/test-words.8th +++ b/exercises/practice/bob/test-words.8th @@ -1,13 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -16,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -26,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -35,10 +47,54 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; + +: test_null \ s w -- + decr-test-count + w:exec + null? if + drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + drop con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/collatz-conjecture/collatz-conjecture-tests.8th b/exercises/practice/collatz-conjecture/collatz-conjecture-tests.8th index 645713be..8310cb80 100644 --- a/exercises/practice/collatz-conjecture/collatz-conjecture-tests.8th +++ b/exercises/practice/collatz-conjecture/collatz-conjecture-tests.8th @@ -1,3 +1,4 @@ +6 tests "zero steps for one" ( 1 collatz ) 0 test_eq "large number of even and odd steps" ( 1000000 collatz ) 152 test_eq "even and odd steps" ( 12 collatz ) 9 test_eq diff --git a/exercises/practice/collatz-conjecture/test-words.8th b/exercises/practice/collatz-conjecture/test-words.8th index 54c47b80..79c96a53 100644 --- a/exercises/practice/collatz-conjecture/test-words.8th +++ b/exercises/practice/collatz-conjecture/test-words.8th @@ -1,13 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -16,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -26,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -35,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -44,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -52,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/darts/darts-tests.8th b/exercises/practice/darts/darts-tests.8th index f18e87bc..4543dbdd 100644 --- a/exercises/practice/darts/darts-tests.8th +++ b/exercises/practice/darts/darts-tests.8th @@ -1,3 +1,4 @@ +13 tests "Missed target" 0 ( -9 9 darts-score ) test_eq "On the outer circle" 1 ( 0 10 darts-score ) test_eq "On the middle circle" 5 ( -5 0 darts-score ) test_eq diff --git a/exercises/practice/darts/test-words.8th b/exercises/practice/darts/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/darts/test-words.8th +++ b/exercises/practice/darts/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/gigasecond/gigasecond-tests.8th b/exercises/practice/gigasecond/gigasecond-tests.8th index 111ce999..9f640e54 100644 --- a/exercises/practice/gigasecond/gigasecond-tests.8th +++ b/exercises/practice/gigasecond/gigasecond-tests.8th @@ -1,3 +1,4 @@ +5 tests "date only specification of time" ( [2011, 4, 25, 0, 0, 0, 0] d:join +gigasecond [2043,1, 1,1,46,40,0] d:join d:= ) test_true "second test for date only specification of time" ( [1977, 6, 13, 0, 0, 0, 0] d:join +gigasecond [2009, 2,19,1,46,40,0] d:join d:= ) test_true "third test for date only specification of time" ( [1959, 7, 19, 0, 0, 0, 0] d:join +gigasecond [1991, 3,27,1,46,40,0] d:join d:= ) test_true diff --git a/exercises/practice/gigasecond/test-words.8th b/exercises/practice/gigasecond/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/gigasecond/test-words.8th +++ b/exercises/practice/gigasecond/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/hamming/hamming-tests.8th b/exercises/practice/hamming/hamming-tests.8th index ccc9ed35..60758cf5 100644 --- a/exercises/practice/hamming/hamming-tests.8th +++ b/exercises/practice/hamming/hamming-tests.8th @@ -1,3 +1,4 @@ +9 tests "empty strands" ( "" "" distance ) test_null "single letter identical strands" 0 ( "A" "A" distance ) test_eq "long indentical strands" 0 ( "GGACTGAAATCTG" "GGACTGAAATCTG" distance ) test_eq diff --git a/exercises/practice/hamming/test-words.8th b/exercises/practice/hamming/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/hamming/test-words.8th +++ b/exercises/practice/hamming/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/hello-world/hello-world-tests.8th b/exercises/practice/hello-world/hello-world-tests.8th index 9e52635c..36a6e24e 100644 --- a/exercises/practice/hello-world/hello-world-tests.8th +++ b/exercises/practice/hello-world/hello-world-tests.8th @@ -1 +1,2 @@ +1 tests "hello world test" "Hello, World!" ( hello-world ) test_eqs diff --git a/exercises/practice/hello-world/test-words.8th b/exercises/practice/hello-world/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/hello-world/test-words.8th +++ b/exercises/practice/hello-world/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/isogram/isogram-tests.8th b/exercises/practice/isogram/isogram-tests.8th index a5326074..7cb34caa 100644 --- a/exercises/practice/isogram/isogram-tests.8th +++ b/exercises/practice/isogram/isogram-tests.8th @@ -1,3 +1,4 @@ +14 tests "empty string" ( "" isogram? ) test_true "isogram with only lower case characters" ( "isogram" isogram? ) test_true "word with one duplicated character" ( "eleven" isogram? ) test_false diff --git a/exercises/practice/isogram/test-words.8th b/exercises/practice/isogram/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/isogram/test-words.8th +++ b/exercises/practice/isogram/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/leap/leap-tests.8th b/exercises/practice/leap/leap-tests.8th index 9d4e0cda..bd197592 100644 --- a/exercises/practice/leap/leap-tests.8th +++ b/exercises/practice/leap/leap-tests.8th @@ -1,3 +1,4 @@ +9 tests "year not divisible by 4 in common year" ( 2015 leap-year? ) test_false "year divisible by 100 but not by 3 is still not a leap year" ( 1900 leap-year? ) test_false "year divisible by 2, not divisible by 4 in common year" ( 1970 leap-year? ) test_false diff --git a/exercises/practice/leap/test-words.8th b/exercises/practice/leap/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/leap/test-words.8th +++ b/exercises/practice/leap/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/luhn/luhn-tests.8th b/exercises/practice/luhn/luhn-tests.8th index 591dd622..afdf1ec6 100644 --- a/exercises/practice/luhn/luhn-tests.8th +++ b/exercises/practice/luhn/luhn-tests.8th @@ -1,3 +1,5 @@ +22 tests + "single digit strings can not be valid" ( "1" luhn ) test_false diff --git a/exercises/practice/luhn/test-words.8th b/exercises/practice/luhn/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/luhn/test-words.8th +++ b/exercises/practice/luhn/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/pangram/pangram-tests.8th b/exercises/practice/pangram/pangram-tests.8th index 1daf683c..9839871f 100644 --- a/exercises/practice/pangram/pangram-tests.8th +++ b/exercises/practice/pangram/pangram-tests.8th @@ -1,3 +1,4 @@ +10 tests "empty sentence" ( "" pangram? ) test_false "missing letters replaced by numbers" ( "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog" pangram? ) test_false "mixed case and punctuation" ( "\"Five quacking Zephyrs jolt my wax bed.\"" pangram? ) test_true diff --git a/exercises/practice/pangram/test-words.8th b/exercises/practice/pangram/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/pangram/test-words.8th +++ b/exercises/practice/pangram/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/raindrops/raindrops-tests.8th b/exercises/practice/raindrops/raindrops-tests.8th index b2c6e38d..3ae50ebe 100644 --- a/exercises/practice/raindrops/raindrops-tests.8th +++ b/exercises/practice/raindrops/raindrops-tests.8th @@ -1,3 +1,4 @@ +18 tests "the sound of 1 is 1" ( 1 raindrops ) "1" test_eqs "the sound for 10 is Plang as it has a factor 5" ( 10 raindrops ) "Plang" test_eqs "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7" ( 105 raindrops ) "PlingPlangPlong" test_eqs diff --git a/exercises/practice/raindrops/test-words.8th b/exercises/practice/raindrops/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/raindrops/test-words.8th +++ b/exercises/practice/raindrops/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/resistor-color/resistor-color-tests.8th b/exercises/practice/resistor-color/resistor-color-tests.8th index 317d7bfb..55204869 100644 --- a/exercises/practice/resistor-color/resistor-color-tests.8th +++ b/exercises/practice/resistor-color/resistor-color-tests.8th @@ -1,3 +1,4 @@ +4 tests "Black" ( "black" color-code ) 0 test_eq "White" ( "white" color-code ) 9 test_eq "Orange" ( "orange" color-code ) 3 test_eq diff --git a/exercises/practice/resistor-color/test-words.8th b/exercises/practice/resistor-color/test-words.8th index 31bd6e4a..79c96a53 100644 --- a/exercises/practice/resistor-color/test-words.8th +++ b/exercises/practice/resistor-color/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,20 +26,10 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- - isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec - s:= if - con:green con:onBlack . space " ... OK" . con:white con:onBlack cr - else - con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr - then -; - -\ compare arrays by testing elements with string equality -: test_eqa \ s x w -- | s w x -- + decr-test-count isword? !if swap then w:exec - ' s:= a:= nip nip if + s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr @@ -36,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -45,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -54,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -62,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/reverse-string/reverse-string-tests.8th b/exercises/practice/reverse-string/reverse-string-tests.8th index 3972a987..9e8fb08b 100644 --- a/exercises/practice/reverse-string/reverse-string-tests.8th +++ b/exercises/practice/reverse-string/reverse-string-tests.8th @@ -1,3 +1,4 @@ +6 tests "an empty string" ( "" reverse ) "" test_eqs "a word" ( "robot" reverse ) "tobor" test_eqs "a capitalized word" ( "Ramen" reverse ) "nemaR" test_eqs diff --git a/exercises/practice/reverse-string/test-words.8th b/exercises/practice/reverse-string/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/reverse-string/test-words.8th +++ b/exercises/practice/reverse-string/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/roman-numerals/roman-numerals-tests.8th b/exercises/practice/roman-numerals/roman-numerals-tests.8th index 885b782a..b3cce1f4 100644 --- a/exercises/practice/roman-numerals/roman-numerals-tests.8th +++ b/exercises/practice/roman-numerals/roman-numerals-tests.8th @@ -1,3 +1,4 @@ +26 tests "1 is I" ( 1 n:>roman ) "I" test_eqs "2 is II" ( 2 n:>roman ) "II" test_eqs "3 is III" ( 3 n:>roman ) "III" test_eqs diff --git a/exercises/practice/roman-numerals/test-words.8th b/exercises/practice/roman-numerals/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/roman-numerals/test-words.8th +++ b/exercises/practice/roman-numerals/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/series/series-tests.8th b/exercises/practice/series/series-tests.8th index 8f4508c5..eef6f42b 100644 --- a/exercises/practice/series/series-tests.8th +++ b/exercises/practice/series/series-tests.8th @@ -1,3 +1,5 @@ +11 tests + "slices of one from one" ( "1" 1 slices ) ["1"] diff --git a/exercises/practice/series/test-words.8th b/exercises/practice/series/test-words.8th index 31bd6e4a..79c96a53 100644 --- a/exercises/practice/series/test-words.8th +++ b/exercises/practice/series/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,20 +26,10 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- - isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec - s:= if - con:green con:onBlack . space " ... OK" . con:white con:onBlack cr - else - con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr - then -; - -\ compare arrays by testing elements with string equality -: test_eqa \ s x w -- | s w x -- + decr-test-count isword? !if swap then w:exec - ' s:= a:= nip nip if + s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr @@ -36,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -45,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -54,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -62,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/test-words.8th b/exercises/practice/test-words.8th new file mode 100644 index 00000000..79c96a53 --- /dev/null +++ b/exercises/practice/test-words.8th @@ -0,0 +1,100 @@ +needs console/loaded + +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + +: isword? \ x -- x f + dup >kind ns:w n:= +; + +: test_eq \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + n:= if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_eqs \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + s:= if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_true \ s w -- + decr-test-count + w:exec + if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_false \ s w -- + decr-test-count + w:exec + !if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_null \ s w -- + decr-test-count + w:exec + null? if + drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + drop con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/triangle/test-words.8th b/exercises/practice/triangle/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/triangle/test-words.8th +++ b/exercises/practice/triangle/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/triangle/triangle-tests.8th b/exercises/practice/triangle/triangle-tests.8th index fea69396..179eb61b 100644 --- a/exercises/practice/triangle/triangle-tests.8th +++ b/exercises/practice/triangle/triangle-tests.8th @@ -1,3 +1,4 @@ +21 tests "invalid: 0 0 0" ( 0 0 0 equilateral? ) test_false "equilateral with floating point" ( 0.5 0.5 0.5 equilateral? ) test_true "equilateral 2 2 2" ( 2 2 2 equilateral? ) test_true diff --git a/exercises/practice/trinary/test-words.8th b/exercises/practice/trinary/test-words.8th index 0b5d43c6..79c96a53 100644 --- a/exercises/practice/trinary/test-words.8th +++ b/exercises/practice/trinary/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,3 +66,35 @@ needs console/loaded then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/trinary/trinary-tests.8th b/exercises/practice/trinary/trinary-tests.8th index 896ecbaf..54e83f6b 100644 --- a/exercises/practice/trinary/trinary-tests.8th +++ b/exercises/practice/trinary/trinary-tests.8th @@ -1,3 +1,4 @@ +10 tests "1 is decimal 1" ( "1" trinary> ) 1 test_eq "2 is decimal 2" ( "2" trinary> ) 2 test_eq "10 is decimal 3" ( "10" trinary> ) 3 test_eq diff --git a/exercises/practice/two-fer/test-words.8th b/exercises/practice/two-fer/test-words.8th index 3bd2d3cf..79c96a53 100644 --- a/exercises/practice/two-fer/test-words.8th +++ b/exercises/practice/two-fer/test-words.8th @@ -1,72 +1,100 @@ -requires console +needs console/loaded -\ place to store test name to keep it out of the stack -\ until needed -\ null var, test-name +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- - \ rot test-name ! + decr-test-count isword? !if swap then - >r r> w:exec + w:exec n:= if - \ test-name @ con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else - \ test-name @ con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; : test_eqs \ s x w -- | s w x -- - \ rot test-name ! + decr-test-count isword? !if swap then - >r r> w:exec + w:exec s:= if - \ test-name @ con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else - \ test-name @ con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; : test_true \ s w -- - \ swap test-name ! - r> >r w:exec + decr-test-count + w:exec if - \ test-name @ con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else - \ test-name @ con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; : test_false \ s w -- - \ swap test-name ! - >r r> w:exec + decr-test-count + w:exec !if - \ test-name @ con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else - \ test-name @ con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; : test_null \ s w -- - \ swap test-name ! - >r r> w:exec + decr-test-count + w:exec null? if - \ test-name @ drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else - \ test-name @ drop con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/two-fer/two-fer-tests.8th b/exercises/practice/two-fer/two-fer-tests.8th index 717b646a..56d4b671 100644 --- a/exercises/practice/two-fer/two-fer-tests.8th +++ b/exercises/practice/two-fer/two-fer-tests.8th @@ -1,3 +1,4 @@ +4 tests "Unnamed person test with empty string" ( "" two-fer ) "One for you, one for me." test_eqs "Unnamed person test with null" ( null two-fer ) "One for you, one for me." test_eqs "One for the judge" ( "Jedoon" two-fer ) "One for Jedoon, one for me." test_eqs diff --git a/exercises/practice/word-count/test-words.8th b/exercises/practice/word-count/test-words.8th index 917d5e11..79c96a53 100644 --- a/exercises/practice/word-count/test-words.8th +++ b/exercises/practice/word-count/test-words.8th @@ -1,12 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; + : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -15,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -25,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -34,7 +47,8 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -43,7 +57,8 @@ needs console/loaded ; : test_null \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec null? if drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -51,22 +66,23 @@ needs console/loaded then ; -: test_map_neq \ m m -- +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec - ' n:= m:= !if - 2drop + w:exec + ' s:= a:= nip nip if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else - 2drop con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; -: test_map_eq \ m m -- +: test_map_neq \ m m -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec - ' n:= m:= if + w:exec + ' n:= m:= !if 2drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -75,5 +91,10 @@ needs console/loaded then ; - - +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/word-count/word-count-tests.8th b/exercises/practice/word-count/word-count-tests.8th index 2772818a..d9a7f0e0 100644 --- a/exercises/practice/word-count/word-count-tests.8th +++ b/exercises/practice/word-count/word-count-tests.8th @@ -1,3 +1,4 @@ +14 tests "count one word" ( "word" word-count ) { "word":1 } test_map_eq "count one of each word" ( "one of each" word-count ) { "one":1,"of":1,"each":1 } test_map_eq "multiple occurrences of a word" ( "one fish two fish red fish blue fish" word-count ) { "one":1,"fish":4,"two":1,"red":1,"blue":1 } test_map_eq @@ -11,5 +12,4 @@ "substrings from the beginning" ( "Joe can't tell between app, apple and a." word-count ) { "joe":1,"can't":1,"tell":1,"between":1,"app":1,"apple":1,"and":1,"a":1 } test_map_eq "multiple spaces not detected as a word" ( " multiple whitespaces" word-count ) { "multiple":1,"whitespaces":1 } test_map_eq "alternating word separators not detected as a word" ( ",\n,one,\n ,two \n 'three'" word-count ) { "one":1,"two":1,"three":1 } test_map_eq -"quotation for word with apostrophe" ( "can, can't, 'can't'" word-count ) { "can":1,"can't":2 } test_map_eq - +"quotation for word with apostrophe" ( "can, can't, 'can't'" word-count ) { "can":1,"can't":2 } test_map_eq \ No newline at end of file diff --git a/exercises/practice/yacht/test-words.8th b/exercises/practice/yacht/test-words.8th index 7053f61a..79c96a53 100644 --- a/exercises/practice/yacht/test-words.8th +++ b/exercises/practice/yacht/test-words.8th @@ -1,13 +1,23 @@ needs console/loaded +-1 var, test-count + +: tests \ n -- + test-count ! +; + +: decr-test-count \ -- + test-count @ n:1- test-count ! +; : isword? \ x -- x f dup >kind ns:w n:= ; : test_eq \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec n:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -16,8 +26,9 @@ needs console/loaded ; : test_eqs \ s x w -- | s w x -- + decr-test-count isword? !if swap then - a:new swap 0 swap a:! 0 a:@ nip w:exec + w:exec s:= if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -26,7 +37,8 @@ needs console/loaded ; : test_true \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else @@ -35,10 +47,54 @@ needs console/loaded ; : test_false \ s w -- - a:new swap 0 swap a:! 0 a:@ nip w:exec + decr-test-count + w:exec !if con:green con:onBlack . space " ... OK" . con:white con:onBlack cr else con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr then ; + +: test_null \ s w -- + decr-test-count + w:exec + null? if + drop con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + drop con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +\ compare arrays by testing elements with string equality +: test_eqa \ s x w -- | s w x -- + decr-test-count + isword? !if swap then + w:exec + ' s:= a:= nip nip if + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +: test_map_neq \ m m -- + decr-test-count + isword? !if swap then + w:exec + ' n:= m:= !if + 2drop + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr + else + 2drop + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + then +; + +( test-count @ 0 n:= + !if + con:red con:onBlack + "... FAIL - not all tests completed" . + con:white con:onBlack + cr + then ) onexit diff --git a/exercises/practice/yacht/yacht-tests.8th b/exercises/practice/yacht/yacht-tests.8th index 584df052..ea09a529 100644 --- a/exercises/practice/yacht/yacht-tests.8th +++ b/exercises/practice/yacht/yacht-tests.8th @@ -1,3 +1,4 @@ +29 tests "Yacht" 50 ( [5, 5, 5, 5, 5] "yacht" play_yacht ) test_eq "Not Yacht" 0 ( [1, 3, 3, 2, 5] "yacht" play_yacht ) test_eq "Ones" 3 ( [1, 1, 1, 3, 5] "ones" play_yacht ) test_eq