diff --git a/CHANGELOG.md b/CHANGELOG.md index 28f5491f..b1bd17ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,49 @@ ## NEXT RELEASE (202?-??-??) -- ... +- Remove deprecated generator bindings: + - `QCheck.Gen`: + - `big_nat` `neg_int` `pint` `small_nat` `small_int` `small_signed_int` `int_pos_corners`, `int_corners` + - `ui32` `ui64` + - `pfloat` `nfloat` + - `opt` + - `string_readable` `small_string` + - `small_list` `list_repeat` + - `array_repeat` `small_array` + - `oneofl` `oneofa` + - `frequency` `frequencyl` `frequencya` + - `shuffle_a` `shuffle_l` `shuffle_w_l` + - `flatten_l` `flatten_a` `flatten_opt` `flatten_res` + - `QCheck.arbitrary`: + - `small_nat` `small_int` `small_signed_int` `pos_int` `neg_int` - `small_int_corners` + - `pos_float` `neg_float` + - `printable_char` `numeral_char` + - `string_gen_of_size` `string_gen` `small_string` `string_of_size` + `printable_string` `printable_string_of_size` `string_printable_of_size` `small_printable_string` `string_small_printable` + `numeral_string` `numeral string` `numeral_string_of_size` `string_numeral_of_size` + - `bytes_gen_of_size` `bytes_of_size` + - `small_list` `list_of_size` + - `array_of_size` + - `choose` `oneofl` `oneofa` + - `frequency` `frequencyl` `frequencya` + - `QCheck2.Gen`: + - `pint` `small_nat` `big_nat` `neg_int` `small_int` `small_signed_int` + `small_int_corners` `int_pos_corners` `int_corners` + - `ui32` `ui64` + - `pfloat` `nfloat` + - `opt` + - `small_string` + - `small_list` `list_repeat` + - `small_array` `array_repeat` + - `oneofl` `oneofa` + - `frequency` `frequencyl` `frequencya` + - `shuffle_a` `shuffle_l` `shuffle_w_l` + - `flatten_l` `flatten_a` `flatten_opt` `flatten_res` +- Other removed deprecated `QCheck2` bindings: + - `Print.comap` + - `Shrink.int_aggressive` + - `Observable.map` + - `TestResult.stats` `TestResult.warnings` `TestResult.collect` ## 0.91 (2025-12-21) diff --git a/src/core/QCheck.ml b/src/core/QCheck.ml index 4185db48..def7865a 100644 --- a/src/core/QCheck.ml +++ b/src/core/QCheck.ml @@ -138,9 +138,7 @@ module Gen = struct let oneof l st = List.nth l (Random.State.int st (List.length l)) st let oneof_list xs st = List.nth xs (Random.State.int st (List.length xs)) - let oneofl = oneof_list let oneof_array xs st = Array.get xs (Random.State.int st (Array.length xs)) - let oneofa = oneof_array let oneof_list_weighted l st = let sums = sum_int (List.map fst l) in @@ -151,21 +149,14 @@ module Gen = struct in aux 0 l - let frequencyl = oneof_list_weighted - let oneof_array_weighted a = oneof_list_weighted (Array.to_list a) - let frequencya = oneof_array_weighted - let oneof_weighted l st = oneof_list_weighted l st st - let frequency = oneof_weighted - let int_pos_small st = let p = RS.float st 1. in if p < 0.75 then RS.int st 10 else RS.int st 100 let nat_small = int_pos_small - let small_nat = int_pos_small (* natural number generator *) let nat st = @@ -177,11 +168,6 @@ module Gen = struct let int_pos_mid = nat - let big_nat st = - let p = RS.float st 1. in - if p < 0.75 then nat st - else RS.int st 1_000_000 - let unit _st = () let bool st = RS.bool st @@ -200,9 +186,6 @@ module Gen = struct let float_pos st = abs_float (float st) let float_neg st = -.(float_pos st) - let pfloat = float_pos - let nfloat = float_neg - let float_bound_inclusive bound st = RS.float st bound let float_bound_exclusive bound st = @@ -225,15 +208,11 @@ module Gen = struct let exponential = float_exp - let neg_int st = -(nat st) - let option ?(ratio = 0.85) f st = let p = RS.float st 1. in if p < (1.0 -. ratio) then None else Some (f st) - let opt = option - let result ?(ratio = 0.75) vg eg st = let p = RS.float st 1. in if p < (1.0 -. ratio) @@ -256,8 +235,6 @@ module Gen = struct let right = RS.bits st in left lor middle lor right - let pint = int_pos - let int_neg st = -(int_pos st)-1 let int st = if RS.bool st then - (int_pos st) - 1 else int_pos st @@ -284,17 +261,11 @@ module Gen = struct let (--) = int_range - (* NOTE: we keep this alias to not break code that uses [small_int] - for sizes of strings, arrays, etc. *) - let small_int = small_nat - let int_small st = if bool st then nat_small st else - (nat_small st) - let small_signed_int = int_small - let char_range a b = map Char.chr (Char.code a -- Char.code b) let random_binary_string st length = @@ -310,9 +281,6 @@ module Gen = struct let int32 st = Int32.of_string (random_binary_string st 32) let int64 st = Int64.of_string (random_binary_string st 64) - let ui32 = int32 - let ui64 = int64 - let list_size size gen st = foldn ~f:(fun acc _ -> (gen st)::acc) ~init:[] (size st) let list gen st = list_size nat gen st @@ -321,12 +289,9 @@ module Gen = struct let array_size size gen st = Array.init (size st) (fun _ -> gen st) let array gen st = array_size nat gen st - let array_repeat n g = array_size (return n) g let flatten_list l st = List.map (fun f->f st) l - let flatten_l = flatten_list let flatten_array a st = Array.map (fun f->f st) a - let flatten_a = flatten_array let flatten_option o st = match o with | None -> None @@ -356,8 +321,6 @@ module Gen = struct shuffle_a a st; Array.to_list a - let shuffle_l = shuffle_list - let shuffle_list_weighted l st = let sample (w, v) = let fl_w = float_of_int w in @@ -366,8 +329,6 @@ module Gen = struct let samples = List.rev_map sample l in List.sort (fun (w1, _) (w2, _) -> poly_compare w1 w2) samples |> List.rev_map snd - let shuffle_w_l = shuffle_list_weighted - let range_subset ~size low high st = let range_size = high - low + 1 in if not (0 <= size && size <= range_size) then @@ -458,14 +419,10 @@ module Gen = struct let string_of gen = string_size ~gen nat let bytes_printable = bytes_size ~gen:char_printable nat let string_printable = string_size ~gen:char_printable nat - let string_readable = string_printable let bytes_small st = bytes_size nat_small st let bytes_small_of gen st = bytes_size ~gen nat_small st - let small_string ?gen st = string_size ?gen nat_small st let list_small gen = list_size nat_small gen - let small_list = list_small let array_small gen = array_size nat_small gen - let small_array = array_small let string_small st = string_size nat_small st let string_small_of gen st = string_size ~gen nat_small st @@ -482,7 +439,6 @@ module Gen = struct let int_corners = int_pos_corners @ [min_int;-2;-1] let int_small_corners () = graft_corners int_small int_corners () - let nng_corners () = graft_corners nat int_pos_corners () (* sized, fix *) @@ -1294,8 +1250,6 @@ let bool = let float = make_scalar Gen.float let float_pos = make_scalar Gen.float_pos let float_neg = make_scalar Gen.float_neg -let pos_float = float_pos -let neg_float = float_neg let float_bound_inclusive bound = make ~small:small1 ~shrink:(Shrink.float_bound bound) ~print:Print.float (Gen.float_bound_inclusive bound) @@ -1317,19 +1271,14 @@ let int_bound n = make_int (Gen.int_bound n) let int_range a b = make_int (Gen.int_range a b) let (--) = int_range let int_pos = make_int Gen.int_pos -let pos_int = int_pos -let small_int = make_int Gen.small_int + let nat = make_int Gen.nat let int_pos_small = make_int Gen.int_pos_small let int_pos_mid = nat let nat_small = int_pos_small -let small_nat = nat_small -let int_small = make_int Gen.small_signed_int -let small_signed_int = int_small -let small_int_corners () = make_int (Gen.nng_corners ()) +let int_small = make_int Gen.int_small let int_small_corners () = make_int (Gen.int_small_corners ()) let int_neg = make_int Gen.int_neg -let neg_int = make_int Gen.neg_int let int32 = make ~print:Print.int32 ~small:small1 ~shrink:Shrink.int32 Gen.int32 @@ -1345,23 +1294,19 @@ let char_range low high = let char_printable = make ~print:Print.char ~small:(small_char 'a') ~shrink:Shrink.char_printable Gen.char_printable let printable = char_printable -let printable_char = char_printable let char_numeral = make ~print:Print.char ~small:(small_char '0') ~shrink:Shrink.char_numeral Gen.char_numeral let numeral = char_numeral -let numeral_char = char_numeral let bytes_size ?(gen = Gen.char) size = make ~shrink:Shrink.bytes ~small:Bytes.length ~print:Print.bytes (Gen.bytes_size ~gen size) let bytes_size_of size gen = bytes_size ~gen size -let bytes_gen_of_size size gen = bytes_size ~gen size let bytes_of gen = make ~shrink:Shrink.bytes ~small:Bytes.length ~print:Print.bytes (Gen.bytes_of gen) let bytes = bytes_of Gen.char -let bytes_of_size size = bytes_size ~gen:Gen.char size let bytes_small = bytes_size ~gen:Gen.char Gen.nat_small let bytes_small_of gen = bytes_size ~gen Gen.nat_small let bytes_printable = @@ -1377,39 +1322,13 @@ let string_of gen = let string = string_of Gen.char let string_size ?(gen=Gen.char) size = string_size_of size gen -let string_of_size size = string_size_of size Gen.char let string_small = string_size_of Gen.nat_small Gen.char let string_small_of gen = string_size_of Gen.nat_small gen -let small_string = string_small -let string_gen = string_of -let string_gen_of_size = string_size_of let string_printable = make ~shrink:(Shrink.string ~shrink:Shrink.char_printable) ~small:String.length ~print:Print.string (Gen.string_of Gen.char_printable) -let printable_string_of_size size = - make ~shrink:(Shrink.string ~shrink:Shrink.char_printable) ~small:String.length - ~print:Print.string (Gen.string_size ~gen:Gen.char_printable size) - -let small_printable_string = - make ~shrink:(Shrink.string ~shrink:Shrink.char_printable) ~small:String.length - ~print:Print.string (Gen.string_size ~gen:Gen.char_printable Gen.nat_small) - -let numeral_string = - make ~shrink:(Shrink.string ~shrink:Shrink.char_numeral) ~small:String.length - ~print:Print.string (Gen.string_of Gen.char_numeral) - -let numeral_string_of_size size = - make ~shrink:(Shrink.string ~shrink:Shrink.char_numeral) ~small:String.length - ~print:Print.string (Gen.string_size ~gen:Gen.char_numeral size) - -let printable_string = string_printable -let string_printable_of_size = printable_string_of_size -let string_small_printable = small_printable_string -let string_numeral = numeral_string -let string_numeral_of_size = numeral_string_of_size - let list_sum_ f l = List.fold_left (fun acc x-> f x+acc) 0 l let mk_list a gen = @@ -1420,9 +1339,7 @@ let mk_list a gen = let list a = mk_list a (Gen.list a.gen) let list_size size a = mk_list a (Gen.list_size size a.gen) -let list_of_size = list_size -let list_small a = mk_list a (Gen.small_list a.gen) -let small_list = list_small +let list_small a = mk_list a (Gen.list_small a.gen) let array_sum_ f a = Array.fold_left (fun acc x -> f x+acc) 0 a @@ -1450,8 +1367,6 @@ let array_size size a = ?print:(_opt_map ~f:Print.array a.print) (Gen.array_size size a.gen) -let array_of_size = array_size - let pair a b = make ?small:(_opt_map_2 ~f:(fun f g (x,y) -> f x+g y) a.small b.small) @@ -1551,7 +1466,7 @@ let tup9 a b c d e f g h i = (Gen.tup9 a.gen b.gen c.gen d.gen e.gen f.gen g.gen h.gen i.gen) let option ?ratio a = - let g = Gen.opt ?ratio a.gen + let g = Gen.option ?ratio a.gen and shrink = _opt_map a.shrink ~f:Shrink.option and small = _opt_map_or a.small ~d:(function None -> 0 | Some _ -> 1) @@ -1866,13 +1781,7 @@ let fun4 o1 o2 o3 o4 ret = (** given a list, returns generator that picks at random from list *) let oneof_list ?print ?small xs = make ?print ?small (Gen.oneof_list xs) -let oneofl ?print ?collect xs = make ?print ?collect (Gen.oneof_list xs) let oneof_array ?print ?small xs = make ?print ?small (Gen.oneof_array xs) -let oneofa ?print ?collect xs = make ?print ?collect (Gen.oneof_array xs) - -(** Given a list of generators, returns generator that randomly uses one of the generators - from the list *) -let choose l = oneof l (** Generator that always returns given value *) let always ?print x = @@ -1888,12 +1797,6 @@ let oneof_weighted ?print ?small ?shrink l = let gens = List.map (fun (x,y) -> x, y.gen) l in make ?print ?small ?shrink (Gen.oneof_weighted gens) -let frequency ?print ?small ?shrink ?collect l = - let arb = oneof_weighted ?print ?small ?shrink l in - match collect with - | None -> arb - | Some c -> set_collect c arb - (** Given list of [(frequency,value)] pairs, returns value with probability proportional to given frequency *) let oneof_list_weighted ?print ?small l = make ?print ?small (Gen.oneof_list_weighted l) diff --git a/src/core/QCheck.mli b/src/core/QCheck.mli index 3c002b54..5adbb815 100644 --- a/src/core/QCheck.mli +++ b/src/core/QCheck.mli @@ -209,67 +209,34 @@ module Gen : sig @raise Invalid_argument or Failure if list is empty @since 0.90 *) - val oneofl : 'a list -> 'a t [@@deprecated "Use [oneof_list] instead"][@@migrate { repl = Rel.oneof_list }] - (** Constructs a generator that selects among a given list of values. - @raise Invalid_argument or Failure if list is empty - @deprecated use {!oneof_list} instead. *) - val oneof_array : 'a array -> 'a t (** Constructs a generator that selects among a given array of values. @raise Invalid_argument or Failure if list is empty @since 0.90 *) - val oneofa : 'a array -> 'a t [@@deprecated "Use [oneof_array] instead"][@@migrate { repl = Rel.oneof_array }] - (** Constructs a generator that selects among a given array of values. - @raise Invalid_argument or Failure if list is empty - @deprecated use {!oneof_array} instead. *) - val oneof_weighted : (int * 'a t) list -> 'a t (** Constructs a generator that selects among a given list of generators. Each of the given generators are chosen based on a positive integer weight. @since 0.90 *) - val frequency : (int * 'a t) list -> 'a t [@@deprecated "Use [oneof_weighted] instead"][@@migrate { repl = Rel.oneof_weighted }] - (** Constructs a generator that selects among a given list of generators. - Each of the given generators are chosen based on a positive integer weight. - @deprecated use {!oneof_weighted} instead. *) - val oneof_list_weighted : (int * 'a) list -> 'a t (** Constructs a generator that selects among a given list of values. Each of the given values are chosen based on a positive integer weight. @since 0.90 *) - val frequencyl : (int * 'a) list -> 'a t [@@deprecated "Use [oneof_list_weighted] instead"][@@migrate { repl = Rel.oneof_list_weighted }] - (** Constructs a generator that selects among a given list of values. - Each of the given values are chosen based on a positive integer weight. - @deprecated use {!oneof_list_weighted} instead. *) - val oneof_array_weighted : (int * 'a) array -> 'a t (** Constructs a generator that selects among a given array of values. Each of the array entries are chosen based on a positive integer weight. @since 0.90 *) - val frequencya : (int * 'a) array -> 'a t [@@deprecated "Use [oneof_array_weighted] instead"][@@migrate { repl = Rel.oneof_array_weighted }] - (** Constructs a generator that selects among a given array of values. - Each of the array entries are chosen based on a positive integer weight. - @deprecated use {!oneof_array_weighted} instead. *) - val shuffle_array : 'a array -> 'a array t (** Creates a generator of shuffled arrays. @since 0.90 *) - val shuffle_a : 'a array -> unit t [@@deprecated "Consider using [shuffle_array] instead"] - (** Shuffles the array in place. - @deprecated Consider using {!shuffle_array} instead. *) - val shuffle_list : 'a list -> 'a list t (** Creates a generator of shuffled lists. @since 0.90 *) - val shuffle_l : 'a list -> 'a list t [@@deprecated "Use [shuffle_list] instead"][@@migrate { repl = Rel.shuffle_list }] - (** Creates a generator of shuffled lists. - @deprecated Use {!shuffle_list} instead. *) - val shuffle_list_weighted : (int * 'a) list -> 'a list t (** Creates a generator of weighted shuffled lists. A given list is shuffled on each generation according to the weights of its elements. An element with a larger weight @@ -283,11 +250,6 @@ module Gen : sig @since 0.90 *) - val shuffle_w_l : (int * 'a) list -> 'a list t [@@deprecated "Use [shuffle_list_weighted] instead"][@@migrate { repl = Rel.shuffle_list_weighted }] - (** An alias for {!shuffle_list_weighted} since 0.90. - @since 0.11 - @deprecated use {!shuffle_list_weighted} instead. *) - val range_subset : size:int -> int -> int -> int array t (** [range_subset ~size:k low high] generates an array of length [k] of sorted distinct integers in the range [low..high] (included). @@ -324,14 +286,6 @@ module Gen : sig val float_neg : float t (** Generates negative floating point numbers (-0. included). *) - val pfloat : float t [@@deprecated "Use [float_pos] instead"][@@migrate { repl = Rel.float_pos }] - (** Generates positive floating point numbers (0. included). - @deprecated use {!float_pos} instead. *) - - val nfloat : float t [@@deprecated "Use [float_neg] instead"][@@migrate { repl = Rel.float_neg }] - (** Generates negative floating point numbers (-0. included). - @deprecated use {!float_neg} instead. *) - val float_bound_inclusive : float -> float t (** [float_bound_inclusive bound] returns a random floating-point number between 0 and [bound] (inclusive). If [bound] is negative, the result is negative or zero. If @@ -371,27 +325,14 @@ module Gen : sig Synonym for {!nat}. @since 0.90 *) - val big_nat : int t [@@deprecated "Use [map abs int] instead"] - (** Generates natural numbers, possibly large. - @since 0.10 - @deprecated use [map abs int] instead. *) - val int_neg : int t (** Generates strictly negative integers uniformly (0 excluded). @since 0.90 *) - val neg_int : int t [@@deprecated "Use [int_neg] or [map (fun i -> -i) nat] instead"] - (** Generates non-strictly negative integers (0 included). - @deprecated use {!int_neg} or [map (fun i -> -i) nat] instead. *) - val int_pos : int t (** Generates non-strictly positive integers uniformly (0 included). @since 0.90 *) - val pint : int t [@@deprecated "Use [int_pos] instead"][@@migrate { repl = Rel.int_pos }] - (** Generates non-strictly positive integers uniformly (0 included). - @deprecated use {!int_pos} instead. *) - val int : int t (** Generates integers uniformly. *) val int_small : int t @@ -407,20 +348,6 @@ module Gen : sig Synonym for {!int_pos_small}. @since 0.90 *) - val small_nat : int t [@@deprecated "Use [nat_small] instead"][@@migrate { repl = Rel.nat_small }] - (** Small integers (< 100) - @since 0.5.1 - @deprecated use {!nat_small} instead *) - - val small_int : int t [@@deprecated "Use [nat_small] instead"][@@migrate { repl = Rel.nat_small }] - (** Small UNSIGNED integers, for retrocompatibility. - @deprecated use {!nat_small}. *) - - val small_signed_int : int t [@@deprecated "Use [int_small] instead"][@@migrate { repl = Rel.int_small }] - (** Small SIGNED integers, based on {!small_nat}. - @since 0.5.2 - @deprecated use {!int_small} instead. *) - val int_bound : int -> int t (** Uniform integer generator producing integers between [0] and [bound] (inclusive). @@ -442,16 +369,6 @@ module Gen : sig @since 0.6 *) - val int_pos_corners : int list [@@deprecated "Define your own list of corner cases instead"] - (** Non-negative corner cases for int. - @since 0.6 - @deprecated define your own list of corner cases instead *) - - val int_corners : int list [@@deprecated "Define your own list of corner cases instead"] - (** All corner cases for int. - @since 0.6 - @deprecated define your own list of corner cases instead *) - val int_small_corners : unit -> int t (** As [int_small], but each newly created generator starts with a list of corner cases before falling back on random generation. @@ -471,49 +388,24 @@ module Gen : sig (** Generates [int64] values uniformly. @since 0.24 *) - val ui32 : int32 t [@@deprecated "Use [int32] instead"][@@migrate { repl = Rel.int32 }] - (** Generates [int32] values. - @deprecated use {!val:int32} instead, the name is wrong, values {i are} signed. - *) - - val ui64 : int64 t [@@deprecated "Use [int64] instead"][@@migrate { repl = Rel.int64 }] - (** Generates [int64] values. - @deprecated use {!val:int64} instead, the name is wrong, values {i are} signed. - *) - val list : 'a t -> 'a list t (** Builds a list generator from an element generator. List size is generated by {!nat}. *) val list_size : int t -> 'a t -> 'a list t (** Builds a list generator from a (non-negative) size generator and an element generator. *) - val list_repeat : int -> 'a t -> 'a list t [@@deprecated "Use [list_size (return i) g] instead"][@@migrate { repl = (fun i g -> Rel.list_size (Rel.return i) g) }] - (** [list_repeat i g] builds a list generator from exactly [i] elements generated by [g]. - @deprecated use [list_size (return i) g] instead. *) - val array : 'a t -> 'a array t (** Builds an array generator from an element generator. Array size is generated by {!nat}. *) val array_size : int t -> 'a t -> 'a array t (** Builds an array generator from a (non-negative) size generator and an element generator. *) - val array_repeat : int -> 'a t -> 'a array t [@@deprecated "Use [array_size (return i) g] instead"][@@migrate { repl = (fun i g -> Rel.array_size (Rel.return i) g) }] - (** [array_repeat i g] builds an array generator from exactly [i] elements generated by [g]. - @deprecated use [array_size (return i) g] instead. *) - val option : ?ratio:float -> 'a t -> 'a option t (** An option generator, with optional ratio. @param ratio a float between [0.] and [1.] indicating the probability of a sample to be [Some _] rather than [None]. - @since 0.19 (renamed from [opt]) - *) - - val opt : ?ratio:float -> 'a t -> 'a option t [@@deprecated "Use [option] instead"][@@migrate { repl = Rel.option }] - (** [opt] is an alias of {!val:option} for backward compatibility. - - @since 0.18 ([?ratio] parameter) - @deprecated use {!val:option} instead. + @since 0.19 *) val result : ?ratio:float -> 'a t -> 'e t -> ('a, 'e) result t @@ -600,20 +492,10 @@ module Gen : sig (** Builds a string generator using the given character generator. @since 0.11 *) - val string_readable : string t [@@deprecated "Use [string_printable] instead"][@@migrate { repl = Rel.string_printable }] - (** Builds a string generator using the {!printable} character generator. - @since 0.11 - @deprecated use {!string_printable} *) - val string_printable : string t (** Builds a string generator using the {!printable} character generator. @since 0.18 *) - val small_string : ?gen:char t -> string t [@@deprecated "Use [string_small] instead"][@@migrate { repl = Rel.string_small }] - (** Builds a string generator, length is {!nat_small} - Accepts an optional character generator (the default is {!char}). - @deprecated use {!string_small} *) - val string_small : string t (** Builds a string generator using the {!char} character generator, length is {!nat_small} @since 0.20 *) @@ -626,55 +508,26 @@ module Gen : sig (** Generates lists of small size (see {!nat_small}). @since 0.90 *) - val small_list : 'a t -> 'a list t [@@deprecated "Use [list_small] instead"][@@migrate { repl = Rel.list_small }] - (** Generates lists of small size (see {!nat_small}). - @since 0.5.3 - @deprecated use {!list_small} instead. *) - val flatten_list : 'a t list -> 'a list t (** Generate a list of elements from individual generators @since 0.90 *) - val flatten_l : 'a t list -> 'a list t [@@deprecated "Use [flatten_list] instead"][@@migrate { repl = Rel.flatten_list }] - (** Generate a list of elements from individual generators - @since 0.13 - @deprecated use {!flatten_list} instead. *) - val flatten_array : 'a t array -> 'a array t (** Generate an array of elements from individual generators @since 0.90 *) - val flatten_a : 'a t array -> 'a array t [@@deprecated "Use [flatten_array] instead"][@@migrate { repl = Rel.flatten_array }] - (** Generate an array of elements from individual generators - @since 0.13 - @deprecated use {!flatten_array} instead. *) - val flatten_option : 'a t option -> 'a option t (** Generate an option from an optional generator @since 0.90 *) - val flatten_opt : 'a t option -> 'a option t [@@deprecated "Use [flatten_option] instead"][@@migrate { repl = Rel.flatten_option }] - (** Generate an option from an optional generator - @since 0.13 - @deprecated use {!flatten_option} instead. *) - val flatten_result : ('a t, 'e) result -> ('a,'e) result t (** Generate a result from [Ok g], an error from [Error e] @since 0.90 *) - val flatten_res : ('a t, 'e) result -> ('a,'e) result t [@@deprecated "Use [flatten_result] instead"][@@migrate { repl = Rel.flatten_result }] - (** Generate a result from [Ok g], an error from [Error e] - @since 0.13 - @deprecated use {!flatten_result} instead. *) - val array_small : 'a t -> 'a array t (** Generates arrays of small size (see {!nat_small}). @since 0.90 *) - val small_array : 'a t -> 'a array t [@@deprecated "Use [array_small] instead"][@@migrate { repl = Rel.array_small }] - (** Generates arrays of small size (see {!nat_small}). - @since 0.10 - @deprecated use {!array_small} instead. *) (** {3 Tuple generators} @@ -1298,14 +1151,6 @@ val float_pos : float arbitrary val float_neg : float arbitrary (** Negative float generator (no infinities). *) -val pos_float : float arbitrary [@@deprecated "Use [float_pos] instead"][@@migrate { repl = Rel.float_pos }] -(** Positive float generator (no infinities). - @deprecated use {!float_pos} instead. *) - -val neg_float : float arbitrary [@@deprecated "Use [float_neg] instead"][@@migrate { repl = Rel.float_neg }] -(** Negative float generator (no infinities). - @deprecated use {!float_neg} instead. *) - val float_bound_inclusive : float -> float arbitrary (** [float_bound_inclusive n] is uniform between [0] and [n] included. If [bound] is negative, the result is negative or zero. If [bound] is 0, the result is 0. @@ -1369,20 +1214,6 @@ val nat_small : int arbitrary Synonym for {!int_pos_small}. @since 0.90 *) -val small_nat : int arbitrary [@@deprecated "Use [nat_small] instead"][@@migrate { repl = Rel.nat_small }] -(** Small unsigned integers. - @since 0.5.1 - @deprecated use {!nat_small} instead *) - -val small_int : int arbitrary [@@deprecated "Use [nat_small] instead"][@@migrate { repl = Rel.nat_small }] -(** Small unsigned integers. See {!Gen.small_int}. - @deprecated use {!nat_small} instead *) - -val small_signed_int : int arbitrary [@@deprecated "Use [int_small] instead"][@@migrate { repl = Rel.int_small }] -(** Small signed integers. - @since 0.5.2 - @deprecated use {!int_small} instead *) - val (--) : int -> int -> int arbitrary (** Synonym for {!int_range}. *) @@ -1396,11 +1227,6 @@ val int_pos : int arbitrary (** Positive int generator (0 included). Uniformly distributed. See {!Gen.int_pos} *) -val pos_int : int arbitrary [@@deprecated "Use [int_pos] instead"][@@migrate { repl = Rel.int_pos }] -(** Positive int generator (0 included). Uniformly distributed. - See {!Gen.int_pos} - @deprecated use {!int_pos} instead. *) - val int_neg : int arbitrary (** Negative int generator (0 excluded). Uniformly distributed. See {!Gen.int_neg} @@ -1421,27 +1247,6 @@ val int_small_corners : unit -> int arbitrary ]} *) -val small_int_corners : unit -> int arbitrary [@@deprecated "Use [int_small_corners] instead"] -(** As [small_int], but each newly created generator starts with - a list of corner cases before falling back on random generation. - - Note that [small_int_corners ()] is stateful, meaning that once the list of - corner cases has been emitted, subsequent calls will not reproduce them. - As a consequence, in the following example, the first test fails with a - counter example, whereas the second rerun does not: - {[ - let gen = QCheck.small_int_corners () - let t = QCheck.Test.make ~name:"never max_int" gen (fun i -> i <> max_int) - let _ = QCheck_base_runner.run_tests ~verbose:true [t;t] - ]} - @deprecated consider using {!int_small_corners} instead. *) - -val neg_int : int arbitrary [@@deprecated "Use uniform [int_neg] instead"] -(** Negative int generator (0 included, see {!Gen.neg_int}). - The distribution is non-uniform and similar to that of - [int_small], not of [int_pos]. - @deprecated consider using uniform {!int_neg} instead. *) - val char : char arbitrary (** Uniformly distributed on all the chars (not just ascii or valid latin-1). *) @@ -1460,10 +1265,6 @@ val printable : char arbitrary (** Synonym for {!char_printable}. @since 0.90 *) -val printable_char : char arbitrary [@@deprecated "Use [char_printable] instead"][@@migrate { repl = Rel.char_printable }] -(** Synonym for {!char_printable}. - @deprecated use {!char_printable} instead. *) - val char_numeral : char arbitrary (** Uniformly distributed over ['0'..'9']. @since 0.90 *) @@ -1472,10 +1273,6 @@ val numeral : char arbitrary (** Synonym for {!char_numeral}. @since 0.90 *) -val numeral_char : char arbitrary [@@deprecated "Use [char_numeral] instead"][@@migrate { repl = Rel.char_numeral }] -(** Synonym for {!char_numeral}. - @deprecated use {!char_numeral} instead. *) - val bytes_size : ?gen:char Gen.t -> int Gen.t -> bytes arbitrary (** Builds a bytes generator from a (non-negative) size generator. Accepts an optional character generator (the default is {!Gen.char}). @@ -1486,11 +1283,6 @@ val bytes_size_of : int Gen.t -> char Gen.t -> bytes arbitrary and a character generator. @since 0.90 *) -val bytes_gen_of_size : int Gen.t -> char Gen.t -> bytes arbitrary [@@deprecated "Use [bytes_size] instead"][@@migrate { repl = (fun s gen -> Rel.bytes_size ~gen s) }] -(** Builds a bytes generator from a (non-negative) size generator and a character generator. - @since 0.20 - @deprecated use {!bytes_size} instead. *) - val bytes_of : char Gen.t -> bytes arbitrary (** Generates bytes with a distribution of length of {!Gen.nat}. @since 0.20 *) @@ -1508,24 +1300,11 @@ val bytes_small_of : char Gen.t -> bytes arbitrary (** Same as {!bytes_of} but with a small length (ie {!Gen.nat_small} ). @since 0.20 *) -val bytes_of_size : int Gen.t -> bytes arbitrary [@@deprecated "Use [bytes_size] instead"][@@migrate { repl = Rel.bytes_size }] -(** Generates bytes with distribution of characters of [char]. - @since 0.20 - @deprecated use {!bytes_size} instead. *) - val bytes_printable : bytes arbitrary (** Generates bytes with a distribution of length of {!Gen.nat} and distribution of characters of [printable_char]. @since 0.20 *) -val string_gen_of_size : int Gen.t -> char Gen.t -> string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = Rel.string_size_of }] -(** Builds a string generator from a (non-negative) size generator and a character generator. - @deprecated use {!string_size_of} instead. *) - -val string_gen : char Gen.t -> string arbitrary [@@deprecated "Use [string_of] instead"][@@migrate { repl = Rel.string_of }] -(** Generates strings with a distribution of length of {!Gen.nat}. - @deprecated use {!string_of} instead. *) - val string_of : char Gen.t -> string arbitrary (** Synonym for {!string_gen} added for convenience. @since 0.20 *) @@ -1544,10 +1323,6 @@ val string_size_of : int Gen.t -> char Gen.t -> string arbitrary and a character generator. @since 0.90 *) -val small_string : string arbitrary [@@deprecated "Use [string_small] instead"][@@migrate { repl = Rel.string_small }] -(** Same as {!string} but with a small length (ie {!Gen.nat_small} ). - @deprecated use {!string_small} *) - val string_small : string arbitrary (** Same as {!string} but with a small length (ie {!Gen.nat_small} ). @since 0.20 *) @@ -1560,63 +1335,11 @@ val list_small : 'a arbitrary -> 'a list arbitrary (** Generates lists of small size (see {!Gen.nat_small}). @since 0.90 *) -val small_list : 'a arbitrary -> 'a list arbitrary [@@deprecated "Use [list_small] instead"][@@migrate { repl = Rel.list_small }] -(** Generates lists of small size (see {!Gen.nat_small}). - @since 0.5.3 - @deprecated use {!list_small} instead. *) - -val string_of_size : int Gen.t -> string arbitrary [@@deprecated "Use [string_size] instead"][@@migrate { repl = Rel.string_size }] -(** Generates strings with distribution of characters of [char]. - @deprecated use {!string_size} instead. *) - -val printable_string : string arbitrary [@@deprecated "Use [string_printable] instead"][@@migrate { repl = Rel.string_printable }] -(** Generates strings with a distribution of length of {!Gen.nat} - and distribution of characters of [char_printable]. - @deprecated use {!string_printable} instead. *) - val string_printable : string arbitrary (** Generates strings with a distribution of length of {!Gen.nat} and distribution of characters of [char_printable]. @since 0.20 *) -val printable_string_of_size : int Gen.t -> string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = (fun s -> Rel.string_size_of s Rel.Gen.char_printable) }] -(** Generates strings with distribution of characters of [char_printable]. - @deprecated use {!string_size_of} instead. *) - -val string_printable_of_size : int Gen.t -> string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = (fun s -> Rel.string_size_of s Rel.Gen.char_printable) }] -(** Synonym for [printable_string_of_size] added for convenience. - @since 0.20 - @deprecated use {!string_size_of} instead. *) - -val small_printable_string : string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = Rel.string_size_of Rel.Gen.nat_small Rel.Gen.char_printable }] -(** Generates strings with a length of [Gen.nat_small] - and distribution of characters of [char_printable]. - @deprecated use {!string_size_of} instead. *) - -val string_small_printable : string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = Rel.string_size_of Rel.Gen.nat_small Rel.Gen.char_printable }] -(** Synonym for [small_printable_string] added for convenience. - @since 0.20 - @deprecated use {!string_size_of} instead. *) - -val numeral_string : string arbitrary [@@deprecated "Use [string_of] instead"][@@migrate { repl = Rel.string_of Rel.Gen.char_numeral }] -(** Generates strings with a distribution of length of {!Gen.nat} - and distribution of characters of [char_numeral]. - @deprecated use {!string_of} instead. *) - -val string_numeral : string arbitrary [@@deprecated "Use [string_of] instead"][@@migrate { repl = Rel.string_of Rel.Gen.char_numeral }] -(** Synonym for [numeral_string] added for convenience. - @since 0.20 - @deprecated use {!string_of} instead. *) - -val numeral_string_of_size : int Gen.t -> string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = (fun s -> Rel.string_size_of s Rel.Gen.char_numeral) }] -(** Generates strings with a distribution of characters of [char_numeral]. - @deprecated use {!string_size_of} instead. *) - -val string_numeral_of_size : int Gen.t -> string arbitrary [@@deprecated "Use [string_size_of] instead"][@@migrate { repl = (fun s -> Rel.string_size_of s Rel.Gen.char_numeral) }] -(** Synonym for [numeral_string_of_size] added for convenience. - @since 0.20 - @deprecated use {!string_size_of} instead. *) - val list : 'a arbitrary -> 'a list arbitrary (** Generates lists with length generated by {!Gen.nat}. *) @@ -1624,10 +1347,6 @@ val list_size : int Gen.t -> 'a arbitrary -> 'a list arbitrary (** Generates lists with length from the given distribution. @since 0.90 *) -val list_of_size : int Gen.t -> 'a arbitrary -> 'a list arbitrary [@@deprecated "Use [list_size] instead"][@@migrate { repl = Rel.list_size }] -(** Generates lists with length from the given distribution. - @deprecated use {!list_size} instead. *) - val array : 'a arbitrary -> 'a array arbitrary (** Generates arrays with length generated by {!Gen.nat}. *) @@ -1639,10 +1358,6 @@ val array_size : int Gen.t -> 'a arbitrary -> 'a array arbitrary (** Generates arrays with length from the given distribution. @since 0.90 *) -val array_of_size : int Gen.t -> 'a arbitrary -> 'a array arbitrary [@@deprecated "Use [array_size] instead"][@@migrate { repl = Rel.array_size }] -(** Generates arrays with length from the given distribution. - @deprecated use {!array_size} instead. *) - val option : ?ratio:float -> 'a arbitrary -> 'a option arbitrary (** Choose between returning Some random value with optional ratio, or None. *) @@ -1765,29 +1480,14 @@ val tup9 : (** {2 Combinatoric arbitrary combinators } *) -val choose : 'a arbitrary list -> 'a arbitrary [@@deprecated "Use [oneof] instead"][@@migrate { repl = Rel.oneof }] -(** Choose among the given list of generators. The list must not - be empty; if it is [Invalid_argument] is raised. - @deprecated use {!oneof} instead. *) - val oneof_list : ?print:'a Print.t -> ?small:('a -> int) -> 'a list -> 'a arbitrary (** Pick an element randomly in the list. @since 0.90 *) -val oneofl : ?print:'a Print.t -> ?collect:('a -> string) -> - 'a list -> 'a arbitrary [@@deprecated "Use [oneof_list] instead"][@@migrate { repl = Rel.oneof_list }] -(** Pick an element randomly in the list. - @deprecated use {!oneof_list} instead. *) - val oneof_array : ?print:'a Print.t -> ?small:('a -> int) -> 'a array -> 'a arbitrary (** Pick an element randomly in the array. @since 0.90 *) -val oneofa : ?print:'a Print.t -> ?collect:('a -> string) -> - 'a array -> 'a arbitrary [@@deprecated "Use [oneof_array] instead"][@@migrate { repl = Rel.oneof_array }] -(** Pick an element randomly in the array. - @deprecated use {!oneof_array} instead. *) - val oneof : ?print:'a Print.t -> ?small:('a -> int) -> ?shrink:'a Shrink.t -> 'a arbitrary list -> 'a arbitrary (** Pick a generator among the list, randomly. @@ -1808,34 +1508,17 @@ val oneof_weighted : ?print:'a Print.t -> ?small:('a -> int) -> (** Similar to {!oneof} but with frequencies. @since 0.90 *) -val frequency : ?print:'a Print.t -> ?small:('a -> int) -> - ?shrink:'a Shrink.t -> ?collect:('a -> string) -> - (int * 'a arbitrary) list -> 'a arbitrary [@@deprecated "Use [oneof_weighted] instead"][@@migrate { repl = Rel.oneof_weighted }] -(** Similar to {!oneof} but with frequencies. - @deprecated use {!oneof_weighted} instead. *) - val oneof_list_weighted : ?print:'a Print.t -> ?small:('a -> int) -> (int * 'a) list -> 'a arbitrary (** Same as {!oneof_list}, but each element is paired with its frequency in the probability distribution (the higher, the more likely). @since 0.90 *) -val frequencyl : ?print:'a Print.t -> ?small:('a -> int) -> - (int * 'a) list -> 'a arbitrary [@@deprecated "Use [oneof_list_weighted] instead"][@@migrate { repl = Rel.oneof_list_weighted }] -(** Same as {!oneof_list}, but each element is paired with its frequency in - the probability distribution (the higher, the more likely). - @deprecated use {!oneof_list_weighted} instead. *) - val oneof_array_weighted : ?print:'a Print.t -> ?small:('a -> int) -> (int * 'a) array -> 'a arbitrary (** Same as {!oneof_list_weighted}, but with an array. @since 0.90 *) -val frequencya : ?print:'a Print.t -> ?small:('a -> int) -> - (int * 'a) array -> 'a arbitrary [@@deprecated "Use [oneof_array_weighted] instead"][@@migrate { repl = Rel.oneof_array_weighted }] -(** Same as {!oneof_list_weighted}, but with an array. - @deprecated use {!oneof_array_weighted} instead. *) - val map : ?rev:('b -> 'a) -> ('a -> 'b) -> 'a arbitrary -> 'b arbitrary (** [map f a] returns a new arbitrary instance that generates values using [a#gen] and then transforms them through [f]. diff --git a/src/core/QCheck2.ml b/src/core/QCheck2.ml index 245ee295..dbc8c86d 100644 --- a/src/core/QCheck2.ml +++ b/src/core/QCheck2.ml @@ -188,9 +188,6 @@ module Shrink = struct else if current < n then let next = succ current in Some (next, next) else let next = pred current in Some (next, next) ) destination () - - let int_aggressive n = fun () -> int_aggressive_towards 0 n () - end module Tree = struct @@ -392,7 +389,6 @@ module Gen = struct Tree.make_primitive shrink x let nat_small = int_pos_small - let small_nat = nat_small (** Natural number generator *) let nat : int t = fun st -> @@ -408,14 +404,6 @@ module Gen = struct let int_pos_mid = nat - let big_nat : int t = fun st -> - let p = RS.float st 1. in - if p < 0.75 - then nat st - else - let shrink a = fun () -> Shrink.int_towards 0 a () in - Tree.make_primitive shrink (RS.int st 1_000_000) - let unit : unit t = fun _st -> Tree.pure () let bool : bool t = fun st -> @@ -441,10 +429,6 @@ module Gen = struct let float_neg : float t = float_pos >|= Float.neg - let pfloat = float_pos - - let nfloat = float_neg - let float_bound_inclusive ?(origin : float = 0.) (bound : float) : float t = fun st -> let (low, high) = Float.min_max_num 0. bound in let shrink a = fun () -> @@ -497,8 +481,6 @@ module Gen = struct let exponential = float_exp - let neg_int : int t = nat >|= Int.neg - (** [option gen] shrinks towards [None] then towards shrinks of [gen]. *) let option ?(ratio : float = 0.85) (gen : 'a t) : 'a option t = fun st -> let p = RS.float st 1. in @@ -506,9 +488,6 @@ module Gen = struct then Tree.pure None else Tree.opt (gen st) - (** [opt] is an alias of {!val:option} for backward compatibility. *) - let opt = option - let result ?(ratio : float = 0.75) (ok_gen : 'a t) (err_gen : 'e t) : ('a, 'e) result t = fun st -> let p = RS.float st 1. in if p < (1. -. ratio) @@ -552,16 +531,11 @@ module Gen = struct let right = RS.bits st in left lor middle lor right - let pint ?(origin : int = 0) : int t = fun st -> + let int_pos : int t = fun st -> let x = pint_raw st in - let shrink a = fun () -> - let origin = parse_origin "Gen.pint" Format.pp_print_int ~origin ~low:0 ~high:max_int in - Shrink.int_towards origin a () - in + let shrink a = fun () -> Shrink.int_towards 0 a () in Tree.make_primitive shrink x - let int_pos = pint ~origin:0 - let int_neg = int_pos >|= (fun n -> - n - 1) let number_towards = Shrink.number_towards @@ -627,24 +601,14 @@ module Gen = struct let oneof_list (l : 'a list) : 'a t = int_bound (List.length l - 1) >|= List.nth l - let oneofl = oneof_list - let oneof_array (a : 'a array) : 'a t = int_bound (Array.length a - 1) >|= Array.get a - let oneofa = oneof_array - - (* NOTE: we keep this alias to not break code that uses [small_int] - for sizes of strings, arrays, etc. *) - let small_int = small_nat - let int_small : int t = fun st -> if RS.bool st then nat_small st else (nat_small >|= Int.neg) st - let small_signed_int = int_small - (** Shrink towards the first element of the list *) let oneof_weighted (l : (int * 'a t) list) : 'a t = if l = [] then failwith "QCheck2.Gen.oneof_weighted called with an empty list"; @@ -658,18 +622,12 @@ module Gen = struct in aux 0 l - let frequency = oneof_weighted - let oneof_list_weighted (l : (int * 'a) list) : 'a t = List.map (fun (weight, value) -> (weight, pure value)) l |> oneof_weighted - let frequencyl = oneof_list_weighted - let oneof_array_weighted a = oneof_list_weighted (Array.to_list a) - let frequencya = oneof_array_weighted - let char_range ?(origin : char option) (a : char) (b : char) : char t = (int_range ~origin:(Char.code (Option.value ~default:a origin)) (Char.code a) (Char.code b)) >|= Char.chr @@ -688,15 +646,11 @@ module Gen = struct let shrink a = fun () -> Shrink.int32_towards 0l a () in Tree.make_primitive shrink x - let ui32 : int32 t = map Int32.abs int32 - let int64 : int64 t = fun st -> let x = random_binary_string 64 st |> Int64.of_string in let shrink a = fun () -> Shrink.int64_towards 0L a () in Tree.make_primitive shrink x - let ui64 : int64 t = map Int64.abs int64 - (* A tail-recursive implementation over Tree.t *) let list_size (size : int t) (gen : 'a t) : 'a list t = fun st -> @@ -734,34 +688,24 @@ module Gen = struct let array (gen : 'a t) : 'a array t = list gen >|= Array.of_list - let array_repeat (n : int) (gen : 'a t) : 'a array t = list_repeat n gen >|= Array.of_list - let rec flatten_list (l : 'a t list) : 'a list t = match l with | [] -> pure [] | gen :: gens -> liftA2 List.cons gen (flatten_list gens) - let flatten_l = flatten_list - let flatten_array (a : 'a t array) : 'a array t = Array.to_list a |> flatten_list >|= Array.of_list - let flatten_a = flatten_array - let flatten_option (o : 'a t option) : 'a option t = match o with | None -> pure None | Some gen -> option gen - let flatten_opt = flatten_option - let flatten_result (res : ('a t, 'e) result) : ('a, 'e) result t = match res with | Ok gen -> gen >|= Result.ok | Error e -> pure (Error e) - let flatten_res = flatten_result - let shuffle_array (a : 'a array) : 'a array t = fun st -> let a = Array.copy a in for i = Array.length a - 1 downto 1 do @@ -772,13 +716,9 @@ module Gen = struct done; Tree.pure a - let shuffle_a = shuffle_array - let shuffle_list (l : 'a list) : 'a list t = Array.of_list l |> shuffle_array >|= Array.to_list - let shuffle_l = shuffle_list - let shuffle_list_weighted (l : ((int * 'a) list)) : 'a list t = fun st -> let sample (w, v) = let Tree.Tree (p, _) = float_bound_inclusive 1. st in @@ -791,8 +731,6 @@ module Gen = struct |> List.rev_map snd |> Tree.pure - let shuffle_w_l = shuffle_list_weighted - let pair (g1 : 'a t) (g2 : 'b t) : ('a * 'b) t = liftA2 (fun a b -> (a, b)) g1 g2 let triple (g1 : 'a t) (g2 : 'b t) (g3 : 'c t) : ('a * 'b * 'c) t = (fun a b c -> (a, b, c)) <$> g1 <*> g2 <*> g3 @@ -921,16 +859,10 @@ module Gen = struct let string_small_of gen = list_ignore_size_tree nat_small gen >|= string_of_char_list - let small_string ?(gen=char) = string_small_of gen - let list_small gen = list_ignore_size_tree nat_small gen - let small_list = list_small - let array_small gen = list_ignore_size_tree nat_small gen >|= Array.of_list - let small_array = array_small - let join (gen : 'a t t) : 'a t = gen >>= Fun.id (* corner cases *) @@ -945,7 +877,6 @@ module Gen = struct let int_corners = int_pos_corners @ [min_int; -2; -1] let int_small_corners () : int t = graft_corners int_small int_corners () - let small_int_corners () : int t = graft_corners nat int_pos_corners () (* sized, fix *) @@ -1037,8 +968,6 @@ module Print = struct let contramap f p x = p (f x) - let comap = contramap - let default = fun _ -> "" let tup2 p_a p_b (a, b) = @@ -1284,8 +1213,6 @@ module Observable = struct make ~hash:(fun x -> p.hash (f x)) ~eq:(fun x y -> p.eq (f x)(f y)) (fun x -> p.print (f x)) - let map = contramap - let pair a b = make ~hash:(H.pair a.hash b.hash) ~eq:(Eq.pair a.eq b.eq) (Print.pair a.print b.print) @@ -1601,16 +1528,10 @@ module TestResult = struct let get_collect r = if Lazy.is_val r.collect_tbl then Some (Lazy.force r.collect_tbl) else None - let collect = get_collect - let get_stats r = r.stats_tbl - let stats = get_stats - let get_warnings r = r.warnings - let warnings = get_warnings - let is_success r = match r.state with | Success -> true | Failed _ | Error _ | Failed_other _ -> false diff --git a/src/core/QCheck2.mli b/src/core/QCheck2.mli index fcff9f04..70648da4 100644 --- a/src/core/QCheck2.mli +++ b/src/core/QCheck2.mli @@ -192,13 +192,6 @@ module Gen : sig @since 0.90 *) - val pint : ?origin : int -> int t [@@deprecated "Use [int_pos] instead"][@@migrate { repl = Rel.int_pos }] - (** Generates non-strictly positive integers uniformly ([0] included). - - Shrinks towards [origin] if specified, otherwise towards [0]. - - @deprecated use {!int_pos} instead *) - val int_pos_small : int t (** Small positive integers (< [100], [0] included). @@ -215,17 +208,6 @@ module Gen : sig @since 0.90 *) - val small_nat : int t [@@deprecated "Use [nat_small] instead"][@@migrate { repl = Rel.nat_small }] - (** Small positive integers (< [100], [0] included). - - Non-uniform: smaller numbers are more likely than bigger numbers. - - Shrinks towards [0]. - - @since 0.5.1 - - @deprecated use {!nat_small} instead *) - val nat : int t (** Generates natural numbers (< [10_000]). @@ -241,17 +223,6 @@ module Gen : sig @since 0.90 *) - val big_nat : int t [@@deprecated "Use [map abs int] instead"] - (** Generates natural numbers, possibly large (< [1_000_000]). - - Non-uniform: smaller numbers are more likely than bigger numbers. - - Shrinks towards [0]. - - @since 0.10 - - @deprecated use [map abs int] instead. *) - val int_neg : int t (** Generates strictly negative integers uniformly ([0] excluded). @@ -259,33 +230,6 @@ module Gen : sig @since 0.90 *) - val neg_int : int t [@@deprecated "Use [int_neg] or [map (fun i -> -i) nat] instead"] - (** Generates non-strictly negative integers ([0] included). - - Non-uniform: smaller numbers (in absolute value) are more likely than bigger numbers. - - Shrinks towards [0]. - - @deprecated use {!int_neg} or [map (fun i -> -i) nat] instead. *) - - val small_int : int t [@@deprecated "Use [nat_small] instead"][@@migrate { repl = Rel.nat_small }] - (** Small UNSIGNED integers, for retrocompatibility. - - Shrinks towards [0]. - - @deprecated use {!nat_small}. *) - - val small_signed_int : int t [@@deprecated "Use [int_small] instead"][@@migrate { repl = Rel.int_small }] - (** Small SIGNED integers, based on {!small_nat}. - - Non-uniform: smaller numbers (in absolute value) are more likely than bigger numbers. - - Shrinks towards [0]. - - @since 0.5.2 - - @deprecated use {!int_small} instead. *) - val int_small_corners : unit -> int t (** As {!int_small}, but each newly created generator starts with a list of corner cases before falling back on random generation. @@ -302,50 +246,18 @@ module Gen : sig @since 0.90 *) - val small_int_corners : unit -> int t [@@deprecated "Use [int_small_corners] instead"] - (** As {!small_int}, but each newly created generator starts with - a list of corner cases before falling back on random generation. - - Note that [small_int_corners ()] is stateful, meaning that once the list of - corner cases has been emitted, subsequent calls will not reproduce them. - As a consequence, in the following example, the first test fails with a - counter example, whereas the second rerun does not: - {[ - let gen = QCheck2.Gen.small_int_corners () - let t = QCheck2.Test.make ~name:"never max_int" gen (fun i -> i <> max_int) - let _ = QCheck_base_runner.run_tests ~verbose:true [t;t] - ]} - - @deprecated use {!int_small_corners} instead. *) - val int32 : int32 t (** Generates uniform {!int32} values. Shrinks towards [0l]. *) - val ui32 : int32 t [@@deprecated "Use [int32] instead"][@@migrate { repl = Rel.int32 }] - (** Generates {!int32} values. - - Shrinks towards [0l]. - - @deprecated use {!val:int32} instead, the name is wrong, values {i are} signed. - *) - val int64 : int64 t (** Generates uniform {!int64} values. Shrinks towards [0L]. *) - val ui64 : int64 t [@@deprecated "Use [int64] instead"][@@migrate { repl = Rel.int64 }] - (** Generates {!int64} values. - - Shrinks towards [0L]. - - @deprecated use {!val:int64} instead, the name is wrong, values {i are} signed. - *) - val float : float t (** Generates floating point numbers. @@ -364,22 +276,6 @@ module Gen : sig Shrinks towards [-0.]. *) - val pfloat : float t [@@deprecated "Use [float_pos] instead"][@@migrate { repl = Rel.float_pos }] - (** Generates positive floating point numbers ([0.] included). - - Shrinks towards [0.]. - - @deprecated use {!float_pos} instead. - *) - - val nfloat : float t [@@deprecated "Use [float_neg] instead"][@@migrate { repl = Rel.float_neg }] - (** Generates negative floating point numbers. ([-0.] included). - - Shrinks towards [-0.]. - - @deprecated use {!float_neg} instead. - *) - val char : char t (** Generates characters in the [0..255] range. @@ -520,16 +416,6 @@ module Gen : sig @since 0.20 *) - val small_string : ?gen:char t -> string t [@@deprecated "Use [string_small] instead"][@@migrate { repl = Rel.string_small }] - (** Builds a string generator, length is {!nat_small}. - Accepts an optional character generator (the default is {!char}). - Shrinks on the number of characters first, then on the characters. - This function is kept for backward compatibility: - The optional argument is in fact a mandatory [option], see c-cube/qcheck#162. - Use {!string_small} instead. - @deprecated use {!string_small} instead. - *) - val pure : 'a -> 'a t (** [pure a] creates a generator that always returns [a]. @@ -692,14 +578,6 @@ module Gen : sig @since 0.90 *) - val oneofl : 'a list -> 'a t [@@deprecated "Use [oneof_list] instead"][@@migrate { repl = Rel.oneof_list }] - (** [oneofl l] constructs a generator that selects among the given list of values [l]. - - Shrinks towards the first element of the list. - @raise Invalid_argument or Failure if [l] is empty - @deprecated use {!oneof_list} instead. - *) - val oneof_array : 'a array -> 'a t (** [oneof_array a] constructs a generator that selects among the given array of values [a]. @@ -708,14 +586,6 @@ module Gen : sig @since 0.90 *) - val oneofa : 'a array -> 'a t [@@deprecated "Use [oneof_array] instead"][@@migrate { repl = Rel.oneof_array }] - (** [oneofa a] constructs a generator that selects among the given array of values [a]. - - Shrinks towards the first element of the array. - @raise Invalid_argument or Failure if [a] is empty - @deprecated use {!oneof_array} instead. - *) - val oneof_weighted : (int * 'a t) list -> 'a t (** Constructs a generator that selects among a given list of generators. Each of the given generators are chosen based on a positive integer weight. @@ -724,14 +594,6 @@ module Gen : sig @since 0.90 *) - val frequency : (int * 'a t) list -> 'a t [@@deprecated "Use [oneof_weighted] instead"][@@migrate { repl = Rel.oneof_weighted }] - (** Constructs a generator that selects among a given list of generators. - Each of the given generators are chosen based on a positive integer weight. - - Shrinks towards the first element of the list. - @deprecated use {!oneof_weighted} instead. - *) - val oneof_list_weighted : (int * 'a) list -> 'a t (** Constructs a generator that selects among a given list of values. Each of the given values are chosen based on a positive integer weight. @@ -740,14 +602,6 @@ module Gen : sig @since 0.90 *) - val frequencyl : (int * 'a) list -> 'a t [@@deprecated "Use [oneof_list_weighted] instead"][@@migrate { repl = Rel.oneof_list_weighted }] - (** Constructs a generator that selects among a given list of values. - Each of the given values are chosen based on a positive integer weight. - - Shrinks towards the first element of the list. - @deprecated use {!oneof_list_weighted} instead. - *) - val oneof_array_weighted : (int * 'a) array -> 'a t (** Constructs a generator that selects among a given array of values. Each of the array entries are chosen based on a positive integer weight. @@ -756,32 +610,16 @@ module Gen : sig @since 0.90 *) - val frequencya : (int * 'a) array -> 'a t [@@deprecated "Use [oneof_array_weighted] instead"][@@migrate { repl = Rel.oneof_array_weighted }] - (** Constructs a generator that selects among a given array of values. - Each of the array entries are chosen based on a positive integer weight. - - Shrinks towards the first element of the array. - @deprecated use {!oneof_array_weighted} instead. - *) - (** {3 Shuffling elements} *) val shuffle_array : 'a array -> 'a array t (** Returns a copy of the array with its elements shuffled. @since 0.90 *) - val shuffle_a : 'a array -> 'a array t [@@deprecated "Use [shuffle_array] instead"][@@migrate { repl = Rel.shuffle_array }] - (** Returns a copy of the array with its elements shuffled. - @deprecated use {!shuffle_array} instead. *) - val shuffle_list : 'a list -> 'a list t (** Creates a generator of shuffled lists. @since 0.90 *) - val shuffle_l : 'a list -> 'a list t [@@deprecated "Use [shuffle_list] instead"][@@migrate { repl = Rel.shuffle_list }] - (** Creates a generator of shuffled lists. - @deprecated use {!shuffle_list} instead. *) - val shuffle_list_weighted : (int * 'a) list -> 'a list t (** Creates a generator of weighted shuffled lists. A given list is shuffled on each generation according to the weights of its elements. An element with a larger weight @@ -795,11 +633,6 @@ module Gen : sig @since 0.90 *) - val shuffle_w_l : (int * 'a) list -> 'a list t [@@deprecated "Use [shuffle_list_weighted] instead"][@@migrate { repl = Rel.shuffle_list_weighted }] - (** A synonym for {!shuffle_list_weighted} since 0.90 - @since 0.11 - @deprecated use {!shuffle_list_weighted} instead. *) - (** {3 Corner cases} *) val graft_corners : 'a t -> 'a list -> unit -> 'a t @@ -816,18 +649,6 @@ module Gen : sig @since 0.6 *) - val int_pos_corners : int list [@@deprecated "Define your own list of corner cases instead"] - (** Non-negative corner cases for int. - - @since 0.6 - @deprecated define your own list of corner cases instead *) - - val int_corners : int list [@@deprecated "Define your own list of corner cases instead"] - (** All corner cases for int. - - @since 0.6 - @deprecated define your own list of corner cases instead *) - (** {3 Lists, arrays and options} *) val list : 'a t -> 'a list t @@ -843,28 +664,12 @@ module Gen : sig @since 0.90 *) - val small_list : 'a t -> 'a list t [@@deprecated "Use [list_small] instead"][@@migrate { repl = Rel.list_small }] - (** Generates lists of small size (see {!nat_small}). - - Shrinks on the number of elements first, then on elements. - - @since 0.5.3 - - @deprecated use {!list_small} instead. *) - val list_size : int t -> 'a t -> 'a list t (** Builds a list generator from a (non-negative) size generator and an element generator. Shrinks on the number of elements first, then on elements. *) - val list_repeat : int -> 'a t -> 'a list t [@@deprecated "Use [list_size (return i) g] instead"][@@migrate { repl = (fun i g -> Rel.list_size (Rel.return i) g) }] - (** [list_repeat i g] builds a list generator from exactly [i] elements generated by [g]. - - Shrinks on elements only. - - @deprecated use [list_size (return i) g] instead. *) - val array : 'a t -> 'a array t (** Builds an array generator from an element generator. Array size is generated by {!nat}. @@ -884,22 +689,6 @@ module Gen : sig @since 0.90 *) - val small_array : 'a t -> 'a array t [@@deprecated "Use [array_small] instead"][@@migrate { repl = Rel.array_small }] - (** Generates arrays of small size (see {!nat_small}). - - Shrinks on the number of elements first, then on elements. - - @since 0.10 - - @deprecated use {!array_small} instead. *) - - val array_repeat : int -> 'a t -> 'a array t [@@deprecated "Use [array_size (return i) g] instead"][@@migrate { repl = (fun i g -> Rel.array_size (Rel.return i) g) }] - (** [array_repeat i g] builds an array generator from exactly [i] elements generated by [g]. - - Shrinks on elements only. - - @deprecated use [array_size (return i) g] instead. *) - val option : ?ratio:float -> 'a t -> 'a option t (** [option gen] is an [option] generator that uses [gen] when generating [Some] values. @@ -911,10 +700,6 @@ module Gen : sig @since 0.19 (renamed from [opt]) *) - val opt : ?ratio:float -> 'a t -> 'a option t [@@deprecated "Use [option] instead"][@@migrate { repl = Rel.option }] - (** [opt] is an alias of {!val:option} for backward compatibility. - @deprecated use {!val:option} instead. *) - val result : ?ratio:float -> 'a t -> 'e t -> ('a, 'e) result t (** [result ~ratio okgen errgen] generates [Ok v] with [v] coming from [okgen] or [Error e] with [e] coming from [errgen], depending on [ratio]. @@ -985,15 +770,6 @@ module Gen : sig @since 0.90 *) - val flatten_l : 'a t list -> 'a list t [@@deprecated "Use [flatten_list] instead"][@@migrate { repl = Rel.flatten_list }] - (** Generate a list of elements from individual generators. - - Shrinks on the elements of the list, in the list order. - - @since 0.13 - - @deprecated use {!flatten_list} instead. *) - val flatten_array : 'a t array -> 'a array t (** Generate an array of elements from individual generators. @@ -1001,15 +777,6 @@ module Gen : sig @since 0.90 *) - val flatten_a : 'a t array -> 'a array t [@@deprecated "Use [flatten_array] instead"][@@migrate { repl = Rel.flatten_array }] - (** Generate an array of elements from individual generators. - - Shrinks on the elements of the array, in the array order. - - @since 0.13 - - @deprecated use {!flatten_array} instead. *) - val flatten_option : 'a t option -> 'a option t (** Generate an option from an optional generator. @@ -1017,15 +784,6 @@ module Gen : sig @since 0.90 *) - val flatten_opt : 'a t option -> 'a option t [@@deprecated "Use [flatten_option] instead"][@@migrate { repl = Rel.flatten_option }] - (** Generate an option from an optional generator. - - Shrinks towards [None] then shrinks on the value. - - @since 0.13 - - @deprecated use {!flatten_option} instead. *) - val flatten_result : ('a t, 'e) result -> ('a,'e) result t (** Generate a result from [Ok gen], an error from [Error e]. @@ -1034,16 +792,6 @@ module Gen : sig @since 0.90 *) - val flatten_res : ('a t, 'e) result -> ('a,'e) result t [@@deprecated "Use [flatten_result] instead"][@@migrate { repl = Rel.flatten_result }] - (** Generate a result from [Ok gen], an error from [Error e]. - - Shrinks on [gen] if [Ok gen]. - Does not shrink if [Error e]. - - @since 0.13 - - @deprecated use {!flatten_result} instead. *) - val join : 'a t t -> 'a t (** Collapses a generator of generators to a generator. @@ -1466,9 +1214,6 @@ module Print : sig ['a] using [f], and then by {i printing} this value of type ['a] using [p]. *) - val comap : ('b -> 'a) -> 'a t -> 'b t [@@deprecated "Use [contramap] instead"][@@migrate { repl = Rel.contramap }] - (** @deprecated use {!contramap} instead. *) - val tup2 : 'a t -> 'b t -> ('a * 'b) t (** 2-tuple printer. Expects printers for each component. *) @@ -1574,11 +1319,6 @@ module Shrink : sig (** [int_agressive_towards destination n] gives all integers from [destination] to [n] (excluded). {b Be careful about time and memory} as the resulting list can be huge *) - - val int_aggressive : int -> int Seq.t [@@deprecated "Use [int_aggressive_towards 0] instead"][@@migrate { repl = Rel.int_aggressive_towards 0 }] - (** @deprecated Use [int_aggressive_towards 0] instead. - @since 0.7 *) - end (** {1 Generating Functions} @@ -1674,9 +1414,6 @@ module Observable : sig ['a] using [f], and then by {i consuming} this value of type ['a] using [o]. *) - val map : ('b -> 'a) -> 'a t -> 'b t [@@deprecated "Use [contramap] instead"][@@migrate { repl = Rel.contramap }] - (** @deprecated use {!contramap} instead. *) - val option : 'a t -> 'a option t (** [option o] wraps the observable [o] of ['a] into an observable of ['a option]. *) @@ -1976,21 +1713,6 @@ module TestResult : sig val is_failed : _ t -> bool (** Returns true iff the state is [Failed _] *) - - val stats : 'a t -> ('a stat * (int,int) Hashtbl.t) list [@@deprecated "Use [get_stats] instead"][@@migrate { repl = Rel.get_stats }] - (** Obtain statistics - @since 0.6 - @deprecated use {!get_stats} instead *) - - val warnings : _ t -> string list [@@deprecated "Use [get_warnings] instead"][@@migrate { repl = Rel.get_warnings }] - (** Obtain list of warnings - @since 0.10 - @deprecated use {!get_warnings} instead *) - - val collect : _ t -> (string,int) Hashtbl.t option [@@deprecated "Use [get_collect] instead"][@@migrate { repl = Rel.get_collect }] - (** Obtain statistics - @since 0.6 - @deprecated use {!get_collect} instead *) end module Test_exceptions : sig