Paste: Use of custom error messages with tools.testest

Author: nomennescio
Mode: factor
Date: Wed, 5 Jan 2022 09:07:48
Plain Text |
! 2021 Factor test cases by nomennescio

USING: accessors debugger io kata kernel locals math math.parser namespaces random sequences regexp tools.testest ;
IN: kata.tests

: multiple? ( a b -- t/f ) mod zero? ;

:: run-tests ( -- )
  solution :> re
  [ "Check if divisible by 7 with regular expression" describe#{
    "Edge cases" it#{
      [ "Should not be empty" write drop ] test-failed. set
      <{ re raw>> empty? -> f }>
      [ "Should accept 0" write drop ] test-failed. set
      <{ "0" re matches? -> t }>
    }#
    [ expected>> first2 number>string write " IS" " is NOT" ? write " divisible by 7" write ] test-failed. set
    "Test 0..100" it#{
      100 <iota> [ :> i <{ i >bin re matches? i -> i 7 multiple? i }> ] each
    }#
    "Random numbers" it#{
      1000 [ random-32 :> r <{ r >bin re matches? r -> r 7 multiple? r }> ] times
    }#
  }# ] with-scope
;

MAIN: run-tests

New Annotation

Summary:
Author:
Mode:
Body: