package qcheck

  1. Overview
  2. Docs

Generate Random Values

type 'a t = Random.State.t -> 'a

A random generator for values of type 'a

type 'a sized = int -> Random.State.t -> 'a

Random generator with a size bound

val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val map : ('a -> 'b) -> 'a t -> 'b t
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
val map3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd t
val map_keep_input : ('a -> 'b) -> 'a t -> ('a * 'b) t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
val oneof : 'a t list -> 'a t
val oneofl : 'a list -> 'a t
val oneofa : 'a array -> 'a t
val frequency : (int * 'a t) list -> 'a t
val frequencyl : (int * 'a) list -> 'a t
val frequencya : (int * 'a) array -> 'a t
val shuffle_a : 'a array -> unit t

Shuffle the array in place

val shuffle_l : 'a list -> 'a list t
val unit : unit t
val bool : bool t
val float : float t
val pfloat : float t

positive float

val nfloat : float t

positive float

negative float

val nat : int t

small nat

val neg_int : int t

small nat

negative int

val pint : int t

negative int

positive uniform int

val int : int t

positive uniform int

uniform int

val small_int : int t

uniform int

Synonym to nat

val int_bound : int -> int t

Synonym to nat

Uniform within 0... bound

val int_range : int -> int -> int t

Uniform within 0... bound

Uniform within low,high

val (--) : int -> int -> int t

Uniform within low,high

Synonym to int_range

val ui32 : int32 t
val ui64 : int64 t
val list : 'a t -> 'a list t
val list_size : int t -> 'a t -> 'a list t
val list_repeat : int -> 'a t -> 'a list t
val array : 'a t -> 'a array t
val array_size : int t -> 'a t -> 'a array t
val array_repeat : int -> 'a t -> 'a array t
val opt : 'a t -> 'a option t
val pair : 'a t -> 'b t -> ('a * 'b) t
val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val char : char t
val printable : char t
val numeral : char t
val string_size : ?gen:char t -> int t -> string t
val string : ?gen:char t -> string t
val small_string : ?gen:char t -> string t
val join : 'a t t -> 'a t
  • since NEXT_RELEASE
val sized : 'a sized -> 'a t
val sized_size : int t -> 'a sized -> 'a t
  • since NEXT_RELEASE
val fix : ('a sized -> 'a sized) -> 'a sized

Fixpoint; size decreases

Example:

type tree = Leaf of int | Node of tree * tree

let leaf x = Leaf x
let node x y = Node (x,y)

let g = QCheck.Gen.(sized @@ fix
  (fun self n -> match n with
    | 0 -> map leaf nat
    | n ->
      frequency
        [1, map leaf nat;
         2, map2 node (self (n/2)) (self (n/2))]
    ))
val generate : ?rand:Random.State.t -> n:int -> 'a t -> 'a list

generate ~n g generates n instances of g

val generate1 : ?rand:Random.State.t -> 'a t -> 'a

generate1 g generates one instance of g

OCaml

Innovation. Community. Security.