From 5a67e371386ab8cc086c8b075591c76eecdc5b91 Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 22 Mar 2022 15:19:36 +0100 Subject: [PATCH 1/6] simpler list shrinker with better complexity --- src/core/QCheck.ml | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/core/QCheck.ml b/src/core/QCheck.ml index 91650b93..602e2ddc 100644 --- a/src/core/QCheck.ml +++ b/src/core/QCheck.ml @@ -727,37 +727,20 @@ module Shrink = struct ) done - let list_spine l yield = - let n = List.length l in - let chunk_size = ref ((n+1)/2) in - - (* push the [n] first elements of [l] into [q], return the rest of the list *) - let rec fill_queue n l q = match n,l with - | 0, _ -> l - | _, x::xs -> - Queue.push x q; - fill_queue (n-1) xs q - | _, _ -> assert false - in - - (* remove elements from the list, by chunks of size [chunk_size] (bigger - chunks first) *) - while !chunk_size > 0 do - let q = Queue.create () in - let l' = fill_queue !chunk_size l q in - (* remove [chunk_size] elements in queue *) - let rec pos_loop rev_prefix suffix = - yield (List.rev_append rev_prefix suffix); - match suffix with - | [] -> () - | x::xs -> - Queue.push x q; - let y = Queue.pop q in - (pos_loop [@tailcall]) (y::rev_prefix) xs - in - pos_loop [] l'; - chunk_size := !chunk_size / 2; - done + let rec list_spine l yield = + let rec split l len acc = match len,l with + | _,[] + | 0,_ -> List.rev acc, l + | _,x::xs -> split xs (len-1) (x::acc) in + match l with + | [] -> () + | [_] -> yield [] + | [x;y] -> yield []; yield [x]; yield [y] + | _::_ -> + let len = List.length l in + let xs,ys = split l ((1 + len) / 2) [] in + yield xs; + list_spine xs (fun xs' -> yield (xs'@ys)) let list_elems shrink l yield = (* try to shrink each element of the list *) From d731af8166c8c304096474f08f5c9e5f7c9f1fee Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 22 Mar 2022 15:26:21 +0100 Subject: [PATCH 2/6] use improved list shrinker for strings --- src/core/QCheck.ml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/core/QCheck.ml b/src/core/QCheck.ml index 602e2ddc..ee1f74b2 100644 --- a/src/core/QCheck.ml +++ b/src/core/QCheck.ml @@ -694,14 +694,6 @@ module Shrink = struct | None -> Iter.empty | Some x -> Iter.(return None <+> map (fun y->Some y) (s x)) - let string s yield = - for i =0 to String.length s-1 do - let s' = Bytes.init (String.length s-1) - (fun j -> if j () | Some shrink -> list_elems shrink l yield + let string (*?(shrink=char)*) s yield = + list ~shrink:char + (List.of_seq (String.to_seq s)) + (fun cs -> yield (String.of_seq (List.to_seq cs))) + let pair a b (x,y) yield = a x (fun x' -> yield (x',y)); b y (fun y' -> yield (x,y')) From 43b3962e980fe30065205e4d8972514a9d18e876 Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 22 Mar 2022 15:37:26 +0100 Subject: [PATCH 3/6] improved function shrinker --- src/core/QCheck.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/QCheck.ml b/src/core/QCheck.ml index ee1f74b2..0526c7a3 100644 --- a/src/core/QCheck.ml +++ b/src/core/QCheck.ml @@ -1328,7 +1328,7 @@ end = struct tbl; Buffer.contents b); p_shrink1=(fun yield -> - Shrink.list (tbl_to_list tbl) + Shrink.list_spine (tbl_to_list tbl) (fun l -> yield (make ~extend:false (tbl_of_list l))) ); @@ -1399,9 +1399,9 @@ module Fn = struct = function | Fun_tbl {fun_arb=a; fun_tbl=tbl; fun_default=def} -> let sh_v = match a.shrink with None -> Shrink.nil | Some s->s in - (Poly_tbl.shrink1 tbl >|= fun tbl' -> mk_repr tbl' a def) - <+> (sh_v def >|= fun def' -> mk_repr tbl a def') + <+> + (Poly_tbl.shrink1 tbl >|= fun tbl' -> mk_repr tbl' a def) <+> (Poly_tbl.shrink2 sh_v tbl >|= fun tbl' -> mk_repr tbl' a def) | Fun_map (g, r') -> From c19ccd0a068869fa2a579b94dcb59b556f38b692 Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 22 Mar 2022 15:32:06 +0100 Subject: [PATCH 4/6] 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 From 9f8dd541a944c86cbbaee8bb0193cdce1831da4b Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 22 Mar 2022 15:46:29 +0100 Subject: [PATCH 5/6] update expected output --- example/alcotest/output.txt.expected | 24 +- example/ounit/output.txt.expected | 6 +- example/output.txt.expected | 24 +- test/core/QCheck_expect_test.expected | 357 +++++++++++++++----------- 4 files changed, 231 insertions(+), 180 deletions(-) diff --git a/example/alcotest/output.txt.expected b/example/alcotest/output.txt.expected index 79e4f3cf..b4ec254a 100644 --- a/example/alcotest/output.txt.expected +++ b/example/alcotest/output.txt.expected @@ -9,30 +9,30 @@ Testing `my test'. ┌──────────────────────────────────────────────────────────────────────────────┐ │ [FAIL] suite 1 fail_sort_id. │ └──────────────────────────────────────────────────────────────────────────────┘ -test `fail_sort_id` failed on ≥ 1 cases: [1; 0] (after 20 shrink steps) -[exception] test `fail_sort_id` failed on ≥ 1 cases: [1; 0] (after 20 shrink steps) +test `fail_sort_id` failed on ≥ 1 cases: [1; 0] (after 11 shrink steps) +[exception] test `fail_sort_id` failed on ≥ 1 cases: [1; 0] (after 11 shrink steps) ────────────────────────────────────────────────────────────────────────────── ┌──────────────────────────────────────────────────────────────────────────────┐ │ [FAIL] suite 2 error_raise_exn. │ └──────────────────────────────────────────────────────────────────────────────┘ test `error_raise_exn` raised exception `Error` -on `0 (after 63 shrink steps)` +on `0 (after 1 shrink steps)` [exception] test `error_raise_exn` raised exception `Error` -on `0 (after 63 shrink steps)` +on `0 (after 1 shrink steps)` ────────────────────────────────────────────────────────────────────────────── ┌──────────────────────────────────────────────────────────────────────────────┐ │ [FAIL] suite 3 fail_check_err_message. │ └──────────────────────────────────────────────────────────────────────────────┘ test `fail_check_err_message` failed on ≥ 1 cases: -0 (after 7 shrink steps) +0 (after 1 shrink steps) this will always fail [exception] test `fail_check_err_message` failed on ≥ 1 cases: -0 (after 7 shrink steps) +0 (after 1 shrink steps) this will always @@ -46,15 +46,9 @@ Test debug_shrink successfully shrunk counter example (step 0) to: (3, 1) ~~~ Shrink ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Test debug_shrink successfully shrunk counter example (step 1) to: -(2, 1) -~~~ Shrink ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Test debug_shrink successfully shrunk counter example (step 2) to: -(2, 0) -~~~ Shrink ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Test debug_shrink successfully shrunk counter example (step 3) to: -(1, 0) +(0, 1) law debug_shrink: 2 relevant cases (2 total) -test `debug_shrink` failed on ≥ 1 cases: (1, 0) (after 3 shrink steps) -[exception] test `debug_shrink` failed on ≥ 1 cases: (1, 0) (after 3 shrink steps) +test `debug_shrink` failed on ≥ 1 cases: (0, 1) (after 1 shrink steps) +[exception] test `debug_shrink` failed on ≥ 1 cases: (0, 1) (after 1 shrink steps) ────────────────────────────────────────────────────────────────────────────── 4 failures! 6 tests run. diff --git a/example/ounit/output.txt.expected b/example/ounit/output.txt.expected index cb6e4427..8a6dcb99 100644 --- a/example/ounit/output.txt.expected +++ b/example/ounit/output.txt.expected @@ -6,7 +6,7 @@ Error: tests:2:error_raise_exn (in the log). test `error_raise_exn` raised exception `Dune__exe__QCheck_ounit_test.Error` -on `0 (after 63 shrink steps)` +on `0 (after 1 shrink steps)` ------------------------------------------------------------------------------ ============================================================================== @@ -18,7 +18,7 @@ Error: tests:3:fail_check_err_message (in the code). test `fail_check_err_message` failed on ≥ 1 cases: -0 (after 7 shrink steps) +0 (after 1 shrink steps) this will always @@ -35,7 +35,7 @@ Error: tests:1:fail_sort_id (in the log). Error: tests:1:fail_sort_id (in the code). -test `fail_sort_id` failed on ≥ 1 cases: [1; 0] (after 20 shrink steps) +test `fail_sort_id` failed on ≥ 1 cases: [1; 0] (after 11 shrink steps) ------------------------------------------------------------------------------ diff --git a/example/output.txt.expected b/example/output.txt.expected index 6692c769..2b45a9a0 100644 --- a/example/output.txt.expected +++ b/example/output.txt.expected @@ -2,13 +2,13 @@ random seed: 1234 --- Failure -------------------------------------------------------------------- -Test should_fail_sort_id failed (18 shrink steps): +Test should_fail_sort_id failed (11 shrink steps): [1; 0] === Error ====================================================================== -Test should_error_raise_exn errored on (63 shrink steps): +Test should_error_raise_exn errored on (1 shrink steps): 0 @@ -59,9 +59,9 @@ stats num: --- Failure -------------------------------------------------------------------- -Test FAIL_pred_map_commute failed (107 shrink steps): +Test FAIL_pred_map_commute failed (116 shrink steps): -([0], {_ -> -21}, {-21 -> true; _ -> false}) +([0], {0 -> -1; _ -> 0}, {0 -> true; _ -> false}) --- Failure -------------------------------------------------------------------- @@ -71,34 +71,34 @@ Test FAIL_fun2_pred_strings failed (1 shrink steps): --- Failure -------------------------------------------------------------------- -Test fold_left fold_right failed (24 shrink steps): +Test fold_left fold_right failed (15 shrink steps): -(0, [1], {(1, 0) -> 1; _ -> 0}) +(0, [1], {(0, 1) -> 1; _ -> 0}) +++ Messages ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Messages for test fold_left fold_right: -l=[1], fold_left=1, fold_right=0 +l=[1], fold_left=0, fold_right=1 --- Failure -------------------------------------------------------------------- -Test fold_left fold_right uncurried failed (97 shrink steps): +Test fold_left fold_right uncurried failed (39 shrink steps): -({(1, 7) -> 0; _ -> 7}, 0, [1; 0]) +({(0, 7) -> 1; _ -> 0}, 0, [7]) --- Failure -------------------------------------------------------------------- -Test long_shrink failed (149 shrink steps): +Test long_shrink failed (89 shrink steps): ([0], [-1]) --- Failure -------------------------------------------------------------------- -Test mod3_should_fail failed (84 shrink steps): +Test mod3_should_fail failed (1 shrink steps): --21 +0 +++ Stats for stats_neg ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/test/core/QCheck_expect_test.expected b/test/core/QCheck_expect_test.expected index 0a00ceb1..e91a781e 100644 --- a/test/core/QCheck_expect_test.expected +++ b/test/core/QCheck_expect_test.expected @@ -1,5 +1,5 @@ random seed: 1234 -50 7 4 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) +50 7 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) @@ -8,114 +8,171 @@ random seed: 1234 (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) (6,fun,50) (0,fun,2) (7,fun,66) (54,fun,9) (2,fun,5) (90,fun,4) (1,fun,4) (37,fun,7) (7,fun,1) (8,fun,5) 2724675603984413065 -1362337801992206533 -681168900996103267 -340584450498051634 -170292225249025817 -85146112624512909 -42573056312256455 -21286528156128228 -10643264078064114 -5321632039032057 -2660816019516029 -1330408009758015 -665204004879008 -332602002439504 -166301001219752 -83150500609876 -41575250304938 -20787625152469 -10393812576235 -5196906288118 -2598453144059 -1299226572030 -649613286015 -324806643008 -162403321504 -81201660752 -40600830376 -20300415188 -10150207594 -5075103797 -2537551899 -1268775950 -634387975 -317193988 -158596994 -79298497 -39649249 -19824625 -9912313 -4956157 -2478079 -1239040 -619520 -309760 -154880 -77440 -38720 -19360 -9680 -4840 -2420 -1210 -605 -303 -152 -76 -38 -19 -10 -5 -3 +0 +1362337801992206532 +0 +681168900996103266 +0 +340584450498051633 +0 +170292225249025816 +0 +85146112624512908 +0 +42573056312256454 +0 +21286528156128227 +0 +10643264078064113 +0 +5321632039032056 +0 +2660816019516028 +0 +1330408009758014 +0 +665204004879007 +0 +332602002439503 +0 +166301001219751 +0 +83150500609875 +0 +41575250304937 +0 +20787625152468 +0 +10393812576234 +0 +5196906288117 +0 +2598453144058 +0 +1299226572029 +0 +649613286014 +0 +324806643007 +0 +162403321503 +0 +81201660751 +0 +40600830375 +0 +20300415187 +0 +10150207593 +0 +5075103796 +0 +2537551898 +0 +1268775949 +0 +634387974 +0 +317193987 +0 +158596993 +0 +79298496 +0 +39649248 +0 +19824624 +0 +9912312 +0 +4956156 +0 +2478078 +0 +1239039 +0 +619519 +0 +309759 +0 +154879 +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71; 14; 26; 47; 5; 1; 6; 34; 9; 4; 2; 37; 3; 8; 4; 31; 6; 2; 1; 0; 7; 5; 1; 0; 15; 6; 1; 8; 13; 0; 6; 2; 4; 2; 6; 6; 1; 4; 1; 9; 79; 0; 87; 6; 8; 8; 62; 1; 4; 62; 6; 31; 1; 5; 6; 5; 9; 3; 3; 1; 79; 4; 3; 2; 67; 5; 7; 12; 70; 8; 8; 6] +[7; 1; 42; 1; 8; 5; 3; 9; 5; 38; 3; 3; 0; 1; 98; 1; 4; 13; 9; 2; 6; 9; 47; 6; 5; 8; 8; 6; 0; 9; 7; 2; 8; 6; 62; 6; 4; 31; 19; 1; 41; 60; 6; 5; 8; 1; 1; 4; 7; 7; 0; 5; 5; 71; 14; 26; 47; 5; 1; 6; 34; 9; 4] +[7; 1; 42; 1; 8; 5; 3; 9; 5; 38; 3; 3; 0; 1; 98; 1; 4; 13; 9; 2; 6; 9; 47; 6; 5; 8; 8; 6; 0; 9; 7; 2] +[7; 1; 42; 1; 8; 5; 3; 9; 5; 38; 3; 3; 0; 1; 98; 1] +[7; 1; 42; 1; 8; 5; 3; 9] +[7; 1; 42; 1] +[7; 1] +[42; 1] +[7; 42; 1] +[1; 42; 1] +[1; 42] +[1] +[1; 1] +[] +[1] +[1] +[0; 1] +[1; 0] --- Failure -------------------------------------------------------------------- -Test should_fail_sort_id failed (18 shrink steps): +Test should_fail_sort_id failed (11 shrink steps): [1; 0] === Error ====================================================================== -Test should_error_raise_exn errored on (63 shrink steps): +Test should_error_raise_exn errored on (1 shrink steps): 0 @@ -166,9 +223,9 @@ stats num: --- Failure -------------------------------------------------------------------- -Test with shrinking retries failed (1 shrink steps): +Test with shrinking retries failed (0 shrink steps): -4 +7 !!! Warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -203,31 +260,31 @@ Test char never produces '\255' failed (0 shrink steps): --- Failure -------------------------------------------------------------------- -Test big bound issue59 failed (52 shrink steps): +Test big bound issue59 failed (51 shrink steps): 209609 --- Failure -------------------------------------------------------------------- -Test long_shrink failed (149 shrink steps): +Test long_shrink failed (89 shrink steps): ([0], [-1]) --- Failure -------------------------------------------------------------------- -Test ints arent 0 mod 3 failed (84 shrink steps): +Test ints arent 0 mod 3 failed (1 shrink steps): --21 +0 --- Failure -------------------------------------------------------------------- -Test ints are 0 failed (62 shrink steps): +Test ints are 0 failed (61 shrink steps): 1 --- Failure -------------------------------------------------------------------- -Test ints < 209609 failed (52 shrink steps): +Test ints < 209609 failed (51 shrink steps): 209609 @@ -245,27 +302,27 @@ Test char never produces 'abcdef' failed (0 shrink steps): --- Failure -------------------------------------------------------------------- -Test strings are empty failed (249 shrink steps): +Test strings are empty failed (145 shrink steps): -"\177" +"\000" --- Failure -------------------------------------------------------------------- -Test string never has a \000 char failed (25 shrink steps): +Test string never has a \000 char failed (8 shrink steps): "\000" --- Failure -------------------------------------------------------------------- -Test string never has a \255 char failed (249 shrink steps): +Test string never has a \255 char failed (14 shrink steps): "\255" --- Failure -------------------------------------------------------------------- -Test strings have unique chars failed (248 shrink steps): +Test strings have unique chars failed (13 shrink steps): -"\206\206" +"\129\129" --- Failure -------------------------------------------------------------------- @@ -275,175 +332,175 @@ Test pairs have different components failed (0 shrink steps): --- Failure -------------------------------------------------------------------- -Test pairs have same components failed (125 shrink steps): +Test pairs have same components failed (62 shrink steps): (0, 1) --- Failure -------------------------------------------------------------------- -Test pairs have a zero component failed (124 shrink steps): +Test pairs have a zero component failed (122 shrink steps): (-1, 1) --- Failure -------------------------------------------------------------------- -Test pairs are (0,0) failed (125 shrink steps): +Test pairs are (0,0) failed (62 shrink steps): (0, 1) --- Failure -------------------------------------------------------------------- -Test pairs are ordered failed (827 shrink steps): +Test pairs are ordered failed (93 shrink steps): (1, 0) --- Failure -------------------------------------------------------------------- -Test pairs are ordered reversely failed (124 shrink steps): +Test pairs are ordered reversely failed (62 shrink steps): (0, 1) --- Failure -------------------------------------------------------------------- -Test pairs sum to less than 128 failed (116 shrink steps): +Test pairs sum to less than 128 failed (56 shrink steps): (0, 128) --- Failure -------------------------------------------------------------------- -Test pairs lists rev concat failed (140 shrink steps): +Test pairs lists rev concat failed (84 shrink steps): ([0], [1]) --- Failure -------------------------------------------------------------------- -Test pairs lists no overlap failed (22 shrink steps): +Test pairs lists no overlap failed (24 shrink steps): ([0], [0]) --- Failure -------------------------------------------------------------------- -Test triples have pair-wise different components failed (7 shrink steps): +Test triples have pair-wise different components failed (3 shrink steps): -(0, 7, 7) +(0, 0, 0) --- Failure -------------------------------------------------------------------- -Test triples have same components failed (188 shrink steps): +Test triples have same components failed (63 shrink steps): (0, -1, 0) --- Failure -------------------------------------------------------------------- -Test triples are ordered failed (188 shrink steps): +Test triples are ordered failed (63 shrink steps): (0, -1, 0) --- Failure -------------------------------------------------------------------- -Test triples are ordered reversely failed (188 shrink steps): +Test triples are ordered reversely failed (63 shrink steps): (0, 0, 1) --- Failure -------------------------------------------------------------------- -Test quadruples have pair-wise different components failed (23 shrink steps): +Test quadruples have pair-wise different components failed (4 shrink steps): (0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test quadruples have same components failed (250 shrink steps): +Test quadruples have same components failed (124 shrink steps): (0, 1, 0, 1) --- Failure -------------------------------------------------------------------- -Test quadruples are ordered failed (251 shrink steps): +Test quadruples are ordered failed (64 shrink steps): (0, 0, -1, 0) --- Failure -------------------------------------------------------------------- -Test quadruples are ordered reversely failed (251 shrink steps): +Test quadruples are ordered reversely failed (64 shrink steps): (0, 0, 0, 1) --- Failure -------------------------------------------------------------------- -Test forall (a, b) in nat: a < b failed (13 shrink steps): +Test forall (a, b) in nat: a < b failed (6 shrink steps): (0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c) in nat: a < b < c failed (15 shrink steps): +Test forall (a, b, c) in nat: a < b < c failed (3 shrink steps): (0, 0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c, d) in nat: a < b < c < d failed (23 shrink steps): +Test forall (a, b, c, d) in nat: a < b < c < d failed (4 shrink steps): (0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c, d, e) in nat: a < b < c < d < e failed (28 shrink steps): +Test forall (a, b, c, d, e) in nat: a < b < c < d < e failed (5 shrink steps): (0, 0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c, d, e, f) in nat: a < b < c < d < e < f failed (30 shrink steps): +Test forall (a, b, c, d, e, f) in nat: a < b < c < d < e < f failed (6 shrink steps): (0, 0, 0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c, d, e, f, g) in nat: a < b < c < d < e < f < g failed (31 shrink steps): +Test forall (a, b, c, d, e, f, g) in nat: a < b < c < d < e < f < g failed (7 shrink steps): (0, 0, 0, 0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c, d, e, f, g, h) in nat: a < b < c < d < e < f < g < h failed (35 shrink steps): +Test forall (a, b, c, d, e, f, g, h) in nat: a < b < c < d < e < f < g < h failed (8 shrink steps): (0, 0, 0, 0, 0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test forall (a, b, c, d, e, f, g, h, i) in nat: a < b < c < d < e < f < g < h < i failed (42 shrink steps): +Test forall (a, b, c, d, e, f, g, h, i) in nat: a < b < c < d < e < f < g < h < i failed (9 shrink steps): (0, 0, 0, 0, 0, 0, 0, 0, 0) --- Failure -------------------------------------------------------------------- -Test bind ordered pairs failed (125 shrink steps): +Test bind ordered pairs failed (2 shrink steps): (0, 0) --- Failure -------------------------------------------------------------------- -Test bind list_size constant failed (50 shrink steps): +Test bind list_size constant failed (11 shrink steps): (4, [0; 0; 0; 0]) --- Failure -------------------------------------------------------------------- -Test lists are empty failed (11 shrink steps): +Test lists are empty failed (9 shrink steps): [0] --- Failure -------------------------------------------------------------------- -Test lists shorter than 10 failed (50 shrink steps): +Test lists shorter than 10 failed (16 shrink steps): [0; 0; 0; 0; 0; 0; 0; 0; 0; 0] --- Failure -------------------------------------------------------------------- -Test lists shorter than 432 failed (1696 shrink steps): +Test lists shorter than 432 failed (417 shrink steps): [...] list length: 432 @@ -461,21 +518,21 @@ Test lists equal to duplication failed (20 shrink steps): --- Failure -------------------------------------------------------------------- -Test lists have unique elems failed (7 shrink steps): +Test lists have unique elems failed (8 shrink steps): -[7; 7] +[1; 1] --- Failure -------------------------------------------------------------------- -Test tree contains only 42 failed (10 shrink steps): +Test tree contains only 42 failed (2 shrink steps): Leaf 0 --- Failure -------------------------------------------------------------------- -Test fail_pred_map_commute failed (107 shrink steps): +Test fail_pred_map_commute failed (116 shrink steps): -([0], {_ -> -21}, {-21 -> true; _ -> false}) +([0], {0 -> -1; _ -> 0}, {0 -> true; _ -> false}) --- Failure -------------------------------------------------------------------- @@ -485,34 +542,34 @@ Test fail_pred_strings failed (1 shrink steps): --- Failure -------------------------------------------------------------------- -Test fold_left fold_right failed (24 shrink steps): +Test fold_left fold_right failed (15 shrink steps): -(0, [1], {(1, 0) -> 1; _ -> 0}) +(0, [1], {(0, 1) -> 1; _ -> 0}) +++ Messages ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Messages for test fold_left fold_right: -l=[1], fold_left=1, fold_right=0 +l=[1], fold_left=0, fold_right=1 --- Failure -------------------------------------------------------------------- -Test fold_left fold_right uncurried failed (97 shrink steps): +Test fold_left fold_right uncurried failed (39 shrink steps): -({(1, 7) -> 0; _ -> 7}, 0, [1; 0]) +({(0, 7) -> 1; _ -> 0}, 0, [7]) --- Failure -------------------------------------------------------------------- -Test fold_left fold_right uncurried fun last failed (21 shrink steps): +Test fold_left fold_right uncurried fun last failed (22 shrink steps): -(0, [1], {(0, 1) -> 0; _ -> 1}) +(0, [1], {(0, 1) -> 1; _ -> 0}) --- Failure -------------------------------------------------------------------- -Test fold_left test, fun first failed (40 shrink steps): +Test fold_left test, fun first failed (272 shrink steps): -({_ -> ""}, "z", [], [0]) +({_ -> ""}, "\000", [], [0]) --- Failure -------------------------------------------------------------------- From 96b08d75b15ce4e087e70a6ce1c332445a176836 Mon Sep 17 00:00:00 2001 From: Jan Midtgaard Date: Tue, 19 Apr 2022 14:19:27 +0200 Subject: [PATCH 6/6] update expected unit test output --- test/core/QCheck_unit_tests.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/core/QCheck_unit_tests.ml b/test/core/QCheck_unit_tests.ml index 9ace8fce..7b3a0fdc 100644 --- a/test/core/QCheck_unit_tests.ml +++ b/test/core/QCheck_unit_tests.ml @@ -19,13 +19,13 @@ module Shrink = struct let test_int () = List.iter (alco_check Alcotest.int (trace_false Shrink.int) "on repeated failure") - [ ("int 100", 100, [50; 75; 88; 94; 97; 99; 99]); (*WTF?*) - ("int 1000", 1000, [500; 750; 875; 938; 969; 985; 993; 997; 999; 999]); (*WTF?*) - ("int (-26)", -26, [-13; -20; -23; -25; -25]) ]; (*WTF?*) + [ ("int 100", 100, [0; 50; 75; 87; 93; 96; 98; 99]); + ("int 1000", 1000, [0; 500; 750; 875; 937; 968; 984; 992; 996; 998; 999]); + ("int (-26)", -26, [0; -13; -19; -22; -24; -25]) ]; List.iter (alco_check Alcotest.int (trace_true Shrink.int) "on repeated success") - [ ("int 100", 100, [50; 25; 13; 7; 4; 2; 1; 0]); - ("int 1000", 1000, [500; 250; 125; 63; 32; 16; 8; 4; 2; 1; 0]); - ("int (-26)", -26, [-13; -7; -4; -2; -1; 0]) ] + [ ("int 100", 100, [0]); + ("int 1000", 1000, [0]); + ("int (-26)", -26, [0]) ] let test_int32 () = List.iter (alco_check Alcotest.int32 (trace_false Shrink.int32) "on repeated failure") @@ -69,14 +69,14 @@ module Check_exn = struct let test_fail_always () = let name = "will-always-fail" in - let counterex_str = "0 (after 63 shrink steps)" in + let counterex_str = "0 (after 1 shrink steps)" in let run_test () = check_exn QCheck.(Test.make ~name int (fun _ -> false)) in Alcotest.check_raises "Fail" (Test.Test_fail (name,[counterex_str])) run_test let test_fail_random () = let name = "list is own reverse" in - let counterex_str = "[0; -1] (after 126 shrink steps)" in + let counterex_str = "[0; 1] (after 63 shrink steps)" in let run_test () = check_exn QCheck.(Test.make ~name (list int) (fun l -> List.rev l = l)) in @@ -86,7 +86,7 @@ module Check_exn = struct let test_error () = let name = "will-always-error" in - let counterex_str = "0 (after 63 shrink steps)" in + let counterex_str = "0 (after 1 shrink steps)" in let run_test () = let () = Printexc.record_backtrace false in (* for easier pattern-matching below *) check_exn QCheck.(Test.make ~name int (fun _ -> raise MyError)) in