Ad

Minimal example for Idris testing with specdris.

module Example

%access export
%default total

add : Nat -> Nat -> Nat
add a b = a + b
kazkFailed Tests

Forth Testing

Experiments to add test support for Forth (Codewars/codewars-runner-cli#625).

The test framework part was originally contributed by @nomennescio.

\ 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 }>
  }#
}#
Testing
Frameworks

Proposed expect_error deployed on preview.