package qcheck

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type 'a t = Random.State.t -> 'a

A generator of arbitrary values of type 'a

val return : 'a -> 'a t

Return always the same value (e.g. 4)

val int : int -> int t

Any integer between 0 (inclusive) and the given higher bound (exclusive)

val int_range : start:int -> stop:int -> int t
val (--) : int -> int -> int t

Infix synonym for int_range

val small_int : int t

Ints lower than 100

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

split_int gen generates a number n from gen, and returns i, j where i + j = n

val bool : bool t

Arbitrary boolean

val char : char t

A (printable) char

val alpha : char t

Alphabetic char

val float : float -> float t

Random float

val string : string t

Random strings of small length

val string_len : int t -> string t

String of random length

val map : 'a t -> ('a -> 'b) -> 'b t

Transform an arbitrary into another

val map' : ('a -> 'b) -> 'a t -> 'b t
  • since 0.3
val list : ?len:int t -> 'a t -> 'a list t

List of arbitrary length. Default len is between 0 and 10.

val opt : 'a t -> 'a option t

May return a value, or None

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 list_repeat : int -> 'a t -> 'a list t

Lists of given length exactly

val array : ?len:int t -> 'a t -> 'a array t

Random array of random length

val array_repeat : int -> 'a t -> 'a array t

Random array of given length

val among : 'a list -> 'a t

Choose an element among those of the list

val among_array : 'a array -> 'a t

Choose in the array

val shuffle : 'a array -> unit t

Shuffle the array in place

  • since 0.3
val choose : 'a t list -> 'a t

Choice among a list generators

val (|||) : 'a t -> 'a t -> 'a t

Choice among two generators. a ||| b is the same as choose [a;b].

val fix : ?max:int -> base:'a t -> ('a t -> 'a t) -> 'a t

Recursive arbitrary values. The optional value max defines the maximal depth, if needed (default 15). base is the base case.

val fix_depth : depth:int t -> base:'a t -> ('a t -> 'a t) -> 'a t

Recursive values of at most given random depth

type 'a recursive_case = [
  1. | `Base of 'a t
  2. | `Base_fuel of int -> 'a t
  3. | `Rec of (int -> 'a list t) -> 'a t
]

What is a recursive case for a fueled fixpoint?

val fix_fuel : 'a recursive_case list -> int -> 'a option t

fix_fuel l fuel consumes fuel in recursive subcases. The idea is that l contains one or more recursive builders, such that every f in l is given a function f' : int -> 'a list t, to call with an integer n so as to obtain n recursive subcases. The function f' MUST be called exactly once per case f in l..

Example:

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

let leaf_ x = Leaf x;;
let node_ x y = Node (x,y);;

let rand_tree =
   fix_fuel [
     `Base (small_int >|= leaf_);
     `Rec (fun self ->
        self 2 >>= function [x;y] ->
        return (node_ x y))
    ];;

generate (rand_tree 20);;  (* generate trees with 20 nodes *)
  • since 0.3
val lift : ('a -> 'b) -> 'a t -> 'b t
val lift2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
val lift3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd t
val lift4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind

val (>|=) : 'a t -> ('a -> 'b) -> 'b t
  • since 0.3
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
  • since 0.3
val pure : 'a -> 'a t
  • since 0.3
val retry : 'a option t -> 'a t

Generate until a Some value is returned

val generate : ?n:int -> ?rand:Random.State.t -> 'a t -> 'a list

Generate n random values of the given type

OCaml

Innovation. Community. Security.