Module QCheck.Gen
Generate Random Values
val return : 'a -> 'a tCreate a constant generator.
val (>>=) : 'a t -> ('a -> 'b t) -> 'b tMonadic bind for writing dependent generators. First generates an
'aand then passes it to the given function, to generate a'b.
val (<*>) : ('a -> 'b) t -> 'a t -> 'b tInfix operator for composing a function generator and an argument generator into a result generator.
val map : ('a -> 'b) -> 'a t -> 'b tmap f gtransforms a generatorgby applyingfto each generated element.
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tmap2 f g1 g2transforms two generatorsg1andg2by applyingfto each pair of generated elements.
val map3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd tmap3 f g1 g2 g3transforms three generatorsg1,g2, andg3by applyingfto each triple of generated elements.
val map_keep_input : ('a -> 'b) -> 'a t -> ('a * 'b) tmap_keep_input f gtransforms a generatorgby applyingfto each generated element. Returns both the generated element fromgand the output fromf.
val oneofl : 'a list -> 'a tConstructs a generator that selects among a given list of values.
val oneofa : 'a array -> 'a tConstructs a generator that selects among a given array of values.
val frequency : (int * 'a t) list -> 'a tConstructs a generator that selects among a given list of generators. Each of the given generators are chosen based on a positive integer weight.
val frequencyl : (int * 'a) list -> 'a tConstructs a generator that selects among a given list of values. Each of the given values are chosen based on a positive integer weight.
val frequencya : (int * 'a) array -> 'a tConstructs a generator that selects among a given array of values. Each of the array entries are chosen based on a positive integer weight.
val shuffle_a : 'a array -> unit tShuffles the array in place.
val shuffle_l : 'a list -> 'a list tCreates a generator of shuffled lists.
val shuffle_w_l : (int * 'a) list -> 'a list tCreates a generator of weighted shuffled lists. A given list is shuffled on each generation according to the weights of its elements. An element with a larger weight is more likely to be at the front of the list than an element with a smaller weight. If we want to pick random elements from the (head of) list but need to prioritize some elements over others, this generator can be useful.
Example: given a weighted list
[1, "one"; 5, "five"; 10, "ten"], the generator is more likely to generate["ten"; "five"; "one"]or["five"; "ten"; "one"]than["one"; "ten"; "five"]because "ten" and "five" have larger weights than "one".- since
- 0.11
val unit : unit tThe unit generator.
val bool : bool tThe boolean generator.
val float : float tGenerates floating point numbers.
val pfloat : float tGenerates positive floating point numbers (0. included).
val nfloat : float tGenerates negative floating point numbers. (-0. included)
val float_bound_inclusive : float -> float tfloat_bound_inclusive boundreturns a random floating-point number between 0 andbound(inclusive). Ifboundis negative, the result is negative or zero. Ifboundis 0, the result is 0.- since
- 0.11
val float_bound_exclusive : float -> float tfloat_bound_exclusive boundreturns a random floating-point number between 0 andbound(exclusive). Ifboundis negative, the result is negative or zero.- raises Invalid_argument
if
boundis zero.
- since
- 0.11
val float_range : float -> float -> float tfloat_range low highgenerates floating-point numbers withinlowandhigh(inclusive)- raises Invalid_argument
if
high < lowor if the range is larger thanmax_float.
- since
- 0.11
val (--.) : float -> float -> float tSynonym for
float_range- since
- 0.11
val nat : int tGenerates small natural numbers.
val big_nat : int tGenerates natural numbers, possibly large.
- since
- 0.10
val neg_int : int tGenerates non-strictly negative integers (0 included).
val pint : int tGenerates non-strictly positive integers uniformly (0 included).
val int : int tGenerates integers uniformly.
val small_nat : int tSmall integers (< 100)
- since
- 0.5.1
val int_bound : int -> int tUniform integer generator producing integers within
0... bound. Forbound < 2^{30} - 1usesRandom.State.intfor integer generation.- raises Invalid_argument
if the argument is negative.
val int_range : int -> int -> int tUniform integer generator producing integers within
low,high.- raises Invalid_argument
if
low > high.
val graft_corners : 'a t -> 'a list -> unit -> 'a tgraft_corners gen l ()makes a new generator that enumerates the corner cases inland then behaves likeg.- since
- 0.6
val ui32 : int32 tGenerates (unsigned)
int32values.
val ui64 : int64 tGenerates (unsigned)
int64values.
val list : 'a t -> 'a list tBuilds a list generator from an element generator. List size is generated by
nat.
val list_size : int t -> 'a t -> 'a list tBuilds a list generator from a (non-negative) size generator and an element generator.
val list_repeat : int -> 'a t -> 'a list tlist_repeat i gbuilds a list generator from exactlyielements generated byg.
val array : 'a t -> 'a array tBuilds an array generator from an element generator. Array size is generated by
nat.
val array_size : int t -> 'a t -> 'a array tBuilds an array generator from a (non-negative) size generator and an element generator.
val array_repeat : int -> 'a t -> 'a array tarray_repeat i gbuilds an array generator from exactlyielements generated byg.
val char : char tGenerates characters upto character code 255.
val printable : char tGenerates printable characters.
val numeral : char tGenerates numeral characters.
val char_range : char -> char -> char tGenerates chars between the two bounds, inclusive. Example:
char_range 'a' 'z'for all lower case ascii letters.- since
- 0.13
val string_size : ?gen:char t -> int t -> string tBuilds a string generator from a (non-negative) size generator. Accepts an optional character generator (the default is
char).
val string : ?gen:char t -> string tBuilds a string generator. String size is generated by
nat. Accepts an optional character generator (the default ischar). See alsostring_ofandstring_readablefor versions without optional parameters.
val string_of : char t -> string tBuilds a string generator using the given character generator.
- since
- 0.11
val string_readable : string tBuilds a string generator using the
charcharacter generator.- since
- 0.11
val small_string : ?gen:char t -> string tBuilds a string generator, length is
small_natAccepts an optional character generator (the default ischar).
val flatten_l : 'a t list -> 'a list tGenerate a list of elements from individual generators
- since
- 0.13
val flatten_a : 'a t array -> 'a array tGenerate an array of elements from individual generators
- since
- 0.13
val flatten_res : ('a t, 'e) Stdlib.result -> ('a, 'e) Stdlib.result tGenerate a result from
Ok g, an error fromError e- since
- 0.13
val sized : 'a sized -> 'a tCreates a generator from a size-bounded generator by first generating a size using
natand passing the result to the size-bounded generator.
val sized_size : int t -> 'a sized -> 'a tCreates a generator from a size-bounded generator by first generating a size using the integer generator and passing the result to the size-bounded generator.
- since
- 0.5
val fix : (('a -> 'b t) -> 'a -> 'b t) -> 'a -> 'b tParametrized fixpoint combinator for generating recursive values.
The fixpoint is parametrized over an arbitrary state ('a), and the fixpoint computation may change the value of this state in the recursive calls.
In particular, this can be used for size-bounded generators ('a is int). The passed size-parameter should decrease to ensure termination.
val generate : ?rand:Stdlib.Random.State.t -> n:int -> 'a t -> 'a listgenerate ~n ggeneratesninstances ofg.
val generate1 : ?rand:Stdlib.Random.State.t -> 'a t -> 'agenerate1 ggenerates one instance ofg.