From 548140e67db5a4d10e7712fc0830c196a3f81968 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Oct 2022 15:52:14 +0200 Subject: [PATCH] Fix benchmarks random integer generator input check MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmarks/benchmarks-utils.js | 5 +---- tests/test-utils.js | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) 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 } -- 2.34.1