From f573c5484956f855ddc8241143d8c04630275bf2 Mon Sep 17 00:00:00 2001 From: Jerry James Date: Wed, 2 Dec 2020 15:07:43 -0700 Subject: [PATCH] Add upstream patches to fix numeric range issues. --- ...ixes-distribution-and-min_int-issues.patch | 36 +++++++++++++++++++ 0002-rm-needless-.Gen.patch | 25 +++++++++++++ ocaml-qcheck.spec | 11 ++++-- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 0001-Fixes-distribution-and-min_int-issues.patch create mode 100644 0002-rm-needless-.Gen.patch diff --git a/0001-Fixes-distribution-and-min_int-issues.patch b/0001-Fixes-distribution-and-min_int-issues.patch new file mode 100644 index 0000000..e1a57d0 --- /dev/null +++ b/0001-Fixes-distribution-and-min_int-issues.patch @@ -0,0 +1,36 @@ +From 99a5f108681271f50f31fe3988db0f94b5779c2b Mon Sep 17 00:00:00 2001 +From: Jan Midtgaard +Date: Thu, 12 Nov 2020 12:43:23 +0100 +Subject: [PATCH 1/2] Fixes distribution and min_int issues + +--- + 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 5a3a3e6..67d6e3a 100644 +--- a/src/core/QCheck.ml ++++ b/src/core/QCheck.ml +@@ -162,7 +162,7 @@ module Gen = struct + else fun st -> let r = pint st in r mod (n + 1) + let int_range a b = + if b < a then invalid_arg "Gen.int_range"; +- if a >= 0 || b <= 0 then ( ++ if a >= 0 || b < 0 then ( + (* range smaller than max_int *) + assert (b-a >= 0); + fun st -> a + (int_bound (b-a) st) +@@ -171,8 +171,8 @@ module Gen = struct + choose the itv wrt to their size ratio *) + fun st -> + let f_a = float_of_int a in +- let ratio = (-.f_a) /. (float_of_int b -. f_a) in +- if Random.float 1. < ratio then - (int_bound (abs a) st) ++ let ratio = (-.f_a) /. (1. +. float_of_int b -. f_a) in ++ if Random.State.float st 1. <= ratio then - (Gen.int_bound (- (a+1)) st) - 1 + else int_bound b st + ) + +-- +2.28.0 + diff --git a/0002-rm-needless-.Gen.patch b/0002-rm-needless-.Gen.patch new file mode 100644 index 0000000..bca6435 --- /dev/null +++ b/0002-rm-needless-.Gen.patch @@ -0,0 +1,25 @@ +From 7616e43b4d011ef90e7e20f47e9837c660d8428f Mon Sep 17 00:00:00 2001 +From: Jan Midtgaard +Date: Thu, 12 Nov 2020 12:47:28 +0100 +Subject: [PATCH 2/2] rm needless .Gen + +--- + src/core/QCheck.ml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/core/QCheck.ml b/src/core/QCheck.ml +index 67d6e3a..f05f73c 100644 +--- a/src/core/QCheck.ml ++++ b/src/core/QCheck.ml +@@ -172,7 +172,7 @@ module Gen = struct + fun st -> + let f_a = float_of_int a in + let ratio = (-.f_a) /. (1. +. float_of_int b -. f_a) in +- if Random.State.float st 1. <= ratio then - (Gen.int_bound (- (a+1)) st) - 1 ++ if Random.State.float st 1. <= ratio then - (int_bound (- (a+1)) st) - 1 + else int_bound b st + ) + +-- +2.28.0 + diff --git a/ocaml-qcheck.spec b/ocaml-qcheck.spec index 15b52e7..2484d57 100644 --- a/ocaml-qcheck.spec +++ b/ocaml-qcheck.spec @@ -1,11 +1,15 @@ Name: ocaml-qcheck Version: 0.16 -Release: 1%{?dist}.1 +Release: 2%{?dist} Summary: QuickCheck inspired property-based testing for OCaml License: BSD URL: https://github.com/c-cube/qcheck Source0: https://github.com/c-cube/qcheck/archive/%{version}/%{name}-%{version}.tar.gz +# Upstream patch to fix https://github.com/c-cube/qcheck/issues/100 +Patch0: 0001-Fixes-distribution-and-min_int-issues.patch +# Small fix to the previous patch +Patch1: 0002-rm-needless-.Gen.patch BuildRequires: ocaml >= 4.03.0 BuildRequires: ocaml-dune @@ -40,7 +44,7 @@ Documentation for %{name}. %prep -%autosetup -n qcheck-%{version} +%autosetup -n qcheck-%{version} -p1 %build @@ -104,6 +108,9 @@ dune runtest --no-buffer --profile release %changelog +* Wed Dec 2 2020 Jerry James - 0.16-2 +- Add upstream patches to fix numeric range issues + * Thu Nov 12 2020 Jerry James - 0.16-1.1 - Rebuild to fix broken ocaml-fmt dependency