build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / tests / utils / StatisticUtils.test.ts
1 import { describe, it } from 'node:test'
2
3 import { expect } from 'expect'
4
5 import { max, min, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils.js'
6
7 await describe('StatisticUtils test suite', async () => {
8 await it('Verify min()', () => {
9 expect(min()).toBe(Infinity)
10 expect(min(0, 1)).toBe(0)
11 expect(min(1, 0)).toBe(0)
12 expect(min(0, -1)).toBe(-1)
13 expect(min(-1, 0)).toBe(-1)
14 })
15
16 await it('Verify max()', () => {
17 expect(max()).toBe(-Infinity)
18 expect(max(0, 1)).toBe(1)
19 expect(max(1, 0)).toBe(1)
20 expect(max(0, -1)).toBe(0)
21 expect(max(-1, 0)).toBe(0)
22 })
23
24 await it('Verify nthPercentile()', () => {
25 expect(nthPercentile([], 25)).toBe(0)
26 expect(nthPercentile([0.08], 50)).toBe(0.08)
27 const array0 = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]
28 expect(nthPercentile(array0, 0)).toBe(0.25)
29 expect(nthPercentile(array0, 50)).toBe(3.05)
30 expect(nthPercentile(array0, 80)).toBe(4.974)
31 expect(nthPercentile(array0, 85)).toBe(5.131)
32 expect(nthPercentile(array0, 90)).toBe(5.434)
33 expect(nthPercentile(array0, 95)).toBe(5.736999999999999)
34 expect(nthPercentile(array0, 100)).toBe(6.04)
35 })
36
37 await it('Verify stdDeviation()', () => {
38 expect(stdDeviation([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(2.1879050645374383)
39 })
40 })