Skip to main content

such-that

function

clojure.test.check.generators/such-that

(such-that [pred gen] [pred gen max-tries-or-opts])
Creates a generator that generates values from `gen` that satisfy predicate `pred`. Care is needed to ensure there is a high chance `gen` will satisfy `pred`. By default, `such-that` will try 10 times to generate a value that satisfies the predicate. If no value passes this predicate after this number of iterations, a runtime exception will be thrown. Note also that each time such-that retries, it will increase the size parameter. Examples: ;; generate non-empty vectors of integers ;; (note, gen/not-empty does exactly this) (gen/such-that not-empty (gen/vector gen/small-integer)) You can customize `such-that` by passing an optional third argument, which can either be an integer representing the maximum number of times test.check will try to generate a value matching the predicate, or a map: :max-tries positive integer, the maximum number of tries (default 10) :ex-fn a function of one arg that will be called if test.check cannot generate a matching value; it will be passed a map with `:gen`, `:pred`, and `:max-tries` and should return an exception

No examples yet. Be the first to add one!