package bam

  1. Overview
  2. Docs

This module contains the various strinking strategies which can be used with the generators below.

type 'a t =
  1. | Default : 'a t
    (*

    Default strategy for all the generators defined in this module. Refer to the documentation of each generator to know what the default strategy is.

    *)
  2. | Manual : ('a -> 'a Seq.t) -> 'a t
    (*

    Instead of relying on a built-in strategy, anyone can define its own shrinking strategy. To do so, given a value, the user must provide a sequence of "smaller" values.

    *)
  3. | Pair_left : ('a * 'b) t
    (*

    Shrinking strategy for pairs where the first component is shrunk first.

    *)
  4. | Pair_right : ('a * 'b) t
    (*

    Shrinking strategy for pairs where the second component is shrunk first.

    *)
  5. | Pair_compare : (('a * 'b) -> ('a * 'b) -> Int.t) -> ('a * 'b) t
    (*

    Shrinking strategy for pairs where the function comparison is given to know which pair to handle first. For example Pair_compare (fun _ _ -> -1) is equivalent to Pair_left. Pair_compare (fun left right -> compare (fst left + snd left) (fst right + snd right)) handles pair of integers by minimizing first the sum of their component.

    *)
  6. | Char : Char.t -> Char.t t
    (*

    Shrinking strategy for chars. The shrinker will try to reduce samples to the char given.

    *)
  7. | Bool : Bool.t -> Bool.t t
    (*

    Shrinking strategy for bool. The shrinker will try to reduce samples to the bool given.

    *)
  8. | Float : Float.t -> Float.t t
    (*

    Shrinking strategy for float. The shrinker will try to reduce samples to the float given.

    The strategy split the initial float into a pair of a fractional and integral part. Then the strategy behaves as Pair_left where the first component is the integral part and the second component is the fractional part. The shrinking behavior for the integral part behaves as the Int n strategy where n is the integral part of the float given. The shrinking behavior for the fractional part tries to minimize the number of decimals.

    This strategy is syntactic sugar for Float_precision with exhaustive_search_digits=0 and precision_digits=15.

    *)
  9. | Float_precision : {
    1. exhaustive_search_digits : int;
    2. precision_digits : int;
    3. target : Float.t;
    } -> Float.t t
    (*

    This shrinking strategy allows to enumerate the float numbers that can be represented with exhaustive_search_digits digits. While precision_digits allows the search up to precision_digits digits with respect to the original counter-example. arget is the same as Float.

    *)
  10. | Int : Int.t -> Int.t t
    (*

    Shrinking strategy for int. The shrinker will try to reduce samples to the int given. The strategy follows a binary search starting with the initial sample to the integer provided by the strategy.

    *)
  11. | Int32 : Int32.t -> Int32.t t
    (*

    See Int

    *)
  12. | Int64 : Int64.t -> Int64.t t
    (*

    See Int

    *)
  13. | Skip : {
    1. eq : 'a -> 'a -> bool;
    2. skip : [ `Auto | `Int of Int.t ];
    } -> 'a List.t t
    (*

    Shrinking strategy for lists. The shrinker will try to reduce first on the size on the list and then shrink the elements of the lists. This strategy will try to shrink to a smaller list by skipping some elements.

    Assuming the initial sample is a;b;c;d, it can first shrink towards a list of size 2 such as a;c or b;d, while the prefix strategy can always shrink to a prefix. Hence for a list of size 2 it must be a;b (and then the shrinking will shrink on a and b individually).

    With `Auto, the tool tries to infer a good value so that the shrinking strategy remains short. With `Int n, the user provides the number of elements that can be skipped. This can be quite time consuming since such a strategy is at least exponential with respect to the initial size of the list.

    *)
  14. | Prefix : 'a List.t t
    (*

    Shrinking strategy for lists. The shrinker will try to reduce first on the size on the list and then shrink the elements of the lists. The strategy will shrink towards a prefix of the list.

    *)
  15. | Suffix : 'a List.t t
    (*

    Shrinking strategy for lists. The shrinker will try to reduce first on the size on the list and then shrink the elements of the lists. The strategy will shrink towards a suffix of the list.

    *)
val skip_auto : 'a list t

skip_auto is an alias for Skip {eq=(=); skip=`Auto}

OCaml

Innovation. Community. Security.