From: Jérôme Benoit Date: Mon, 7 Nov 2022 14:50:20 +0000 (+0100) Subject: Small improvements to Utils UTs X-Git-Tag: v1.1.87~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0b3122086d4ad8e3cc0c97774a1234681785ffe3;p=e-mobility-charging-stations-simulator.git Small improvements to Utils UTs Signed-off-by: Jérôme Benoit --- diff --git a/test/utils/UtilsTest.ts b/test/utils/UtilsTest.ts index 7eb6aeb2..36d06ddb 100644 --- a/test/utils/UtilsTest.ts +++ b/test/utils/UtilsTest.ts @@ -53,10 +53,12 @@ describe('Utils test suite', () => { expect(Utils.convertToInt(0)).toBe(0); const randomInteger = Utils.getRandomInteger(); expect(Utils.convertToInt(randomInteger)).toEqual(randomInteger); + expect(Utils.convertToInt('-1')).toBe(-1); expect(Utils.convertToInt('1')).toBe(1); expect(Utils.convertToInt('1.1')).toBe(1); expect(Utils.convertToInt('1.9')).toBe(1); expect(Utils.convertToInt('1.999')).toBe(1); + expect(Utils.convertToInt(-1)).toBe(-1); expect(Utils.convertToInt(1)).toBe(1); expect(Utils.convertToInt(1.1)).toBe(1); expect(Utils.convertToInt(1.9)).toBe(1); @@ -69,10 +71,12 @@ describe('Utils test suite', () => { expect(Utils.convertToFloat(0)).toBe(0); const randomFloat = Utils.getRandomFloat(); expect(Utils.convertToFloat(randomFloat)).toEqual(randomFloat); + expect(Utils.convertToFloat('-1')).toBe(-1); expect(Utils.convertToFloat('1')).toBe(1); expect(Utils.convertToFloat('1.1')).toBe(1.1); expect(Utils.convertToFloat('1.9')).toBe(1.9); expect(Utils.convertToFloat('1.999')).toBe(1.999); + expect(Utils.convertToFloat(-1)).toBe(-1); expect(Utils.convertToFloat(1)).toBe(1); expect(Utils.convertToFloat(1.1)).toBe(1.1); expect(Utils.convertToFloat(1.9)).toBe(1.9); @@ -92,6 +96,8 @@ describe('Utils test suite', () => { expect(Utils.convertToBoolean(0)).toBe(false); expect(Utils.convertToBoolean(true)).toBe(true); expect(Utils.convertToBoolean(false)).toBe(false); + expect(Utils.convertToBoolean('')).toBe(false); + expect(Utils.convertToBoolean('NoNBoolean')).toBe(false); }); it('Verify secureRandom()', () => { @@ -112,6 +118,11 @@ describe('Utils test suite', () => { randomInteger = Utils.getRandomInteger(2, 1); expect(randomInteger).toBeGreaterThanOrEqual(1); expect(randomInteger).toBeLessThanOrEqual(2); + const max = 2.2, + min = 1.1; + randomInteger = Utils.getRandomInteger(max, min); + expect(randomInteger).toBeGreaterThanOrEqual(Math.ceil(min)); + expect(randomInteger).toBeLessThanOrEqual(Math.floor(max)); }); it('Verify getRandomFloat()', () => {