refactor: use more ramdba helpers
[e-mobility-charging-stations-simulator.git] / tests / utils / StatisticUtils.test.ts
CommitLineData
66a7748d 1import { describe, it } from 'node:test'
6c43b441 2
66a7748d 3import { expect } from 'expect'
4884b8d3 4
c17a8d29 5import { max, min, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils.js'
4884b8d3 6
6c43b441 7await describe('StatisticUtils test suite', async () => {
c17a8d29
JB
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)
66a7748d 14 })
c7ba22b7 15
c17a8d29
JB
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)
66a7748d 22 })
4884b8d3 23
6c43b441 24 await it('Verify nthPercentile()', () => {
66a7748d
JB
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 })
4884b8d3 36
6c43b441 37 await it('Verify stdDeviation()', () => {
66a7748d
JB
38 expect(stdDeviation([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(2.1879050645374383)
39 })
40})