build(deps): apply updates
[e-mobility-charging-stations-simulator.git] / test / utils / Utils.test.ts
index 892f25a56462aea681eeda17aa737cf1150494c0..5b9f81515c9686bcbea50afe1b781b3d6c108036 100644 (file)
@@ -11,6 +11,7 @@ import {
   getRandomFloat,
   getRandomInteger,
   hasOwnProp,
+  isArraySorted,
   isEmptyArray,
   isEmptyObject,
   isEmptyString,
@@ -20,6 +21,7 @@ import {
   isNullOrUndefined,
   isObject,
   isUndefined,
+  isValidDate,
   roundTo,
   secureRandom,
   sleep,
@@ -46,6 +48,24 @@ describe('Utils test suite', () => {
     expect(end - start).toBeGreaterThanOrEqual(1000);
   });
 
+  it('Verify isValidDate()', () => {
+    expect(isValidDate(undefined)).toBe(false);
+    expect(isValidDate(null)).toBe(false);
+    expect(isValidDate('')).toBe(false);
+    expect(isValidDate({})).toBe(false);
+    expect(isValidDate([])).toBe(false);
+    expect(isValidDate(new Map())).toBe(false);
+    expect(isValidDate(new Set())).toBe(false);
+    expect(isValidDate(new WeakMap())).toBe(false);
+    expect(isValidDate(new WeakSet())).toBe(false);
+    expect(isValidDate(-1)).toBe(true);
+    expect(isValidDate(0)).toBe(true);
+    expect(isValidDate(1)).toBe(true);
+    expect(isValidDate(-0.5)).toBe(true);
+    expect(isValidDate(0.5)).toBe(true);
+    expect(isValidDate(new Date())).toBe(true);
+  });
+
   it('Verify convertToDate()', () => {
     expect(convertToDate(undefined)).toBe(undefined);
     expect(convertToDate(null)).toBe(null);
@@ -137,15 +157,15 @@ describe('Utils test suite', () => {
     expect(randomInteger).toBeGreaterThanOrEqual(-Constants.MAX_RANDOM_INTEGER);
     expect(randomInteger).toBeLessThanOrEqual(0);
     expect(() => getRandomInteger(0, 1)).toThrowError(
-      'The value of "max" is out of range. It must be greater than the value of "min" (1). Received 1'
+      'The value of "max" is out of range. It must be greater than the value of "min" (1). Received 1',
     );
     expect(() => getRandomInteger(-1)).toThrowError(
-      'The value of "max" is out of range. It must be greater than the value of "min" (0). Received 0'
+      'The value of "max" is out of range. It must be greater than the value of "min" (0). Received 0',
     );
     expect(() => getRandomInteger(Constants.MAX_RANDOM_INTEGER + 1)).toThrowError(
       `The value of "max" is out of range. It must be <= ${
         Constants.MAX_RANDOM_INTEGER + 1
-      }. Received 281_474_976_710_656`
+      }. Received 281_474_976_710_656`,
     );
     randomInteger = getRandomInteger(2, 1);
     expect(randomInteger).toBeGreaterThanOrEqual(1);
@@ -180,7 +200,7 @@ describe('Utils test suite', () => {
     expect(randomFloat).not.toEqual(getRandomFloat());
     expect(() => getRandomFloat(0, 1)).toThrowError(new RangeError('Invalid interval'));
     expect(() => getRandomFloat(Number.MAX_VALUE, -Number.MAX_VALUE)).toThrowError(
-      new RangeError('Invalid interval')
+      new RangeError('Invalid interval'),
     );
     randomFloat = getRandomFloat(0, -Number.MAX_VALUE);
     expect(randomFloat).toBeGreaterThanOrEqual(-Number.MAX_VALUE);
@@ -360,11 +380,24 @@ describe('Utils test suite', () => {
   it('Verify isEmptyObject()', () => {
     expect(isEmptyObject({})).toBe(true);
     expect(isEmptyObject({ 1: 1, 2: 2 })).toBe(false);
-    expect(isEmptyObject(undefined)).toBe(false);
-    expect(isEmptyObject(null)).toBe(false);
     expect(isEmptyObject(new Map())).toBe(false);
     expect(isEmptyObject(new Set())).toBe(false);
     expect(isEmptyObject(new WeakMap())).toBe(false);
     expect(isEmptyObject(new WeakSet())).toBe(false);
   });
+
+  it('Verify isArraySorted()', () => {
+    expect(
+      isArraySorted([], (a, b) => {
+        return a - b;
+      }),
+    ).toBe(true);
+    expect(
+      isArraySorted([1], (a, b) => {
+        return a - b;
+      }),
+    ).toBe(true);
+    expect(isArraySorted<number>([1, 2, 3, 4, 5], (a, b) => a - b)).toBe(true);
+    expect(isArraySorted<number>([1, 2, 3, 5, 4], (a, b) => a - b)).toBe(false);
+  });
 });