Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QCheck: improve int shrinker fast path #173

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/alcotest/output.txt.expected
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Testing `my test'.
│ [FAIL] suite 1 fail_sort_id. │
└──────────────────────────────────────────────────────────────────────────────┘

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 17 shrink steps)

[exception] 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 17 shrink steps)



Expand Down
6 changes: 3 additions & 3 deletions example/ounit/output.txt.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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)`

------------------------------------------------------------------------------
==============================================================================
Expand All @@ -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
Expand All @@ -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 17 shrink steps)


------------------------------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions example/output.txt.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ random seed: 1234

--- Failure --------------------------------------------------------------------

Test should_fail_sort_id failed (18 shrink steps):
Test should_fail_sort_id failed (15 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

Expand Down Expand Up @@ -59,9 +59,9 @@ stats num:

--- Failure --------------------------------------------------------------------

Test FAIL_pred_map_commute failed (127 shrink steps):
Test FAIL_pred_map_commute failed (128 shrink steps):

([3], {_ -> 0}, {3 -> false; _ -> true})
([0], {_ -> -1}, {0 -> false; _ -> true})

--- Failure --------------------------------------------------------------------

Expand All @@ -71,7 +71,7 @@ Test FAIL_fun2_pred_strings failed (1 shrink steps):

--- Failure --------------------------------------------------------------------

Test fold_left fold_right failed (25 shrink steps):
Test fold_left fold_right failed (23 shrink steps):

(0, [1], {(1, 0) -> 1; _ -> 0})

Expand All @@ -84,21 +84,21 @@ l=[1], fold_left=1, fold_right=0

--- Failure --------------------------------------------------------------------

Test fold_left fold_right uncurried failed (111 shrink steps):
Test fold_left fold_right uncurried failed (104 shrink steps):

({(5, 7) -> 0; _ -> 7}, 0, [5; 0])
({(7, 0) -> 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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Expand Down
6 changes: 3 additions & 3 deletions src/core/QCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ module Shrink = struct
let int x yield =
let y = ref x in
(* try some divisors *)
while !y < -2 || !y >2 do y := !y / 2; yield (x - !y); done; (* fast path *)
while !y < -2 || !y >2 do yield (x - !y); y := !y / 2; done; (* fast path *)
if x>0 then yield (x-1);
if x<0 then yield (x+1);
()
Expand All @@ -480,7 +480,7 @@ module Shrink = struct
let open Int32 in
let y = ref x in
(* try some divisors *)
while !y < -2l || !y > 2l do y := div !y 2l; yield (sub x !y); done; (* fast path *)
while !y < -2l || !y > 2l do yield (sub x !y); y := div !y 2l; done; (* fast path *)
if x>0l then yield (pred x);
if x<0l then yield (succ x);
()
Expand All @@ -489,7 +489,7 @@ module Shrink = struct
let open Int64 in
let y = ref x in
(* try some divisors *)
while !y < -2L || !y > 2L do y := div !y 2L; yield (sub x !y); done; (* fast path *)
while !y < -2L || !y > 2L do yield (sub x !y); y := div !y 2L; done; (* fast path *)
if x>0L then yield (pred x);
if x<0L then yield (succ x);
()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,168 +1,4 @@
random seed: 1234
2724675603984413065
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
0
77439
0
38719
0
19359
0
9679
0
4839
0
2419
0
1209
0
604
0
302
0
151
0
75
0
37
0
18
0
9
0
4
0
2
0
1
0
[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; 2; 37; 3; 8; 4; 31; 6; 2; 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 7; 7]
[]
[9; 61; 8; 4; 69; 2; 0; 72; 4; 41; 3; 8; 75; 83; 7; 7; 3; 9; 5; 8; 4; 1; 0; 2; 1; 4; 7; 6; 2; 1; 4; 86; 3; 79; 7; 86; 52; 39; 19; 0; 4; 7; 7; 7; 0; 4; 8; 8; 0; 5; 13; 1; 5; 0; 7; 12; 64; 34; 1; 1; 85; 8; 2; 9; 76; 0; 2; 5; 76; 69; 8; 8; 0; 1; 2; 2; 4; 60; 29; 5; 9; 4; 0; 8; 3; 3; 5; 1; 35; 8; 2; 7; 23; 61; 56; 8; 1; 1; 78; 7; 5; 0; 30; 9; 3; 7; 28; 57; 98; 3; 52; 3; 82; 7; 5; 5; 6; 8; 1; 6; 8; 9; 8; 16; 0]
[]
[1; 9; 8; 28; 47; 8; 5; 6; 8; 9; 2; 5; 8; 30; 6; 8; 84; 0; 6; 7; 76; 7; 9; 1; 0; 5; 76; 95; 2; 2; 1; 45; 7; 8; 8; 1; 6; 37; 5; 6; 73; 8; 0; 85; 8; 0; 4; 5; 2; 0; 26; 59; 0; 5; 13; 4; 7; 3; 6; 8; 1; 3]
[]
[5; 0; 0; 4; 10; 2; 4; 9; 5; 73; 6; 1; 5; 5; 3; 10; 5; 31; 1; 4; 3; 8; 9; 13; 41; 20; 96; 5; 1; 2; 8]
[]
[9; 8; 73; 5; 8; 2; 1; 8; 2; 6; 4; 18; 5; 76; 3]
[]
[0; 6; 2; 8; 8; 1; 4]
[]
[5; 2; 3]
[3; 2; 7; 3; 3]
[]
[5; 3]
[5; 3; 2]
[9; 87; 7; 0]
[0; 2; 7; 3; 3]
[0; 0; 7; 3; 3]
[0; 0; 0; 3; 3]
[0; 0; 0; 0; 3]
[0; 0; 0; 0; 0]

--- Failure --------------------------------------------------------------------

Expand Down
8 changes: 3 additions & 5 deletions test/core/QCheck2_expect_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module Shrink = struct

let ints_are_0 =
Test.make ~name:"ints are 0" ~count:1000 ~print:Print.int
Gen.int (fun i -> Printf.printf "%i\n" i; i = 0)
Gen.int (fun i -> i = 0)

(* test from issue #59 *)
let ints_smaller_209609 =
Expand Down Expand Up @@ -195,11 +195,9 @@ module Shrink = struct
(fun s -> String.to_seq s |> Seq.fold_left (fun acc c -> acc && c <> '\255') true)

(* tests from issue #64 *)
let print_list xs = print_endline Print.(list int xs)

let lists_are_empty_issue_64 =
Test.make ~name:"lists are empty" ~print:Print.(list int)
Gen.(list small_int) (fun xs -> print_list xs; xs = [])
Gen.(list small_int) (fun xs -> xs = [])

let list_shorter_10 =
Test.make ~name:"lists shorter than 10" ~print:Print.(list int)
Expand Down Expand Up @@ -230,7 +228,7 @@ module Shrink = struct
Test.make ~name:"lists have unique elems" ~print:Print.(list int)
Gen.(list small_int)
(fun xs -> let ys = List.sort_uniq Int.compare xs in
print_list xs; List.length xs = List.length ys)
List.length xs = List.length ys)

let tree_contains_only_42 =
Test.make ~name:"tree contains only 42" ~print:IntTree.print_tree
Expand Down
File renamed without changes.
Loading