package core

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val create : (size:Base.Int.t -> random:Splittable_random.State.t -> 'a) -> 'a Generator.t
val generate : 'a Generator.t -> size:Base.Int.t -> random:Splittable_random.State.t -> 'a
val (>>=) : 'a Generator.t -> ('a -> 'b Generator.t) -> 'b Generator.t
module Monad_infix : sig ... end
val bind : 'a Generator.t -> f:('a -> 'b Generator.t) -> 'b Generator.t
val join : 'a Generator.t Generator.t -> 'a Generator.t
val ignore_m : 'a Generator.t -> unit Generator.t
val return : 'a -> 'a Generator.t
val map : 'a Generator.t -> f:('a -> 'b) -> 'b Generator.t
val both : 'a Generator.t -> 'b Generator.t -> ('a * 'b) Generator.t
val (<*>) : ('a -> 'b) Generator.t -> 'a Generator.t -> 'b Generator.t
val (<*) : 'a Generator.t -> unit Generator.t -> 'a Generator.t
val (*>) : unit Generator.t -> 'a Generator.t -> 'a Generator.t
val (>>|) : 'a Generator.t -> ('a -> 'b) -> 'b Generator.t
val apply : ('a -> 'b) Generator.t -> 'a Generator.t -> 'b Generator.t
val map2 : 'a Generator.t -> 'b Generator.t -> f:('a -> 'b -> 'c) -> 'c Generator.t
val map3 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> f:('a -> 'b -> 'c -> 'd) -> 'd Generator.t
val all : 'a Generator.t list -> 'a list Generator.t
val all_unit : unit Generator.t list -> unit Generator.t
module Applicative_infix : sig ... end
val size : Base.Int.t Generator.t

size = create (fun ~size _ -> size)

val with_size : 'a Generator.t -> size:Base.Int.t -> 'a Generator.t

with_size t ~size = create (fun ~size:_ random -> generate t ~size random)

val bool : Base.Bool.t Generator.t
val char : Base.Char.t Generator.t
val char_digit : Base.Char.t Generator.t
val char_lowercase : Base.Char.t Generator.t
val char_uppercase : Base.Char.t Generator.t
val char_alpha : Base.Char.t Generator.t
val char_alphanum : Base.Char.t Generator.t
val char_print : Base.Char.t Generator.t
val char_whitespace : Base.Char.t Generator.t
val singleton : 'a -> 'a Generator.t
val doubleton : 'a -> 'a -> 'a Generator.t
val of_list : 'a Base.List.t -> 'a Generator.t

Produce any of the given values, weighted equally.

of_list [ v1 ; ... ; vN ] = union [ singleton v1 ; ... ; singleton vN ]

val union : 'a Generator.t Base.List.t -> 'a Generator.t

Combine arbitary generators, weighted equally.

union [ g1 ; ... ; gN ] = weighted_union [ (1.0, g1) ; ... ; (1.0, gN) ]

val of_sequence : p:Base.Float.t -> 'a Sequence.t -> 'a Generator.t

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 tuple2 : 'a Generator.t -> 'b Generator.t -> ('a * 'b) Generator.t
val tuple3 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> ('a * 'b * 'c) Generator.t
val tuple4 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> 'd Generator.t -> ('a * 'b * 'c * 'd) Generator.t
val tuple5 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> 'd Generator.t -> 'e Generator.t -> ('a * 'b * 'c * 'd * 'e) Generator.t
val tuple6 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> 'd Generator.t -> 'e Generator.t -> 'f Generator.t -> ('a * 'b * 'c * 'd * 'e * 'f) Generator.t
val variant2 : 'a Generator.t -> 'b Generator.t -> [ `A of 'a | `B of 'b ] Generator.t
val variant3 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> [ `A of 'a | `B of 'b | `C of 'c ] Generator.t
val variant4 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> 'd Generator.t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd ] Generator.t
val variant5 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> 'd Generator.t -> 'e Generator.t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e ] Generator.t
val variant6 : 'a Generator.t -> 'b Generator.t -> 'c Generator.t -> 'd Generator.t -> 'e Generator.t -> 'f Generator.t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e | `F of 'f ] Generator.t
val geometric : Base.Int.t -> p:Base.Float.t -> Base.Int.t Generator.t

geometric init ~p produces a geometric distribution (think "radioactive decay") that produces init with probability p, and otherwise effectively recursively chooses from geometric (init+1) ~p. The implementation can be more efficient than actual recursion. Must satisfy 0. <= p && p <= 1..

val small_non_negative_int : Base.Int.t Generator.t

small_non_negative_int produces a non-negative int of a tractable size, e.g. allocating a value of this size should not run out of memory.

val small_positive_int : Base.Int.t Generator.t

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 : 'a Base_quickcheck.Observer.t -> 'b Generator.t -> ('a -> 'b) Generator.t

Generators for functions; take observers for inputs and a generator for outputs.

val compare_fn : 'a Base_quickcheck.Observer.t -> ('a -> 'a -> Base.Int.t) Generator.t

Generator for comparison functions; result is guaranteed to be a partial order.

val equal_fn : 'a Base_quickcheck.Observer.t -> ('a -> 'a -> Base.Bool.t) Generator.t

Generator for equality functions; result is guaranteed to be an equivalence relation.

val filter_map : 'a Generator.t -> f:('a -> 'b Base.Option.t) -> 'b Generator.t

filter_map t ~f produces y for every x in t such that f x = Some y.

val filter : 'a Generator.t -> f:('a -> Base.Bool.t) -> 'a Generator.t

filter t ~f produces every x in t such that f x = true.

val recursive_union : 'a Generator.t Base.List.t -> f:('a Generator.t -> 'a Generator.t Base.List.t) -> 'a Generator.t

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 * 'a Generator.t) Base.List.t -> f:('a Generator.t -> (Base.Float.t * 'a Generator.t) Base.List.t) -> 'a Generator.t

Like recursive_union, with the addition of non-uniform weights for each clause.

val fixed_point : ('a Generator.t -> 'a Generator.t) -> 'a Generator.t

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 * 'a Generator.t) Base.List.t -> 'a Generator.t

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.

val of_fun : (Base.Unit.t -> 'a Generator.t) -> 'a Generator.t

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.

val list : 'a Generator.t -> 'a Base.List.t Generator.t

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.

val list_non_empty : 'a Generator.t -> 'a Base.List.t Generator.t
val list_with_length : Base.Int.t -> 'a Generator.t -> 'a Base.List.t Generator.t
OCaml

Innovation. Community. Security.