Liking cljdoc? Tell your friends :D

clojure.test.check.generators


anyclj/s

A recursive generator that will generate many different, often nested, values

A recursive generator that will generate many different, often nested, values
source (clj)source (cljs)raw docstring

any-printableclj/s

Like any, but avoids characters that the shell will interpret as actions, like 7 and 14 (bell and alternate character set command)

Like any, but avoids characters that the shell will interpret as actions,
like 7 and 14 (bell and alternate character set command)
source (clj)source (cljs)raw docstring

bindclj/s

(bind generator k)

Create a new generator that passes the result of gen into function k. k should return a new generator. This allows you to create new generators that depend on the value of other generators. For example, to create a generator which first generates a vector of integers, and then chooses a random element from that vector:

(gen/bind (gen/such-that not-empty (gen/vector gen/int))
          ;; this function takes a realized vector,
          ;; and then returns a new generator which
          ;; chooses a random element from it
          gen/elements)
Create a new generator that passes the result of `gen` into function
`k`. `k` should return a new generator. This allows you to create new
generators that depend on the value of other generators. For example,
to create a generator which first generates a vector of integers, and
then chooses a random element from that vector:

    (gen/bind (gen/such-that not-empty (gen/vector gen/int))
              ;; this function takes a realized vector,
              ;; and then returns a new generator which
              ;; chooses a random element from it
              gen/elements)

source (clj)source (cljs)raw docstring

booleanclj/s

Generates one of true or false. Shrinks to false.

Generates one of `true` or `false`. Shrinks to `false`.
source (clj)source (cljs)raw docstring

byteclj

Generates java.lang.Bytes, using the full byte-range.

Generates `java.lang.Byte`s, using the full byte-range.
sourceraw docstring

bytesclj

Generates byte-arrays.

Generates byte-arrays.
sourceraw docstring

charclj/s

Generates character from 0-255.

Generates character from 0-255.
source (clj)source (cljs)raw docstring

char-alphaclj/s

Generate alpha characters.

Generate alpha characters.
source (clj)source (cljs)raw docstring

char-alpha-numericclj/sdeprecated

Deprecated - use char-alphanumeric instead.

Generate alphanumeric characters.

Deprecated - use char-alphanumeric instead.

Generate alphanumeric characters.
source (clj)source (cljs)raw docstring

char-alphanumericclj/s

Generate alphanumeric characters.

Generate alphanumeric characters.
source (clj)source (cljs)raw docstring

char-asciiclj/s

Generate only ascii character.

Generate only ascii character.
source (clj)source (cljs)raw docstring

chooseclj/s≠

(choose lower upper)
clj

Create a generator that returns long integers in the range lower to upper, inclusive.

Create a generator that returns long integers in the range `lower` to `upper`, inclusive.
cljs

Create a generator that returns numbers in the range min-range to max-range, inclusive.

Create a generator that returns numbers in the range
`min-range` to `max-range`, inclusive.
source (clj)source (cljs)raw docstring

container-typeclj/s

(container-type inner-type)
source (clj)source (cljs)

elementsclj/s

(elements coll)

Create a generator that randomly chooses an element from coll.

Examples:

(gen/elements [:foo :bar :baz])
Create a generator that randomly chooses an element from `coll`.

Examples:

    (gen/elements [:foo :bar :baz])
source (clj)source (cljs)raw docstring

fmapclj/s

(fmap f gen)
source (clj)source (cljs)

frequencyclj/s

(frequency pairs)

Create a generator that chooses a generator from pairs based on the provided likelihoods. The likelihood of a given generator being chosen is its likelihood divided by the sum of all likelihoods

Examples:

(gen/frequency [[5 gen/int] [3 (gen/vector gen/int)] [2 gen/boolean]])
Create a generator that chooses a generator from `pairs` based on the
provided likelihoods. The likelihood of a given generator being chosen is
its likelihood divided by the sum of all likelihoods

Examples:

    (gen/frequency [[5 gen/int] [3 (gen/vector gen/int)] [2 gen/boolean]])
source (clj)source (cljs)raw docstring

generateclj/s

(generate generator)
(generate generator size)

Returns a single sample value from the generator, using a default size of 30.

Returns a single sample value from the generator, using a default
size of 30.
source (clj)source (cljs)raw docstring

generator?clj/s

(generator? x)

Test if x is a generator. Generators should be treated as opaque values.

Test if `x` is a generator. Generators should be treated as opaque values.
source (clj)source (cljs)raw docstring

hash-mapclj/s

(hash-map & kvs)

Like clojure.core/hash-map, except the values are generators. Returns a generator that makes maps with the supplied keys and values generated using the supplied generators.

Examples:

(gen/hash-map :a gen/boolean :b gen/nat)

Like clojure.core/hash-map, except the values are generators.
 Returns a generator that makes maps with the supplied keys and
 values generated using the supplied generators.

Examples:

  (gen/hash-map :a gen/boolean :b gen/nat)
source (clj)source (cljs)raw docstring

intclj/s

Generates a positive or negative integer bounded by the generator's size parameter. (Really returns a long)

Generates a positive or negative integer bounded by the generator's
`size` parameter.
(Really returns a long)
source (clj)source (cljs)raw docstring

keywordclj/s

Generate keywords without namespaces.

Generate keywords without namespaces.
source (clj)source (cljs)raw docstring

keyword-nsclj/s

Generate keywords with optional namespaces.

Generate keywords with optional namespaces.
source (clj)source (cljs)raw docstring

lazy-random-statesclj/s

(lazy-random-states rr)

Given a random number generator, returns an infinite lazy sequence of random number generators.

Given a random number generator, returns an infinite lazy sequence
of random number generators.
source (clj)source (cljs)raw docstring

listclj/s

(list generator)

Like vector, but generates lists.

Like `vector`, but generates lists.
source (clj)source (cljs)raw docstring

mapclj/s

(map key-gen val-gen)

Create a generator that generates maps, with keys chosen from key-gen and values chosen from val-gen.

Create a generator that generates maps, with keys chosen from
`key-gen` and values chosen from `val-gen`.
source (clj)source (cljs)raw docstring

natclj/s

Generates natural numbers, starting at zero. Shrinks to zero.

Generates natural numbers, starting at zero. Shrinks to zero.
source (clj)source (cljs)raw docstring

neg-intclj/s

Generate negative integers bounded by the generator's size parameter.

Generate negative integers bounded by the generator's `size` parameter.
source (clj)source (cljs)raw docstring

no-shrinkclj/s

(no-shrink gen)

Create a new generator that is just like gen, except does not shrink at all. This can be useful when shrinking is taking a long time or is not applicable to the domain.

Create a new generator that is just like `gen`, except does not shrink
at all. This can be useful when shrinking is taking a long time or is not
applicable to the domain.
source (clj)source (cljs)raw docstring

not-emptyclj/s

(not-empty gen)

Modifies a generator so that it doesn't generate empty collections.

Examples:

;; generate a vector of booleans, but never the empty vector
(gen/not-empty (gen/vector gen/boolean))
Modifies a generator so that it doesn't generate empty collections.

Examples:

    ;; generate a vector of booleans, but never the empty vector
    (gen/not-empty (gen/vector gen/boolean))
source (clj)source (cljs)raw docstring

one-ofclj/s

(one-of generators)

Create a generator that randomly chooses a value from the list of provided generators. Shrinks toward choosing an earlier generator, as well as shrinking the value generated by the chosen generator.

Examples:

(one-of [gen/int gen/boolean (gen/vector gen/int)])
Create a generator that randomly chooses a value from the list of
provided generators. Shrinks toward choosing an earlier generator,
as well as shrinking the value generated by the chosen generator.

Examples:

    (one-of [gen/int gen/boolean (gen/vector gen/int)])

source (clj)source (cljs)raw docstring

pos-intclj/s

Generate positive integers bounded by the generator's size parameter.

Generate positive integers bounded by the generator's `size` parameter.
source (clj)source (cljs)raw docstring

ratioclj/s

Generates a clojure.lang.Ratio. Shrinks toward 0. Not all values generated will be ratios, as many values returned by / are not ratios.

Generates a `clojure.lang.Ratio`. Shrinks toward 0. Not all values generated
will be ratios, as many values returned by `/` are not ratios.
source (clj)source (cljs)raw docstring

recursive-genclj/s

(recursive-gen container-gen-fn scalar-gen)

This is a helper for writing recursive (tree-shaped) generators. The first argument should be a function that takes a generator as an argument, and produces another generator that 'contains' that generator. The vector function in this namespace is a simple example. The second argument is a scalar generator, like boolean. For example, to produce a tree of booleans:

(gen/recursive-gen gen/vector gen/boolean)

Vectors or maps either recurring or containing booleans or integers:

(gen/recursive-gen (fn [inner] (gen/one-of [(gen/vector inner) (gen/map inner inner)])) (gen/one-of [gen/boolean gen/int]))

This is a helper for writing recursive (tree-shaped) generators. The first
argument should be a function that takes a generator as an argument, and
produces another generator that 'contains' that generator. The vector function
in this namespace is a simple example. The second argument is a scalar
generator, like boolean. For example, to produce a tree of booleans:

  (gen/recursive-gen gen/vector gen/boolean)

Vectors or maps either recurring or containing booleans or integers:

  (gen/recursive-gen (fn [inner] (gen/one-of [(gen/vector inner)
                                              (gen/map inner inner)]))
                     (gen/one-of [gen/boolean gen/int]))
source (clj)source (cljs)raw docstring

resizeclj/s

(resize n generator)

Create a new generator with size always bound to n.

Create a new generator with `size` always bound to `n`.
source (clj)source (cljs)raw docstring

returnclj/s

(return value)

Create a generator that always returns value, and never shrinks. You can think of this as the constantly of generators.

Create a generator that always returns `value`,
and never shrinks. You can think of this as
the `constantly` of generators.
source (clj)source (cljs)raw docstring

s-neg-intclj/s

Generate strictly negative integers bounded by the generator's size parameter.

Generate strictly negative integers bounded by the generator's `size`
parameter.
source (clj)source (cljs)raw docstring

s-pos-intclj/s

Generate strictly positive integers bounded by the generator's size parameter.

Generate strictly positive integers bounded by the generator's `size`
parameter.
source (clj)source (cljs)raw docstring

sampleclj/s

(sample generator)
(sample generator num-samples)

Return a sequence of num-samples (default 10) realized values from generator.

Return a sequence of `num-samples` (default 10)
realized values from `generator`.
source (clj)source (cljs)raw docstring

sample-seqclj/s

(sample-seq generator)
(sample-seq generator max-size)

Return a sequence of realized values from generator.

Return a sequence of realized values from `generator`.
source (clj)source (cljs)raw docstring

scaleclj/s

(scale f generator)

Create a new generator that modifies the size parameter by the given function. Intended to support generators with sizes that need to grow at different rates compared to the normal linear scaling.

Create a new generator that modifies the size parameter by the given function. Intended to
support generators with sizes that need to grow at different rates compared to the normal
linear scaling.
source (clj)source (cljs)raw docstring

shrink-2clj/s

(shrink-2 gen)

Create a new generator like gen, but will consider nodes for shrinking even if their parent passes the test (up to one additional level).

Create a new generator like `gen`, but will consider nodes for shrinking
even if their parent passes the test (up to one additional level).
source (clj)source (cljs)raw docstring

shuffleclj/s

(shuffle coll)

Create a generator that generates random permutations of coll. Shrinks toward the original collection: coll. coll will be turned into a vector, if it's not already.

Create a generator that generates random permutations of `coll`. Shrinks
toward the original collection: `coll`. `coll` will be turned into a vector,
if it's not already.
source (clj)source (cljs)raw docstring

simple-type-printableclj/s

source (clj)source (cljs)

sizedclj/s

(sized sized-gen)

Create a generator that depends on the size parameter. sized-gen is a function that takes an integer and returns a generator.

Create a generator that depends on the size parameter.
`sized-gen` is a function that takes an integer and returns
a generator.
source (clj)source (cljs)raw docstring

stringclj/s

Generate strings. May generate unprintable characters.

Generate strings. May generate unprintable characters.
source (clj)source (cljs)raw docstring

string-alpha-numericclj/sdeprecated

Deprecated - use string-alphanumeric instead.

Generate alphanumeric strings.

Deprecated - use string-alphanumeric instead.

Generate alphanumeric strings.
source (clj)source (cljs)raw docstring

string-alphanumericclj/s

Generate alphanumeric strings.

Generate alphanumeric strings.
source (clj)source (cljs)raw docstring

string-asciiclj/s

Generate ascii strings.

Generate ascii strings.
source (clj)source (cljs)raw docstring

such-thatclj/s

(such-that pred gen)
(such-that pred gen max-tries)

Create 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 throw. You can pass an optional third argument to change the number of times tried. 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/int))
Create 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 throw. You can pass an optional
third argument to change the number of times tried. 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/int))
source (clj)source (cljs)raw docstring

symbolclj/s

Generate symbols without namespaces.

Generate symbols without namespaces.
source (clj)source (cljs)raw docstring

symbol-nsclj/s

Generate symbols with optional namespaces.

Generate symbols with optional namespaces.
source (clj)source (cljs)raw docstring

tupleclj/s

(tuple & generators)

Create a generator that returns a vector, whose elements are chosen from the generators in the same position. The individual elements shrink according to their generator, but the value will never shrink in count.

Examples:

(def t (tuple gen/int gen/boolean))
(sample t)
;; => ([1 true] [2 true] [2 false] [1 false] [0 true] [-2 false] [-6 false]
;; =>  [3 true] [-4 false] [9 true]))
Create a generator that returns a vector, whose elements are chosen
from the generators in the same position. The individual elements shrink
according to their generator, but the value will never shrink in count.

Examples:

    (def t (tuple gen/int gen/boolean))
    (sample t)
    ;; => ([1 true] [2 true] [2 false] [1 false] [0 true] [-2 false] [-6 false]
    ;; =>  [3 true] [-4 false] [9 true]))
source (clj)source (cljs)raw docstring

vectorclj/s

(vector generator)
(vector generator num-elements)
(vector generator min-elements max-elements)

Create a generator whose elements are chosen from gen. The count of the vector will be bounded by the size generator parameter.

Create a generator whose elements are chosen from `gen`. The count of the
vector will be bounded by the `size` generator parameter.
source (clj)source (cljs)raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close