val create : (size:Base.Int.t -> random:Splittable_random.State.t -> 'a) -> 'a Generator.t
val generate : 'a Generator.t -> size:Base.Int.t -> random:Splittable_random.State.t -> 'a
Generators form a monad. t1 >>= fun x -> t2
replaces each value x
in t1
with the values in t2
; each value's probability is the product of its probability in t1
and t2
.
include Base.Monad.S with module Let_syntax := Generator.Let_syntax and type 'a t := 'a Generator.t
val (>>=) : 'a Generator.t -> ('a -> 'a Generator.t) -> 'a Generator.t
t >>= f
returns a computation that sequences the computations represented by two monad elements. The resulting computation first doest
to yield a valuev
, and then runs the computation returned byf v
.
val (>>|) : 'a Generator.t -> ('a -> 'b) -> 'a Generator.t
t >>| f
ist >>= (fun a -> return (f a))
.
module Monad_infix : sig ... end
val bind : 'a Generator.t -> f:('a -> 'a Generator.t) -> 'a Generator.t
bind t ~f
=t >>= f
val return : 'a -> 'a Generator.t
return v
returns the (trivial) computation that returns v.
val map : 'a Generator.t -> f:('a -> 'b) -> 'a Generator.t
map t ~f
is t >>| f.
val join : 'a Generator.t -> 'a Generator.t
join t
ist >>= (fun t' -> t')
.
val ignore_m : 'a Generator.t -> 'a Generator.t
ignore_m t
ismap t ~f:(fun _ -> ())
.ignore_m
used to be calledignore
, but we decided that was a bad name, because it shadowed the widely usedCaml.ignore
. Some monads still dolet ignore = ignore_m
for historical reasons.
val all : 'a Generator.t list -> 'a Generator.t
val all_unit : 'a Generator.t list -> 'a Generator.t
Like
all
, but ensures that every monadic value in the list produces a unit value, all of which are discarded rather than being collected into a list.
include Base.Applicative.S with type 'a t := 'a Generator.t
val return : 'a -> 'a Generator.t
val map : 'a Generator.t -> f:('a -> 'b) -> 'a Generator.t
val both : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val (<*>) : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
same as
apply
val (<*) : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val (*>) : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val (>>|) : 'a Generator.t -> ('a -> 'b) -> 'a Generator.t
val apply : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val map2 : 'a Generator.t -> 'a Generator.t -> f:('a -> 'b -> 'c) -> 'a Generator.t
val map3 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> f:('a -> 'b -> 'c -> 'd) -> 'a Generator.t
val all : 'a Generator.t list -> 'a Generator.t
val all_unit : 'a Generator.t list -> 'a Generator.t
module Applicative_infix : sig ... end
val size : 'a Generator.t
size = create (fun ~size _ -> size)
val with_size : 'a Generator.t -> size:Base.Int.t -> 'a Generator.t
with_size t ~size = create (fun ~size:_ random -> generate t ~size random)
val bool : 'a Generator.t
val char : 'a Generator.t
val char_digit : 'a Generator.t
val char_lowercase : 'a Generator.t
val char_uppercase : 'a Generator.t
val char_alpha : 'a Generator.t
val char_alphanum : 'a Generator.t
val char_print : 'a Generator.t
val char_whitespace : 'a Generator.t
val singleton : 'a -> 'a Generator.t
val doubleton : 'a -> 'a -> 'a Generator.t
val of_list : 'a Base.List.t -> 'a Generator.t
Produce any of the given values, weighted equally.
of_list [ v1 ; ... ; vN ] = union [ singleton v1 ; ... ; singleton vN ]
val union : 'a Generator.t Base.List.t -> 'a Generator.t
Combine arbitary generators, weighted equally.
union [ g1 ; ... ; gN ] = weighted_union [ (1.0, g1) ; ... ; (1.0, gN) ]
val of_sequence : p:Base.Float.t -> 'a Sequence.t -> 'a Generator.t
Generator for the values from a potentially infinite sequence. Chooses each value with probability
p
, or continues with probability1-p
. Must satisfy0. < p && p <= 1.
.
val tuple2 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val tuple3 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val tuple4 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val tuple5 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val tuple6 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val variant2 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val variant3 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val variant4 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val variant5 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val variant6 : 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t -> 'a Generator.t
val geometric : p:Base.Float.t -> Base.Int.t -> 'a Generator.t
geometric ~p init
produces a geometric distribution (think "radioactive decay") that producesinit
with probabilityp
, and otherwise recursively chooses fromgeometric ~p (init+1)
. Must satisfy0. < p && p <= 1.
.
val small_non_negative_int : 'a Generator.t
small_non_negative_int
produces a non-negative int of a tractable size, e.g. allocating a value of this size should not run out of memory.
val small_positive_int : 'a Generator.t
small_positive_int
produces a positive int of a tractable size, e.g. allocating a value of this size should not run out of memory.
val fn : 'a Base_quickcheck.Observer.t -> 'a Generator.t -> 'a Generator.t
Generators for functions; take observers for inputs and a generator for outputs.
val fn2 : 'a Base_quickcheck.Observer.t -> 'b Base_quickcheck.Observer.t -> 'a Generator.t -> 'a Generator.t
val fn3 : 'a Base_quickcheck.Observer.t -> 'b Base_quickcheck.Observer.t -> 'c Base_quickcheck.Observer.t -> 'a Generator.t -> 'a Generator.t
val fn4 : 'a Base_quickcheck.Observer.t -> 'b Base_quickcheck.Observer.t -> 'c Base_quickcheck.Observer.t -> 'd Base_quickcheck.Observer.t -> 'a Generator.t -> 'a Generator.t
val fn5 : 'a Base_quickcheck.Observer.t -> 'b Base_quickcheck.Observer.t -> 'c Base_quickcheck.Observer.t -> 'd Base_quickcheck.Observer.t -> 'e Base_quickcheck.Observer.t -> 'a Generator.t -> 'a Generator.t
val fn6 : 'a Base_quickcheck.Observer.t -> 'b Base_quickcheck.Observer.t -> 'c Base_quickcheck.Observer.t -> 'd Base_quickcheck.Observer.t -> 'e Base_quickcheck.Observer.t -> 'f Base_quickcheck.Observer.t -> 'a Generator.t -> 'a Generator.t
val compare_fn : 'a Base_quickcheck.Observer.t -> 'a Generator.t
Generator for comparison functions; result is guaranteed to be a partial order.
val equal_fn : 'a Base_quickcheck.Observer.t -> 'a Generator.t
Generator for equality functions; result is guaranteed to be an equivalence relation.
val filter_map : 'a Generator.t -> f:('a -> 'b Base.Option.t) -> 'a Generator.t
filter_map t ~f
producesy
for everyx
int
such thatf x = Some y
.
val filter : 'a Generator.t -> f:('a -> Base.Bool.t) -> 'a Generator.t
filter t ~f
produces everyx
int
such thatf x = true
.
val recursive_union : 'a Generator.t Base.List.t -> f:('a Generator.t -> 'a Generator.t Base.List.t) -> 'a Generator.t
Generator for recursive data type with multiple clauses. At size 0, chooses only among the non-recursive cases; at sizes greater than 0, chooses among non-recursive and recursive cases, calling the recursive cases with decremented size.
type tree = Leaf | Node of tree * int * tree;; recursive_union [return Leaf] ~f:(fun self -> [let%map left = self and int = Int.gen and right = self in Node (left, int, right)])
val weighted_recursive_union : (Base.Float.t * 'a Generator.t) Base.List.t -> f:('a Generator.t -> (Base.Float.t * 'a Generator.t) Base.List.t) -> 'a Generator.t
Like
recursive_union
, with the addition of non-uniform weights for each clause.
val fixed_point : ('a Generator.t -> 'a Generator.t) -> 'a Generator.t
Fixed-point generator. Use
size
to bound the size of the value and the depth of the recursion. There is no prescribed semantics forsize
except that it must be non-negative. For example, the following produces a naive generator for natural numbers:fixed_point (fun self -> match%bind size with | 0 -> singleton 0 | n -> with_size self ~size:(n-1) >>| Int.succ)
val weighted_union : (Base.Float.t * 'a Generator.t) Base.List.t -> 'a Generator.t
weighted_union alist
produces a generator that combines the distributions of eacht
inalist
with the associated weights, which must be finite positive floating point values.
val of_fun : (Base.Unit.t -> 'a Generator.t) -> 'a Generator.t
of_fun f
produces a generator that lazily appliesf
.It is recommended that
f
not be memoized. Instead, spread out the work of generating a whole distribution over manyof_fun
calls combined withweighted_union
. This allows lazily generated generators to be garbage collected after each test and the relevant portions cheaply recomputed in subsequent tests, rather than accumulating without bound over time.
val list : 'a Generator.t -> 'a Generator.t
Generators for lists, choosing each element independently from the given element generator.
list
andlist_non_empty
distributesize
among the list length and the sizes of each element.list_non_empty
never generates the empty list.list_with_length
generates lists of the given length, and distributessize
among the sizes of the elements.
val list_non_empty : 'a Generator.t -> 'a Generator.t
val list_with_length : Base.Int.t -> 'a Generator.t -> 'a Generator.t