From: Jérôme Benoit Date: Wed, 26 Oct 2022 20:16:52 +0000 (+0200) Subject: Improve random number generators unit tests X-Git-Tag: v1.1.87~27 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bd9f680e5ac3b20551b7aafe1d844542cc7a0dab;p=e-mobility-charging-stations-simulator.git Improve random number generators unit tests Signed-off-by: Jérôme Benoit --- 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()', () => {