Legend:
Library
Module
Module type
Parameter
Class
Class type
An 'a t a generates values of type 'a with a specific probability distribution.
Generators are constructed as functions that produce a value from a splittable pseudorandom number generator (see Splittable_random), with a ~size argument threaded through to bound the size of the result value and the depth of recursion.
There is no prescribed semantics for size other than that it must be non-negative. Non-recursive generators are free to ignore it, and recursive generators need only make sure it decreases in recursive calls and that recursion bottoms out at 0.
type+'a t = 'aBase_quickcheck.Generator.t
val create :
(size:Base.Int.t ->random:Splittable_random.State.t ->'a)->'at
val generate :
'at->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.
This can be used to form distributions of related values. For instance, the following expression creates a distribution of pairs x,y where x <= y:
Int.gen
>>= fun x ->
Int.gen_incl x Int.max_value
>>| fun y ->
x, y
union [ g1 ; ... ; gN ] = weighted_union [ (1.0, g1) ; ... ; (1.0, gN) ]
val of_sequence : p:Base.Float.t ->'aSequence.t->'at
Generator for the values from a potentially infinite sequence. Chooses each value with probability p, or continues with probability 1-p. Must satisfy 0. < p &&
p <= 1..
val variant3 : 'at->'bt->'ct->[ `A of 'a| `B of 'b| `C of 'c ]t
val variant4 :
'at->'bt->'ct->'dt->[ `A of 'a| `B of 'b| `C of 'c| `D of 'd ]t
val variant5 :
'at->'bt->'ct->'dt->'et->[ `A of 'a| `B of 'b| `C of 'c| `D of 'd| `E of 'e ]t
val variant6 :
'at->'bt->'ct->'dt->'et->'ft->[ `A of 'a| `B of 'b| `C of 'c| `D of 'd| `E of 'e| `F of 'f ]t
val geometric : p:Base.Float.t ->Base.Int.t ->Base.Int.t t
geometric ~p init produces a geometric distribution (think "radioactive decay") that produces init with probability p, and otherwise recursively chooses from geometric ~p (init+1). Must satisfy 0. < p && p <= 1..
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 : 'aBase_quickcheck.Observer.t->'bt->('a->'b)t
Generators for functions; take observers for inputs and a generator for outputs.
val fn2 :
'aBase_quickcheck.Observer.t->'bBase_quickcheck.Observer.t->'ct->('a->'b->'c)t
val fn3 :
'aBase_quickcheck.Observer.t->'bBase_quickcheck.Observer.t->'cBase_quickcheck.Observer.t->'dt->('a->'b->'c->'d)t
val fn4 :
'aBase_quickcheck.Observer.t->'bBase_quickcheck.Observer.t->'cBase_quickcheck.Observer.t->'dBase_quickcheck.Observer.t->'et->('a->'b->'c->'d->'e)t
val fn5 :
'aBase_quickcheck.Observer.t->'bBase_quickcheck.Observer.t->'cBase_quickcheck.Observer.t->'dBase_quickcheck.Observer.t->'eBase_quickcheck.Observer.t->'ft->('a->'b->'c->'d->'e->'f)t
val fn6 :
'aBase_quickcheck.Observer.t->'bBase_quickcheck.Observer.t->'cBase_quickcheck.Observer.t->'dBase_quickcheck.Observer.t->'eBase_quickcheck.Observer.t->'fBase_quickcheck.Observer.t->'gt->('a->'b->'c->'d->'e->'f->'g)t
val compare_fn : 'aBase_quickcheck.Observer.t->('a->'a->Base.Int.t)t
Generator for comparison functions; result is guaranteed to be a partial order.
val equal_fn : 'aBase_quickcheck.Observer.t->('a->'a->Base.Bool.t)t
Generator for equality functions; result is guaranteed to be an equivalence relation.
val filter_map : 'at->f:('a->'bBase.Option.t)->'bt
filter_map t ~f produces y for every x in t such that f x = Some y.
filter t ~f produces every x in t such that f x = true.
val recursive_union : 'atBase.List.t->f:('at->'atBase.List.t)->'at
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 * 'at)Base.List.t->f:('at->(Base.Float.t * 'at)Base.List.t)->'at
Like recursive_union, with the addition of non-uniform weights for each clause.
Fixed-point generator. Use size to bound the size of the value and the depth of the recursion. There is no prescribed semantics for size 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 * 'at)Base.List.t->'at
weighted_union alist produces a generator that combines the distributions of each t in alist with the associated weights, which must be finite positive floating point values.
of_fun f produces a generator that lazily applies f.
It is recommended that f not be memoized. Instead, spread out the work of generating a whole distribution over many of_fun calls combined with weighted_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.
Generators for lists, choosing each element independently from the given element generator. list and list_non_empty distribute size 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 distributes size among the sizes of the elements.