Skip to content

Commit

Permalink
improved int shrinker
Browse files Browse the repository at this point in the history
  • Loading branch information
jmid committed Apr 20, 2022
1 parent 43b3962 commit c19ccd0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/QCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c19ccd0

Please sign in to comment.