From c19ccd0a068869fa2a579b94dcb59b556f38b692 Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 22 Mar 2022 15:32:06 +0100 Subject: [PATCH] improved int shrinker --- src/core/QCheck.ml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/QCheck.ml b/src/core/QCheck.ml index 0526c7a3..a375f62c 100644 --- a/src/core/QCheck.ml +++ b/src/core/QCheck.ml @@ -650,14 +650,17 @@ module Shrink = struct let unit = nil - (* balanced shrinker for integers (non-exhaustive) *) + (* inspired by QCheck2's int shrinker algorithm (non-exhaustive) *) let int x yield = - let y = ref x in + let curr = ref 0 in (*to return 0 repeatedly *) (*was: let curr = ref (x/2) *) (* try some divisors *) - while !y < -2 || !y >2 do y := !y / 2; yield (x - !y); done; (* fast path *) - if x>0 then yield (x-1); - if x<0 then yield (x+1); - () + while !curr <> x do + yield !curr; + let half_diff = (x - !curr)/2 in (*was: let half_diff = (x/2) - (!curr/2) in *) + if half_diff = 0 + then curr := x + else curr := !curr + half_diff + done let int32 x yield = let open Int32 in