From: Jérôme Benoit Date: Mon, 24 Oct 2022 13:52:14 +0000 (+0200) Subject: Fix benchmarks random integer generator input check X-Git-Tag: v2.3.8~112 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=548140e67db5a4d10e7712fc0830c196a3f81968;p=poolifier.git Fix benchmarks random integer generator input check Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 0a964d7b..c04162e1 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -31,14 +31,11 @@ function jsonIntegerSerialization (n) { } function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { - if (max < 0) { + if (max < min || max < 0 || min < 0) { throw new RangeError('Invalid interval') } max = Math.floor(max) if (min != null && min !== 0) { - if (max < min || min < 0) { - throw new RangeError('Invalid interval') - } min = Math.ceil(min) return Math.floor(Math.random() * (max - min + 1)) + min } diff --git a/tests/test-utils.js b/tests/test-utils.js index f4cb38b2..116b1942 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -37,14 +37,11 @@ class TestUtils { } static generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { - if (max < 0) { + if (max < min || max < 0 || min < 0) { throw new RangeError('Invalid interval') } max = Math.floor(max) if (min != null && min !== 0) { - if (max < min || min < 0) { - throw new RangeError('Invalid interval') - } min = Math.ceil(min) return Math.floor(Math.random() * (max - min + 1)) + min }