From a661f277b8ba26f8f9bb3d86ec42fc9f05c5a755 Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 17 Sep 2024 09:59:05 +0200 Subject: [PATCH] Factor exp_dist_gen into two combinators --- lib/STM.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/STM.ml b/lib/STM.ml index 94d70191..03441c8e 100644 --- a/lib/STM.ml +++ b/lib/STM.ml @@ -159,14 +159,17 @@ struct let gen_cmds_size gen s size_gen = Gen.sized_size size_gen (gen_cmds gen s) - let exp_dist_gen = - let mean = 10. in - let skew = 0.75 in (* to avoid too many empty cmd lists *) + let exp_dist_gen mean = let unit_gen = Gen.float_bound_inclusive 1.0 in - Gen.map (fun p -> int_of_float (-. (mean *. (log p)) +. skew)) unit_gen + Gen.map (fun p -> -. mean *. (log p)) unit_gen + + let cmd_list_size_dist mean = + let skew = 0.75 in (* to avoid too many empty cmd lists *) + Gen.map (fun p -> int_of_float (p +. skew)) (exp_dist_gen mean) let arb_cmds s = - let cmds_gen = gen_cmds_size Spec.arb_cmd s exp_dist_gen in + let mean = 10. in (* generate on average ~10 cmds, ignoring skew *) + let cmds_gen = gen_cmds_size Spec.arb_cmd s (cmd_list_size_dist mean) in let shrinker = shrink_list ?shrink:(Spec.arb_cmd s).shrink in (* pass opt. elem. shrinker *) let ac = QCheck.make ~shrink:(Shrink.filter (cmds_ok Spec.init_state) shrinker) cmds_gen in (match (Spec.arb_cmd s).print with