\ First Forth Kumite
: hw ." Hello World!" ;
hw cr
Code
Diff
  • \ Test Framework (ttester + extension)
    decimal
    s" test/ttester.fs" included
    
    : #ms ( dmicroseconds -- len c-addr ) <# # # # [char] . hold #s #> ;
    
    : describe#{ ( len c-addr -- ) cr ." <DESCRIBE::>" type cr utime ;
    : it#{ ( len c-addr -- ) cr ." <IT::>" type cr utime ;
    : }# ( -- ) utime cr ." <COMPLETEDIN::>" 2swap d- #ms type ."  ms" cr ;
    
    create EXPECTED-RESULTS 32 cells allot
    variable RESULTS
    variable DIFFERENCES
    
    : <{ T{ ;
    : }>
      depth ACTUAL-DEPTH @ = if
        depth START-DEPTH @ > if
          depth START-DEPTH @ - dup RESULTS ! 0 do
            dup EXPECTED-RESULTS i cells + !
            ACTUAL-RESULTS i cells + @ <> DIFFERENCES +!
          loop
    
          DIFFERENCES @ if
            cr ." <FAILED::>expected: "
            RESULTS @ 0 do EXPECTED-RESULTS i cells + @ . loop
            ." <:LF:>  actual: "
            RESULTS @ 0 do ACTUAL-RESULTS i cells + @ . loop
            cr
    
          else
            cr ." <PASSED::>Test Passed" cr
          then
        then
      else
        cr ." <FAILED::>Wrong number of results. Expected:<:LF:>" ACTUAL-DEPTH @ . ." <:LF:>got:<:LF:>" depth . cr
      then
    F} ;
    
    \ Solution
    : solution ( a b -- a*b ) * ;
    
    \ Tests
    s" Basic Tests" describe#{
      s" zeros" it#{
        <{ 0 0 solution -> 0 }>
        <{ 0 1 solution -> 0 }>
        <{ 1 0 solution -> 0 }>
      }#
    
      s" non-zeros" it#{
        \ intentionally broken tests
        \ <{ 1 1 solution -> 2 }>
        \ <{ 3 5 solution -> 8 }>
        <{ 1 1 solution -> 1 }>
      }#
    }#
  • 4747
        <{ 0 1 solution -> 0 }>
    
    4848
        <{ 1 0 solution -> 0 }>
    
    4949
      }#
    
    5050
    5151
      s" non-zeros" it#{
    
    5252
        \ intentionally broken tests
    
    53
        <{ 1 1 solution -> 2 }>
    
    54
        <{ 3 5 solution -> 8 }>
    
    53+
        \ <{ 1 1 solution -> 2 }>
    
    54+
        \ <{ 3 5 solution -> 8 }>
    
    55+
        <{ 1 1 solution -> 1 }>
    
    5555
      }#
    
    5656
    }#