From bd9f680e5ac3b20551b7aafe1d844542cc7a0dab Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 26 Oct 2022 22:16:52 +0200 Subject: [PATCH] Improve random number generators unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/utils/UtilsTest.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/utils/UtilsTest.ts b/test/utils/UtilsTest.ts index eb1681ce..cb8b5d08 100644 --- a/test/utils/UtilsTest.ts +++ b/test/utils/UtilsTest.ts @@ -30,23 +30,29 @@ describe('Utils test suite', () => { }); it('Verify getRandomInteger()', () => { - const randomInteger = Utils.getRandomInteger(); + let randomInteger = Utils.getRandomInteger(); expect(Number.isSafeInteger(randomInteger)).toBe(true); expect(randomInteger).toBeGreaterThanOrEqual(0); expect(randomInteger).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER); expect(() => Utils.getRandomInteger(0, 1)).toThrowError(new RangeError('Invalid interval')); expect(() => Utils.getRandomInteger(-1)).toThrowError(new RangeError('Invalid interval')); expect(() => Utils.getRandomInteger(0, -1)).toThrowError(new RangeError('Invalid interval')); + randomInteger = Utils.getRandomInteger(2, 1); + expect(randomInteger).toBeGreaterThanOrEqual(1); + expect(randomInteger).toBeLessThanOrEqual(2); }); it('Verify getRandomFloat()', () => { - const randomFloat = Utils.getRandomFloat(); + let randomFloat = Utils.getRandomFloat(); expect(typeof randomFloat === 'number').toBe(true); expect(randomFloat).toBeGreaterThanOrEqual(0); expect(randomFloat).toBeLessThanOrEqual(Number.MAX_VALUE); expect(() => Utils.getRandomFloat(0, 1)).toThrowError(new RangeError('Invalid interval')); expect(() => Utils.getRandomFloat(-1)).toThrowError(new RangeError('Invalid interval')); expect(() => Utils.getRandomFloat(0, -1)).toThrowError(new RangeError('Invalid interval')); + randomFloat = Utils.getRandomFloat(Number.MAX_VALUE, 0, true); + expect(randomFloat).toBeGreaterThanOrEqual(-Number.MAX_VALUE); + expect(randomFloat).toBeLessThanOrEqual(Number.MAX_VALUE); }); it('Verify isIterable()', () => { -- 2.34.1