diff --git a/qCheck.ml b/qCheck.ml index f8993fa0..a776a771 100644 --- a/qCheck.ml +++ b/qCheck.ml @@ -218,7 +218,10 @@ type 'a result = | Failed of 'a list | 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 failures = ref [] in try @@ -252,7 +255,7 @@ type test = let mk_test ?(n=100) ?pp ?(name="") gen prop = 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; match check ~rand ~n:test.n test.gen test.prop with | Ok (n, prefail) -> @@ -276,7 +279,7 @@ type suite = test list 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 failed = ref 0 in Printf.fprintf out "check %d properties...\n" (List.length l); diff --git a/qCheck.mli b/qCheck.mli index bfa12eaa..c294623d 100644 --- a/qCheck.mli +++ b/qCheck.mli @@ -193,10 +193,13 @@ module Prop : sig (** Precondition for a test *) 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 - (** Assume the given (lazy) precondition holds *) + (** Assume the given (lazy) precondition holds. See {!assume}. *) val (&&&) : 'a t -> 'a t -> 'a t (** Logical 'and' on tests *)