1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/util/median.test.ts
Jaanus Sellin 958ccabb54
feat: lifecycle prometheus metrics per project (#7032)
When we pushed metrics per feature, it had too many datapoints and
grafana could not handle it. Now I am taking median for a project.
2024-05-10 15:24:27 +03:00

22 lines
552 B
TypeScript

import { median } from './median';
test('calculateMedian with an odd number of elements', () => {
expect(median([1, 3, 5])).toBe(3);
});
test('calculateMedian with an even number of elements', () => {
expect(median([1, 2, 3, 4])).toBe(2.5);
});
test('calculateMedian with negative numbers', () => {
expect(median([-5, -1, -3, -2, -4])).toBe(-3);
});
test('calculateMedian with one element', () => {
expect(median([42])).toBe(42);
});
test('calculateMedian with an empty array', () => {
expect(median([])).toBe(Number.NaN);
});