package qtest

  1. Overview
  2. Docs
On This Page
  1. Generate Values
Legend:
Library
Module
Module type
Parameter
Class
Class type

Generate 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 (>|=) : 'a t -> ('a -> 'b) -> 'b t
val oneof : 'a t list -> 'a t
val oneofl : 'a list -> 'a t
val frequency : (int * 'a t) list -> 'a t
val frequencyl : (int * 'a) list -> 'a 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 array : 'a t -> 'a array t
val array_size : int t -> 'a t -> 'a array t
val pair : 'a t -> 'b t -> ('a * 'b) t
val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) 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 sized : 'a sized -> 'a t
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 = Quickcheck.Gen.(sized @@ fix
  (fun self n st -> match n with
    | 0 -> map leaf nat st
    | n ->
      frequency
        [1, map leaf nat;
         2, map2 node (self (n/2)) (self (n/2))]
         st
    ))
OCaml

Innovation. Community. Security.