isUndefined,
logPrefix,
logger,
+ min,
once,
roundTo,
secureRandom,
const connectorMaximumPower = this.getMaximumPower() / this.powerDivider;
const connectorChargingProfilesPowerLimit =
getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId);
- return Math.min(
+ return min(
isNaN(connectorMaximumPower) ? Infinity : connectorMaximumPower,
isNaN(connectorAmperageLimitationPowerLimit!)
? Infinity
isNotEmptyString,
logPrefix,
logger,
+ min,
} from '../../utils';
export class OCPPServiceUtils {
const parsedInt = parseInt(value);
const numberValue = isNaN(parsedInt) ? Infinity : parsedInt;
return options?.limitationEnabled
- ? Math.min(numberValue * options.unitMultiplier!, limit)
+ ? min(numberValue * options.unitMultiplier!, limit)
: numberValue * options.unitMultiplier!;
}
generateUUID,
logPrefix,
logger,
+ max,
median,
+ min,
nthPercentile,
stdDeviation,
} from '../utils';
this.statistics.statisticsData.get(entryName)!.timeMeasurementCount =
(this.statistics.statisticsData.get(entryName)?.timeMeasurementCount ?? 0) + 1;
this.statistics.statisticsData.get(entryName)!.currentTimeMeasurement = entry.duration;
- this.statistics.statisticsData.get(entryName)!.minTimeMeasurement = Math.min(
+ this.statistics.statisticsData.get(entryName)!.minTimeMeasurement = min(
entry.duration,
this.statistics.statisticsData.get(entryName)?.minTimeMeasurement ?? Infinity,
);
- this.statistics.statisticsData.get(entryName)!.maxTimeMeasurement = Math.max(
+ this.statistics.statisticsData.get(entryName)!.maxTimeMeasurement = max(
entry.duration,
this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement ?? -Infinity,
);
return result;
};
};
+
+export const min = (...args: number[]): number =>
+ args.reduce((minimum, num) => (minimum < num ? minimum : num), Infinity);
+
+export const max = (...args: number[]): number =>
+ args.reduce((maximum, num) => (maximum > num ? maximum : num), -Infinity);
isUndefined,
isValidTime,
logPrefix,
+ max,
+ min,
once,
promiseWithTimeout,
roundTo,
isObject,
isUndefined,
isValidTime,
+ max,
+ min,
once,
roundTo,
secureRandom,
randomInteger = getRandomInteger(2, 1);
expect(randomInteger).toBeGreaterThanOrEqual(1);
expect(randomInteger).toBeLessThanOrEqual(2);
- const max = 2.2,
- min = 1.1;
- randomInteger = getRandomInteger(max, min);
- expect(randomInteger).toBeGreaterThanOrEqual(Math.ceil(min));
- expect(randomInteger).toBeLessThanOrEqual(Math.floor(max));
+ const maximum = 2.2,
+ minimum = 1.1;
+ randomInteger = getRandomInteger(maximum, minimum);
+ expect(randomInteger).toBeLessThanOrEqual(Math.floor(maximum));
+ expect(randomInteger).toBeGreaterThanOrEqual(Math.ceil(minimum));
});
it('Verify roundTo()', () => {
expect(called).toBe(1);
expect(result3).toBe(1);
});
+
+ it('Verify min()', () => {
+ expect(min(0, 1)).toBe(0);
+ expect(min(1, 0)).toBe(0);
+ expect(min(0, -1)).toBe(-1);
+ expect(min(-1, 0)).toBe(-1);
+ });
+
+ it('Verify max()', () => {
+ expect(max(0, 1)).toBe(1);
+ expect(max(1, 0)).toBe(1);
+ expect(max(0, -1)).toBe(0);
+ expect(max(-1, 0)).toBe(0);
+ });
});