Source file quickcheck_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
(** Quickcheck is a library that uses predicate-based tests and pseudo-random inputs to
automate testing.
For examples see {e lib/base_quickcheck/examples}.
*)
open! Import
open Base_quickcheck
module type Generator = sig
(** An ['a t] a generates values of type ['a] with a specific probability distribution.
Generators are constructed as functions that produce a value from a splittable
pseudorandom number generator (see [Splittable_random]), with a [~size] argument
threaded through to bound the size of the result value and the depth of recursion.
There is no prescribed semantics for [size] other than that it must be non-negative.
Non-recursive generators are free to ignore it, and recursive generators need only
make sure it decreases in recursive calls and that recursion bottoms out at 0. *)
type +'a t = 'a Generator.t
val create : (size:int -> random:Splittable_random.t -> 'a) -> 'a t
val generate : 'a t -> size:int -> random:Splittable_random.t -> 'a
(** Generators form a monad. [t1 >>= fun x -> t2] replaces each value [x] in [t1] with
the values in [t2]; each value's probability is the product of its probability in
[t1] and [t2].
This can be used to form distributions of related values. For instance, the
following expression creates a distribution of pairs [x,y] where [x <= y]:
{[
Int.gen
>>= fun x ->
Int.gen_incl x Int.max_value
>>| fun y ->
x, y
]}
*)
include Monad.S with type 'a t := 'a t
include Applicative.S with type 'a t := 'a t
(** [size = create (fun ~size _ -> size)] *)
val size : int t
(** [with_size t ~size = create (fun ~size:_ random -> generate t ~size random)] *)
val with_size : 'a t -> size:int -> 'a t
val bool : bool t
val char : char t
val char_digit : char t
val char_lowercase : char t
val char_uppercase : char t
val char_alpha : char t
val char_alphanum : char t
val char_print : char t
val char_whitespace : char t
val singleton : 'a -> 'a t
val doubleton : 'a -> 'a -> 'a t
(** Produce any of the given values, weighted equally.
[of_list [ v1 ; ... ; vN ] = union [ singleton v1 ; ... ; singleton vN ]] *)
val of_list : 'a list -> 'a t
(** Combine arbitrary generators, weighted equally.
[ union [ g1 ; ... ; gN ] = weighted_union [ (1.0, g1) ; ... ; (1.0, gN) ] ] *)
val union : 'a t list -> 'a 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 of_sequence : p:float -> 'a Sequence.t -> 'a t
val tuple2 : 'a t -> 'b t -> ('a * 'b) t
val tuple3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val tuple4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val tuple5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t
val tuple6
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> 'f t
-> ('a * 'b * 'c * 'd * 'e * 'f) t
val variant2 : 'a t -> 'b t -> [ `A of 'a | `B of 'b ] t
val variant3 : 'a t -> 'b t -> 'c t -> [ `A of 'a | `B of 'b | `C of 'c ] t
val variant4
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd ] t
val variant5
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e ] t
val variant6
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> 'f t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e | `F of 'f ] 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 geometric : int -> p:float -> int 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_non_negative_int : int 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 small_positive_int : int t
(** Generators for functions; take observers for inputs and a generator for outputs. *)
val fn : 'a Observer.t -> 'b t -> ('a -> 'b) t
val fn2 : 'a Observer.t -> 'b Observer.t -> 'c t -> ('a -> 'b -> 'c) t
val fn3
: 'a Observer.t
-> 'b Observer.t
-> 'c Observer.t
-> 'd t
-> ('a -> 'b -> 'c -> 'd) t
val fn4
: 'a Observer.t
-> 'b Observer.t
-> 'c Observer.t
-> 'd Observer.t
-> 'e t
-> ('a -> 'b -> 'c -> 'd -> 'e) t
val fn5
: 'a Observer.t
-> 'b Observer.t
-> 'c Observer.t
-> 'd Observer.t
-> 'e Observer.t
-> 'f t
-> ('a -> 'b -> 'c -> 'd -> 'e -> 'f) t
val fn6
: 'a Observer.t
-> 'b Observer.t
-> 'c Observer.t
-> 'd Observer.t
-> 'e Observer.t
-> 'f Observer.t
-> 'g t
-> ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) t
(** Generator for comparison functions; result is guaranteed to be a partial order. *)
val compare_fn : 'a Observer.t -> ('a -> 'a -> int) t
(** Generator for equality functions; result is guaranteed to be an equivalence
relation. *)
val equal_fn : 'a Observer.t -> ('a -> 'a -> bool) t
(** [filter_map t ~f] produces [y] for every [x] in [t] such that [f x = Some y]. *)
val filter_map : 'a t -> f:('a -> 'b option) -> 'b t
(** [filter t ~f] produces every [x] in [t] such that [f x = true]. *)
val filter : 'a t -> f:('a -> bool) -> 'a 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 recursive_union : 'a t list -> f:('a t -> 'a t list) -> 'a t
(** Like [recursive_union], with the addition of non-uniform weights for each clause. *)
val weighted_recursive_union
: (float * 'a t) list
-> f:('a t -> (float * 'a t) list)
-> 'a 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 fixed_point : ('a t -> 'a t) -> 'a 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 weighted_union : (float * 'a t) list -> 'a 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 of_fun : (unit -> 'a t) -> 'a 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 : 'a t -> 'a list t
val list_non_empty : 'a t -> 'a list t
val list_with_length : int -> 'a t -> 'a list t
end
module type Deriving_hash = sig
type t [@@deriving hash]
end
module type Observer = sig
(** An ['a Quickcheck.Observer.t] represents a hash function on ['a]. Observers are
used to construct distributions of random functions; see [Quickcheck.Generator.fn].
Like generators, observers have a [~size] argument that is threaded through to bound
the depth of recursion in potentially infinite cases. For finite values, [size] can
be ignored.
For hashable types, one can construct an observer using [of_hash]. For other types,
use the built-in observers and observer combinators below, or use [create] directly.
*)
type -'a t = 'a Observer.t
val create : ('a -> size:int -> hash:Hash.state -> Hash.state) -> 'a t
val observe : 'a t -> 'a -> size:int -> hash:Hash.state -> Hash.state
(** [of_hash] creates an observer for any hashable type. *)
val of_hash : (module Deriving_hash with type t = 'a) -> 'a t
val bool : bool t
val char : char t
(** [doubleton f] maps values to two "buckets" (as described in [t] above),
depending on whether they satisfy [f]. *)
val doubleton : ('a -> bool) -> 'a t
(** [enum n ~f] maps values to [n] buckets, where [f] produces the index for a bucket
from [0] to [n-1] for each value. *)
val enum : int -> f:('a -> int) -> 'a t
(** [of_list list ~equal] maps values in [list] to separate buckets, and compares
observed values to the elements of [list] using [equal]. *)
val of_list : 'a list -> equal:('a -> 'a -> bool) -> 'a t
(** Fixed point observer for recursive types. For example:
{[
let sexp_obs =
fixed_point (fun sexp_t ->
unmap (variant2 string (list sexp_t))
~f:(function
| Sexp.Atom atom -> `A atom
| Sexp.List list -> `B list))
]}
*)
val fixed_point : ('a t -> 'a t) -> 'a t
val variant2 : 'a t -> 'b t -> [ `A of 'a | `B of 'b ] t
val variant3 : 'a t -> 'b t -> 'c t -> [ `A of 'a | `B of 'b | `C of 'c ] t
val variant4
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd ] t
val variant5
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e ] t
val variant6
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> 'f t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e | `F of 'f ] t
(** [of_predicate t1 t2 ~f] combines [t1] and [t2], where [t1] observes values that
satisfy [f] and [t2] observes values that do not satisfy [f]. *)
val of_predicate : 'a t -> 'a t -> f:('a -> bool) -> 'a t
(** [comparison ~compare ~eq ~lt ~gt] combines observers [lt] and [gt], where [lt]
observes values less than [eq] according to [compare], and [gt] observes values
greater than [eq] according to [compare]. *)
val comparison : compare:('a -> 'a -> int) -> eq:'a -> lt:'a t -> gt:'a t -> 'a t
(** maps all values to a single bucket. *)
val singleton : unit -> _ t
(** [unmap t ~f] applies [f] to values before observing them using [t]. *)
val unmap : 'a t -> f:('b -> 'a) -> 'b t
val tuple2 : 'a t -> 'b t -> ('a * 'b) t
val tuple3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val tuple4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val tuple5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t
val tuple6
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> 'f t
-> ('a * 'b * 'c * 'd * 'e * 'f) t
(** Observer for function type. [fn gen t] observes a function by generating random
inputs from [gen], applying the function, and observing the output using [t]. *)
val fn : 'a Generator.t -> 'b t -> ('a -> 'b) t
(** [of_fun f] produces an observer that lazily applies [f].
It is recommended that [f] should not do a lot of expensive work and should not be
memoized. Instead, spread out the work of generating an observer over many [of_fun]
calls combined with, e.g., [variant] or [tuple]. This allows lazily generated
observers to be garbage collected after each test and the relevant portions cheaply
recomputed in subsequent tests, rather than accumulating without bound over time. *)
val of_fun : (unit -> 'a t) -> 'a t
end
module type Shrinker = sig
(** A ['a Quickcheck.Shrinker.t] takes a value of type ['a] and produces similar values
that are smaller by some metric.
The defined shrinkers generally try to make a single change for each value based on
the assumption that the first resulting value that preserves the desired property
will be used to create another sequence of shrunk values.
Within [Quickcheck.test] the shrinker is used as described above.
Shrinkers aim to aid understanding of what's causing an error by reducing the input
down to just the elements making it fail. The default shrinkers remove elements of
compound structures, but leave atomic values alone. For example, the default list
shrinker tries removing elements from the list, but the default int shrinker does
nothing. This default strikes a balance between performance and precision.
Individual tests can use different shrinking behavior as necessary.
See lib/base_quickcheck/examples/shrinker_example.ml for some example shrinkers.
*)
type 'a t = 'a Shrinker.t
val shrink : 'a t -> 'a -> 'a Sequence.t
val create : ('a -> 'a Sequence.t) -> 'a t
val empty : unit -> 'a t
val bool : bool t
val char : char t
val map : 'a t -> f:('a -> 'b) -> f_inverse:('b -> 'a) -> 'b t
val filter : 'a t -> f:('a -> bool) -> 'a t
(** Filters and maps according to [f], and provides input to [t] via [f_inverse]. Only
the [f] direction produces options, intentionally. *)
val filter_map : 'a t -> f:('a -> 'b option) -> f_inverse:('b -> 'a) -> 'b t
val tuple2 : 'a t -> 'b t -> ('a * 'b) t
val tuple3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val tuple4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val tuple5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t
val tuple6
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> 'f t
-> ('a * 'b * 'c * 'd * 'e * 'f) t
val variant2 : 'a t -> 'b t -> [ `A of 'a | `B of 'b ] t
val variant3 : 'a t -> 'b t -> 'c t -> [ `A of 'a | `B of 'b | `C of 'c ] t
val variant4
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd ] t
val variant5
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e ] t
val variant6
: 'a t
-> 'b t
-> 'c t
-> 'd t
-> 'e t
-> 'f t
-> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e | `F of 'f ] t
(** [fixed_point] assists with shrinking structures recursively. Its advantage over
directly using [rec] in the definition of the shrinker is that it causes lazy
evaluation where possible. *)
val fixed_point : ('a t -> 'a t) -> 'a t
end
module type S = sig
type t
val quickcheck_generator : t Generator.t
val quickcheck_observer : t Observer.t
val quickcheck_shrinker : t Shrinker.t
end
module type S1 = sig
type 'a t
val quickcheck_generator : 'a Generator.t -> 'a t Generator.t
val quickcheck_observer : 'a Observer.t -> 'a t Observer.t
val quickcheck_shrinker : 'a Shrinker.t -> 'a t Shrinker.t
end
module type S2 = sig
type ('a, 'b) t
val quickcheck_generator : 'a Generator.t -> 'b Generator.t -> ('a, 'b) t Generator.t
val quickcheck_observer : 'a Observer.t -> 'b Observer.t -> ('a, 'b) t Observer.t
val quickcheck_shrinker : 'a Shrinker.t -> 'b Shrinker.t -> ('a, 'b) t Shrinker.t
end
module type S_range = sig
include S
(** [gen_incl lower_bound upper_bound] produces values between [lower_bound] and
[upper_bound], inclusive. It uses an ad hoc distribution that stresses boundary
conditions more often than a uniform distribution, while still able to produce any
value in the range. Raises if [lower_bound > upper_bound]. *)
val gen_incl : t -> t -> t Generator.t
(** [gen_uniform_incl lower_bound upper_bound] produces a generator for values uniformly
distributed between [lower_bound] and [upper_bound], inclusive. Raises if
[lower_bound > upper_bound]. *)
val gen_uniform_incl : t -> t -> t Generator.t
end
module type S_int = sig
include S_range
(** [gen_log_uniform_incl lower_bound upper_bound] produces a generator for values
between [lower_bound] and [upper_bound], inclusive, where the number of bits used to
represent the value is uniformly distributed. Raises if [(lower_bound < 0) ||
(lower_bound > upper_bound)]. *)
val gen_log_uniform_incl : t -> t -> t Generator.t
(** [gen_log_incl lower_bound upper_bound] is like [gen_log_uniform_incl], but weighted
slightly more in favor of generating [lower_bound] and [upper_bound]
specifically. *)
val gen_log_incl : t -> t -> t Generator.t
end
(** [seed] specifies how to initialize a pseudo-random number generator. When multiple
tests share a deterministic seed, they each get a separate copy of the random
generator's state; random choices in one test do not affect those in another. The
nondeterministic seed causes a fresh random state to be generated nondeterministically
for each test. *)
type seed =
[ `Deterministic of string
| `Nondeterministic
]
type shrink_attempts =
[ `Exhaustive
| `Limit of int
]
module type Quickcheck_config = sig
(** [default_seed] is used initialize the pseudo-random generator that chooses random
values from generators, in each test that is not provided its own seed. *)
val default_seed : seed
(** [default_sizes] determines the default sequence of sizes used in generating
values. *)
val default_sizes : int Sequence.t
(** [default_trial_count] determines the number of trials per test, except in tests
that explicitly override it. *)
val default_trial_count : int
(** [default_can_generate_trial_count] determines the number of trials used in attempts
to generate satisfying values, except in tests that explicitly override it. *)
val default_can_generate_trial_count : int
(** [default_shrink_attempts] determines the number of attempts at shrinking
when running [test] or [iter] with [~shrinker] and without
[~shrink_attempts] *)
val default_shrink_attempts : shrink_attempts
end
module type Quickcheck_configured = sig
include Quickcheck_config
(** [random_value gen] produces a single value chosen from [gen] using [seed]. *)
val random_value : ?seed:seed -> ?size:int -> 'a Generator.t -> 'a
(** [iter gen ~f] runs [f] on up to [trials] different values generated by [gen]. It
stops successfully after [trials] successful trials or if [gen] runs out of values.
It raises an exception if [f] raises an exception. *)
val iter
: ?seed:seed
-> ?sizes:int Sequence.t
-> ?trials:int
-> 'a Generator.t
-> f:('a -> unit)
-> unit
(** [test gen ~f] is like [iter], with optional concrete [examples] that are tested
before values from [gen], and additional information provided on failure. If [f]
raises an exception and [sexp_of] is provided, the exception is re-raised with a
description of the random input that triggered the failure. If [f] raises an
exception and [shrinker] is provided, it will be used to attempt to shrink the value
that caused the exception with re-raising behaving the same as for unshrunk inputs.
*)
val test
: ?seed:seed
-> ?sizes:int Sequence.t
-> ?trials:int
-> ?shrinker:'a Shrinker.t
-> ?shrink_attempts:shrink_attempts
-> ?sexp_of:('a -> Base.Sexp.t)
-> ?examples:'a list
-> 'a Generator.t
-> f:('a -> unit)
-> unit
(** [test_or_error] is like [test], except failure is determined using [Or_error.t]. Any
exceptions raised by [f] are also treated as failures. *)
val test_or_error
: ?seed:seed
-> ?sizes:int Sequence.t
-> ?trials:int
-> ?shrinker:'a Shrinker.t
-> ?shrink_attempts:shrink_attempts
-> ?sexp_of:('a -> Base.Sexp.t)
-> ?examples:'a list
-> 'a Generator.t
-> f:('a -> unit Or_error.t)
-> unit Or_error.t
(** [test_can_generate gen ~f] is useful for testing [gen] values, to make sure they can
generate useful examples. It tests [gen] by generating up to [trials] values and
passing them to [f]. Once a value satisfies [f], the iteration stops. If no values
satisfy [f], [test_can_generate] raises an exception. If [sexp_of] is provided, the
exception includes all of the generated values. *)
val test_can_generate
: ?seed:seed
-> ?sizes:int Sequence.t
-> ?trials:int
-> ?sexp_of:('a -> Base.Sexp.t)
-> 'a Generator.t
-> f:('a -> bool)
-> unit
(** [test_distinct_values gen] is useful for testing [gen] values, to make sure they
create sufficient distinct values. It tests [gen] by generating up to [trials]
values and making sure at least [distinct_values] of the resulting values are unique
with respect to [compare]. If too few distinct values are generated,
[test_distinct_values] raises an exception. If [sexp_of] is provided, the exception
includes the values generated. *)
val test_distinct_values
: ?seed:seed
-> ?sizes:int Sequence.t
-> ?sexp_of:('a -> Base.Sexp.t)
-> 'a Generator.t
-> trials:int
-> distinct_values:int
-> compare:('a -> 'a -> int)
-> unit
(** [random_sequence ~seed gen] produces a sequence of values chosen from [gen]. *)
val random_sequence
: ?seed:seed
-> ?sizes:int Sequence.t
-> 'a Generator.t
-> 'a Sequence.t
end
(** Includes [Let_syntax] from [Monad.Syntax]. Sets [Open_on_rhs] to be all of
[Generator], except that it does not shadow [Let_syntax] itself. Both [Generator] and
[Open_on_rhs] are meant to be destructively assigned. *)
module type Syntax = sig
module Generator : Generator
module Open_on_rhs :
Generator
with type 'a t := 'a Generator.t
and module Let_syntax := Generator.Let_syntax
include
Monad.Syntax
with type 'a t := 'a Generator.t
and module Let_syntax.Let_syntax.Open_on_rhs = Open_on_rhs
end
module type Quickcheck = sig
type nonrec seed = seed
type nonrec shrink_attempts = shrink_attempts
module Generator : Generator
module Observer : Observer
module Shrinker : Shrinker
module type S = S
module type S1 = S1
module type S2 = S2
module type S_int = S_int
module type S_range = S_range
include Syntax with module Generator := Generator and module Open_on_rhs := Generator
module type Quickcheck_config = Quickcheck_config
module type Quickcheck_configured = Quickcheck_configured
(** with a default config *)
include Quickcheck_configured
module Configure (Config : Quickcheck_config) : Quickcheck_configured
end