Skip to content

Commit

Permalink
Tests for tup2..9 generators and shrinkers
Browse files Browse the repository at this point in the history
  • Loading branch information
vch9 committed Dec 3, 2021
1 parent 7d41ebe commit c830129
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 2 deletions.
126 changes: 126 additions & 0 deletions test/core/QCheck2_expect_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,60 @@ module Generator = struct
IntTree.gen_tree
(fun tree -> IntTree.(rev_tree (rev_tree tree)) = tree)

let test_tup2 =
Test.make ~count:10
~name:"forall x in (0, 1): x = (0, 1)"
Gen.(tup2 (pure 0) (pure 1))
(fun x -> x = (0, 1))

let test_tup3 =
Test.make ~count:10
~name:"forall x in (0, 1, 2): x = (0, 1, 2)"
Gen.(tup3 (pure 0) (pure 1) (pure 2))
(fun x -> x = (0, 1, 2))

let test_tup4 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3): x = (0, 1, 2, 3)"
Gen.(tup4 (pure 0) (pure 1) (pure 2) (pure 3))
(fun x -> x = (0, 1, 2, 3))

let test_tup5 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4): x = (0, 1, 2, 3, 4)"
Gen.(tup5 (pure 0) (pure 1) (pure 2) (pure 3) (pure 4))
(fun x -> x = (0, 1, 2, 3, 4))

let test_tup6 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5): x = (0, 1, 2, 3, 4, 5)"
Gen.(tup6 (pure 0) (pure 1) (pure 2) (pure 3) (pure 4) (pure 5))
(fun x -> x = (0, 1, 2, 3, 4, 5))

let test_tup7 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5, 6): x = (0, 1, 2, 3, 4, 5, 6)"
Gen.(tup7
(pure 0) (pure 1) (pure 2) (pure 3) (pure 4)
(pure 5) (pure 6))
(fun x -> x = (0, 1, 2, 3, 4, 5, 6))

let test_tup8 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5, 6, 7): x = (0, 1, 2, 3, 4, 5, 6, 7)"
Gen.(tup8
(pure 0) (pure 1) (pure 2) (pure 3) (pure 4)
(pure 5) (pure 6) (pure 7))
(fun x -> x = (0, 1, 2, 3, 4, 5, 6, 7))

let test_tup9 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5, 6, 7, 8): x = (0, 1, 2, 3, 4, 5, 6, 7, 8)"
Gen.(tup9
(pure 0) (pure 1) (pure 2) (pure 3) (pure 4)
(pure 5) (pure 6) (pure 7) (pure 8))
(fun x -> x = (0, 1, 2, 3, 4, 5, 6, 7, 8))

let tests = [
char_dist_issue_23;
char_test;
Expand All @@ -151,6 +205,14 @@ module Generator = struct
list_repeat_test;
array_repeat_test;
passing_tree_rev;
test_tup2;
test_tup3;
test_tup4;
test_tup5;
test_tup6;
test_tup7;
test_tup8;
test_tup9;
]
end

Expand Down Expand Up @@ -259,6 +321,62 @@ module Shrink = struct
IntTree.gen_tree
(fun tree -> IntTree.contains_only_n tree 42)

let test_tup2 =
Test.make
~print:Print.(tup2 int int)
~name:"forall (a, b) in nat: a < b"
Gen.(tup2 small_int small_int)
(fun (a, b) -> a < b)

let test_tup3 =
Test.make
~print:Print.(tup3 int int int)
~name:"forall (a, b, c) in nat: a < b < c"
Gen.(tup3 small_int small_int small_int)
(fun (a, b, c) -> a < b && b < c)

let test_tup4 =
Test.make
~print:Print.(tup4 int int int int)
~name:"forall (a, b, c, d) in nat: a < b < c < d"
Gen.(tup4 small_int small_int small_int small_int)
(fun (a, b, c, d) -> a < b && b < c && c < d)

let test_tup5 =
Test.make
~print:Print.(tup5 int int int int int)
~name:"forall (a, b, c, d, e) in nat: a < b < c < d < e"
Gen.(tup5 small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e) -> a < b && b < c && c < d && d < e)

let test_tup6 =
Test.make
~print:Print.(tup6 int int int int int int)
~name:"forall (a, b, c, d, e, f) in nat: a < b < c < d < e < f"
Gen.(tup6 small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f) -> a < b && b < c && c < d && d < e && e < f)

let test_tup7 =
Test.make
~print:Print.(tup7 int int int int int int int)
~name:"forall (a, b, c, d, e, f, g) in nat: a < b < c < d < e < f < g"
Gen.(tup7 small_int small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f, g) -> a < b && b < c && c < d && d < e && e < f && f < g)

let test_tup8 =
Test.make
~print:Print.(tup8 int int int int int int int int)
~name:"forall (a, b, c, d, e, f, g, h) in nat: a < b < c < d < e < f < g < h"
Gen.(tup8 small_int small_int small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f, g, h) -> a < b && b < c && c < d && d < e && e < f && f < g && g < h)

let test_tup9 =
Test.make
~print:Print.(tup9 int int int int int int int int int)
~name:"forall (a, b, c, d, e, f, g, h, i) in nat: a < b < c < d < e < f < g < h < i"
Gen.(tup9 small_int small_int small_int small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f, g, h, i) -> a < b && b < c && c < d && d < e && e < f && f < g && g < h && h < i)

let tests = [
(*test_fac_issue59;*)
big_bound_issue59;
Expand All @@ -278,6 +396,14 @@ module Shrink = struct
list_equal_dupl;
list_unique_elems;
tree_contains_only_42;
test_tup2;
test_tup3;
test_tup4;
test_tup5;
test_tup6;
test_tup7;
test_tup8;
test_tup9;
]
end

Expand Down
118 changes: 118 additions & 0 deletions test/core/QCheck_expect_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,60 @@ module Generator = struct
&& Array.for_all (fun k -> 0 < k) arr
&& Array.fold_left (+) 0 arr = n)

let test_tup2 =
Test.make ~count:10
~name:"forall x in (0, 1): x = (0, 1)"
(tup2 (always 0) (always 1))
(fun x -> x = (0, 1))

let test_tup3 =
Test.make ~count:10
~name:"forall x in (0, 1, 2): x = (0, 1, 2)"
(tup3 (always 0) (always 1) (always 2))
(fun x -> x = (0, 1, 2))

let test_tup4 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3): x = (0, 1, 2, 3)"
(tup4 (always 0) (always 1) (always 2) (always 3))
(fun x -> x = (0, 1, 2, 3))

let test_tup5 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4): x = (0, 1, 2, 3, 4)"
(tup5 (always 0) (always 1) (always 2) (always 3) (always 4))
(fun x -> x = (0, 1, 2, 3, 4))

let test_tup6 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5): x = (0, 1, 2, 3, 4, 5)"
(tup6 (always 0) (always 1) (always 2) (always 3) (always 4) (always 5))
(fun x -> x = (0, 1, 2, 3, 4, 5))

let test_tup7 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5, 6): x = (0, 1, 2, 3, 4, 5, 6)"
(tup7
(always 0) (always 1) (always 2) (always 3) (always 4)
(always 5) (always 6))
(fun x -> x = (0, 1, 2, 3, 4, 5, 6))

let test_tup8 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5, 6, 7): x = (0, 1, 2, 3, 4, 5, 6, 7)"
(tup8
(always 0) (always 1) (always 2) (always 3) (always 4)
(always 5) (always 6) (always 7))
(fun x -> x = (0, 1, 2, 3, 4, 5, 6, 7))

let test_tup9 =
Test.make ~count:10
~name:"forall x in (0, 1, 2, 3, 4, 5, 6, 7, 8): x = (0, 1, 2, 3, 4, 5, 6, 7, 8)"
(tup9
(always 0) (always 1) (always 2) (always 3) (always 4)
(always 5) (always 6) (always 7) (always 8))
(fun x -> x = (0, 1, 2, 3, 4, 5, 6, 7, 8))

let tests = [
char_dist_issue_23;
char_test;
Expand All @@ -238,6 +292,14 @@ module Generator = struct
nat_split_n_way;
nat_split_smaller;
pos_split;
test_tup2;
test_tup3;
test_tup4;
test_tup5;
test_tup6;
test_tup7;
test_tup8;
test_tup9;
]
end

Expand Down Expand Up @@ -339,6 +401,54 @@ module Shrink = struct
(fun xs -> let ys = List.sort_uniq Int.compare xs in
print_list xs; List.length xs = List.length ys)

let test_tup2 =
Test.make
~name:"forall (a, b) in nat: a < b"
(tup2 small_int small_int)
(fun (a, b) -> a < b)

let test_tup3 =
Test.make
~name:"forall (a, b, c) in nat: a < b < c"
(tup3 small_int small_int small_int)
(fun (a, b, c) -> a < b && b < c)

let test_tup4 =
Test.make
~name:"forall (a, b, c, d) in nat: a < b < c < d"
(tup4 small_int small_int small_int small_int)
(fun (a, b, c, d) -> a < b && b < c && c < d)

let test_tup5 =
Test.make
~name:"forall (a, b, c, d, e) in nat: a < b < c < d < e"
(tup5 small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e) -> a < b && b < c && c < d && d < e)

let test_tup6 =
Test.make
~name:"forall (a, b, c, d, e, f) in nat: a < b < c < d < e < f"
(tup6 small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f) -> a < b && b < c && c < d && d < e && e < f)

let test_tup7 =
Test.make
~name:"forall (a, b, c, d, e, f, g) in nat: a < b < c < d < e < f < g"
(tup7 small_int small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f, g) -> a < b && b < c && c < d && d < e && e < f && f < g)

let test_tup8 =
Test.make
~name:"forall (a, b, c, d, e, f, g, h) in nat: a < b < c < d < e < f < g < h"
(tup8 small_int small_int small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f, g, h) -> a < b && b < c && c < d && d < e && e < f && f < g && g < h)

let test_tup9 =
Test.make
~name:"forall (a, b, c, d, e, f, g, h, i) in nat: a < b < c < d < e < f < g < h < i"
(tup9 small_int small_int small_int small_int small_int small_int small_int small_int small_int)
(fun (a, b, c, d, e, f, g, h, i) -> a < b && b < c && c < d && d < e && e < f && f < g && g < h && h < i)

let tests = [
(*test_fac_issue59;*)
big_bound_issue59;
Expand All @@ -357,6 +467,14 @@ module Shrink = struct
list_shorter_4332;
list_equal_dupl;
list_unique_elems;
test_tup2;
test_tup3;
test_tup4;
test_tup5;
test_tup6;
test_tup7;
test_tup8;
test_tup9;
]
end

Expand Down
50 changes: 49 additions & 1 deletion test/core/qcheck2_output.txt.expected
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,54 @@ Leaf 0

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

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 (3 shrink steps):

(0, 0, 0)

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

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 (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 (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 (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 (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 (9 shrink steps):

(0, 0, 0, 0, 0, 0, 0, 0, 0)

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

Test fail_pred_map_commute failed (16 shrink steps):

([2], {_ -> 0}, {1 -> false; 2 -> true; _ -> false})
Expand Down Expand Up @@ -934,7 +982,7 @@ stats dist:
4150517416584649600.. 4611686018427387903: ################# 189
================================================================================
1 warning(s)
failure (27 tests failed, 1 tests errored, ran 67 tests)
failure (35 tests failed, 1 tests errored, ran 83 tests)
random seed: 153870556

+++ Stats for int_dist_empty_bucket ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
Loading

0 comments on commit c830129

Please sign in to comment.