package windtrap

  1. Overview
  2. Docs

Module Windtrap_prop.ArbitrarySource

Arbitrary values: generators bundled with printers. Used internally by Prop.check. Most users should use Testable values with Windtrap.prop instead.

Arbitrary values bundle generators with printers.

An Arbitrary.t combines a Gen.t with a printer for displaying counterexamples. Most users should use Testable values with Windtrap.prop instead of using this module directly.

Sourcetype 'a t

An arbitrary value: generator + printer.

Sourceval make : gen:'a Gen.t -> print:('a -> string) -> 'a t

make ~gen ~print creates an arbitrary from a generator and printer.

Sourceval gen : 'a t -> 'a Gen.t

gen arb returns the generator.

Sourceval print : 'a t -> 'a -> string

print arb x formats x for display.

Primitives

Sourceval unit : unit t

Generates ().

Sourceval bool : bool t

Generates true or false. Shrinks toward false.

Sourceval int : int t

Generates integers. Shrinks toward 0.

Sourceval int_range : int -> int -> int t

int_range low high generates integers in [low, high]. Shrinks toward value closest to 0 within range.

Sourceval int32 : int32 t

Generates 32-bit integers using full range. Shrinks toward 0l.

Sourceval int32_range : int32 -> int32 -> int32 t

int32_range low high generates 32-bit integers in [low, high]. Shrinks toward value closest to 0l within range.

Sourceval int64 : int64 t

Generates 64-bit integers using full range. Shrinks toward 0L.

Sourceval int64_range : int64 -> int64 -> int64 t

int64_range low high generates 64-bit integers in [low, high]. Shrinks toward value closest to 0L within range.

Sourceval float : float t

Generates floats. Shrinks toward 0.0.

Sourceval char : char t

Generates characters in the 0..255 byte range.

Sourceval string : string t

Generates strings of bytes.

Sourceval bytes : bytes t

Generates bytes.

Containers

Sourceval option : 'a t -> 'a option t

option arb generates None or Some x. Shrinks toward None.

Sourceval result : 'a t -> 'e t -> ('a, 'e) result t

result ok_arb err_arb generates Ok or Error.

Sourceval list : 'a t -> 'a list t

list arb generates lists. Shrinks toward empty and smaller elements.

Sourceval array : 'a t -> 'a array t

array arb generates arrays.

Sourceval pair : 'a t -> 'b t -> ('a * 'b) t

pair a b generates pairs.

Sourceval triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

triple a b c generates triples.

Sourceval quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

quad a b c d generates 4-tuples.

Choice

Sourceval oneof : 'a t list -> 'a t

oneof arbs picks one arbitrary uniformly at random. Uses the printer from the first element for all values.

Sourceval oneofl : print:('a -> string) -> 'a list -> 'a t

oneofl ~print xs picks one element uniformly at random. Shrinks toward earlier elements in the list.

Transformers

Sourceval map : print:('b -> string) -> ('a -> 'b) -> 'a t -> 'b t

map ~print f arb maps f over generated values. Requires new printer since type changes.

Sourceval filter : ('a -> bool) -> 'a t -> 'a t

filter p arb filters shrink candidates to only those satisfying p. This does not filter generated values; use Prop.assume to discard invalid test cases during generation.