diff --git a/src/core/QCheck2.ml b/src/core/QCheck2.ml index 8bd8c41a..ed0eac74 100644 --- a/src/core/QCheck2.ml +++ b/src/core/QCheck2.ml @@ -477,11 +477,13 @@ module Gen = struct let oneof (l : 'a t list) : 'a t = int_range 0 (List.length l - 1) >>= List.nth l - let oneofl (l : 'a list) : 'a t = + let oneof_l (l : 'a list) : 'a t = int_range 0 (List.length l - 1) >|= List.nth l + let oneofl = oneof_l - let oneofa (a : 'a array) : 'a t = + let oneof_a (a : 'a array) : 'a t = int_range 0 (Array.length a - 1) >|= Array.get a + let oneofa = oneof_a let int_small_signed : int t = fun st -> if RS.bool st @@ -503,11 +505,13 @@ module Gen = struct in aux 0 l - let frequencyl (l : (int * 'a) list) : 'a t = + let frequency_l (l : (int * 'a) list) : 'a t = List.map (fun (weight, value) -> (weight, pure value)) l |> frequency + let frequencyl = frequency_l - let frequencya a = frequencyl (Array.to_list a) + let frequency_a a = frequencyl (Array.to_list a) + let frequencya = frequency_a 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 diff --git a/src/core/QCheck2.mli b/src/core/QCheck2.mli index 5400daf6..2a6048f7 100644 --- a/src/core/QCheck2.mli +++ b/src/core/QCheck2.mli @@ -551,18 +551,40 @@ module Gen : sig @raise Invalid_argument or Failure if [l] is empty *) - val oneofl : 'a list -> 'a t + val oneof_l : 'a list -> 'a t + (** [oneof_l 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 + + @since NEXT_RELEASE + *) + + val oneofl : 'a list -> 'a t (** [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_l} *) + val oneof_a : 'a array -> 'a t + (** [oneof_a 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 [l] is empty + + @since NEXT_RELEASE + *) + val oneofa : 'a array -> 'a t (** [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 [l] is empty + + @deprecated use {!oneof_a} *) val frequency : (int * 'a t) list -> 'a t @@ -572,18 +594,40 @@ module Gen : sig Shrinks towards the first element of the list. *) + val frequency_l : (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. + + Shrinks towards the first element of the list. + + @since NEXT_RELEASE + *) + val frequencyl : (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. Shrinks towards the first element of the list. + + @deprecated use {!frequency_l} *) + val frequency_a : (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. + + Shrinks towards the first element of the array. + + @since NEXT_RELEASE + *) + val frequencya : (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. Shrinks towards the first element of the array. + + @deprecated use {!frequency_a} *) (** {3 Shuffling elements} *)