From c830129c74f3798353bc77788e0dac3cf4f3d0a5 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Fri, 3 Dec 2021 18:20:14 +0100 Subject: [PATCH] Tests for tup2..9 generators and shrinkers --- test/core/QCheck2_expect_test.ml | 126 ++++++++++++++++++++++++++ test/core/QCheck_expect_test.ml | 118 ++++++++++++++++++++++++ test/core/qcheck2_output.txt.expected | 50 +++++++++- test/core/qcheck_output.txt.expected | 50 +++++++++- 4 files changed, 342 insertions(+), 2 deletions(-) diff --git a/test/core/QCheck2_expect_test.ml b/test/core/QCheck2_expect_test.ml index 48ec2fd6..fa710abf 100644 --- a/test/core/QCheck2_expect_test.ml +++ b/test/core/QCheck2_expect_test.ml @@ -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; @@ -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 @@ -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; @@ -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 diff --git a/test/core/QCheck_expect_test.ml b/test/core/QCheck_expect_test.ml index cb6f34ad..28fc0a25 100644 --- a/test/core/QCheck_expect_test.ml +++ b/test/core/QCheck_expect_test.ml @@ -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; @@ -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 @@ -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; @@ -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 diff --git a/test/core/qcheck2_output.txt.expected b/test/core/qcheck2_output.txt.expected index 7c04fa8b..208dfb3d 100644 --- a/test/core/qcheck2_output.txt.expected +++ b/test/core/qcheck2_output.txt.expected @@ -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}) @@ -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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/test/core/qcheck_output.txt.expected b/test/core/qcheck_output.txt.expected index 4d55d633..6b455dda 100644 --- a/test/core/qcheck_output.txt.expected +++ b/test/core/qcheck_output.txt.expected @@ -277,6 +277,54 @@ Test lists have unique elems failed (7 shrink steps): --- Failure -------------------------------------------------------------------- +Test forall (a, b) in nat: a < b failed (13 shrink steps): + +(0, 0) + +--- Failure -------------------------------------------------------------------- + +Test forall (a, b, c) in nat: a < b < c failed (15 shrink steps): + +(0, 0, 0) + +--- Failure -------------------------------------------------------------------- + +Test forall (a, b, c, d) in nat: a < b < c < d failed (23 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): + +(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): + +(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): + +(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): + +(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): + +(0, 0, 0, 0, 0, 0, 0, 0, 0) + +--- Failure -------------------------------------------------------------------- + Test fail_pred_map_commute failed (127 shrink steps): ([3], {_ -> 0}, {3 -> false; _ -> true}) @@ -889,7 +937,7 @@ stats dist: 4150517416584649600.. 4611686018427387903: ################# 189 ================================================================================ 1 warning(s) -failure (26 tests failed, 1 tests errored, ran 73 tests) +failure (34 tests failed, 1 tests errored, ran 89 tests) random seed: 153870556 +++ Stats for int_dist_empty_bucket ++++++++++++++++++++++++++++++++++++++++++++++++++++++++