getRandomFloat,
getRandomInteger,
hasOwnProp,
+ isArraySorted,
isEmptyArray,
isEmptyObject,
isEmptyString,
isNullOrUndefined,
isObject,
isUndefined,
+ isValidDate,
roundTo,
secureRandom,
sleep,
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);
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);
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);
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);
+ });
});