mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
by default, use a constant random seed
so that qcheck tests are repeatable
This commit is contained in:
parent
9003d26a60
commit
e4bc1277a8
2 changed files with 11 additions and 5 deletions
|
|
@ -218,7 +218,10 @@ type 'a result =
|
||||||
| Failed of 'a list
|
| Failed of 'a list
|
||||||
| Error of exn
|
| Error of exn
|
||||||
|
|
||||||
let check ?(rand=Random.State.make_self_init ()) ?(n=100) gen prop =
|
(* random seed, for repeatability of tests *)
|
||||||
|
let __seed = [| 89809344; 994326685; 290180182 |]
|
||||||
|
|
||||||
|
let check ?(rand=Random.State.make __seed) ?(n=100) gen prop =
|
||||||
let precond_failed = ref 0 in
|
let precond_failed = ref 0 in
|
||||||
let failures = ref [] in
|
let failures = ref [] in
|
||||||
try
|
try
|
||||||
|
|
@ -252,7 +255,7 @@ type test =
|
||||||
let mk_test ?(n=100) ?pp ?(name="<anon prop>") gen prop =
|
let mk_test ?(n=100) ?pp ?(name="<anon prop>") gen prop =
|
||||||
Test { prop; gen; name; n; pp; }
|
Test { prop; gen; name; n; pp; }
|
||||||
|
|
||||||
let run ?(out=stdout) ?(rand=Random.State.make_self_init()) (Test test) =
|
let run ?(out=stdout) ?(rand=Random.State.make __seed) (Test test) =
|
||||||
Printf.fprintf out "testing property %s...\n" test.name;
|
Printf.fprintf out "testing property %s...\n" test.name;
|
||||||
match check ~rand ~n:test.n test.gen test.prop with
|
match check ~rand ~n:test.n test.gen test.prop with
|
||||||
| Ok (n, prefail) ->
|
| Ok (n, prefail) ->
|
||||||
|
|
@ -276,7 +279,7 @@ type suite = test list
|
||||||
|
|
||||||
let flatten = List.flatten
|
let flatten = List.flatten
|
||||||
|
|
||||||
let run_tests ?(out=stdout) ?(rand=Random.State.make_self_init()) l =
|
let run_tests ?(out=stdout) ?(rand=Random.State.make __seed) l =
|
||||||
let start = Unix.gettimeofday () in
|
let start = Unix.gettimeofday () in
|
||||||
let failed = ref 0 in
|
let failed = ref 0 in
|
||||||
Printf.fprintf out "check %d properties...\n" (List.length l);
|
Printf.fprintf out "check %d properties...\n" (List.length l);
|
||||||
|
|
|
||||||
|
|
@ -193,10 +193,13 @@ module Prop : sig
|
||||||
(** Precondition for a test *)
|
(** Precondition for a test *)
|
||||||
|
|
||||||
val assume : bool -> unit
|
val assume : bool -> unit
|
||||||
(** Assume the given precondition holds *)
|
(** Assume the given precondition holds. A test won't fail if the
|
||||||
|
precondition (the boolean argument) is false, but it will be
|
||||||
|
discarded. Running tests counts how many instances were
|
||||||
|
discarded for not satisfying preconditions. *)
|
||||||
|
|
||||||
val assume_lazy : bool lazy_t -> unit
|
val assume_lazy : bool lazy_t -> unit
|
||||||
(** Assume the given (lazy) precondition holds *)
|
(** Assume the given (lazy) precondition holds. See {!assume}. *)
|
||||||
|
|
||||||
val (&&&) : 'a t -> 'a t -> 'a t
|
val (&&&) : 'a t -> 'a t -> 'a t
|
||||||
(** Logical 'and' on tests *)
|
(** Logical 'and' on tests *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue