feat: warn if charging profile schedule periods are not sorted
[e-mobility-charging-stations-simulator.git] / test / utils / Utils.test.ts
index 4677fcdaa337c9a736d5b0e9df326eaf09b8cf11..233ee75d8baa886fcdd5e8920d7c58d544095a75 100644 (file)
@@ -11,6 +11,7 @@ import {
   getRandomFloat,
   getRandomInteger,
   hasOwnProp,
+  isArraySorted,
   isEmptyArray,
   isEmptyObject,
   isEmptyString,
@@ -365,4 +366,19 @@ describe('Utils test suite', () => {
     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);
+  });
 });