package base_quickcheck

  1. Overview
  2. Docs

Source file test_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
open! Base

module type S = sig
  type t [@@deriving sexp_of]

  val quickcheck_generator : t Generator.t
  val quickcheck_shrinker : t Shrinker.t
end

module type Test = sig
  module type S = S

  module Config : sig
    module Seed : sig
      type t =
        | Nondeterministic
        | Deterministic of string
      [@@deriving sexp_of]
    end

    type t =
      { seed : Seed.t
      (** [seed] is used to initialize the pseudo-random state before running tests of a
          property. *)
      ; test_count : int
      (** [test_count] determines how many random values to test a property with. *)
      ; shrink_count : int
      (** [shrink_count] determines the maximum number of attempts to find a smaller
          version of a value that fails a test. *)
      ; sizes : int Sequence.t
      (** [sizes] determines the progression of value sizes to generate while testing.
          Testing fails if [sizes] is not of length at least [test_count]. *)
      }
    [@@deriving fields, sexp_of]
  end

  (** Defaults to a deterministic seed, [shrink_count] and [test_count] of 10_000 each,
      and sizes ranging from 0 to 30. *)
  val default_config : Config.t

  (** Tests the property [f], failing if it raises or returns [Error _]. Tests [f] first
      with any [examples], then with values from the given generator. Only random values
      count toward the [test_count] total, not values from [examples]. *)
  val run
    :  f:('a -> unit Or_error.t)
    -> ?config:Config.t (** defaults to [default_config] *)
    -> ?examples:'a list (** defaults to the empty list *)
    -> (module S with type t = 'a)
    -> unit Or_error.t

  (** Like [run], but raises on failure. *)
  val run_exn
    :  f:('a -> unit)
    -> ?config:Config.t (** defaults to [default_config] *)
    -> ?examples:'a list (** defaults to the empty list *)
    -> (module S with type t = 'a)
    -> unit

  (** Calls [f] with the sequence of values that [run] would get in the same
      configuration. *)
  val with_sample
    :  f:('a Sequence.t -> unit Or_error.t)
    -> ?config:Config.t (** defaults to [default_config] *)
    -> ?examples:'a list (** defaults to the empty list *)
    -> 'a Generator.t
    -> unit Or_error.t

  (** Like [with_sample], but raises on failure. *)
  val with_sample_exn
    :  f:('a Sequence.t -> unit)
    -> ?config:Config.t (** defaults to [default_config] *)
    -> ?examples:'a list (** defaults to the empty list *)
    -> 'a Generator.t
    -> unit
end
OCaml

Innovation. Community. Security.