feat(ui): prefer arrow functions
[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
66a7748d 5import { average, median, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils.js'
4884b8d3 6
6c43b441
JB
7await describe('StatisticUtils test suite', async () => {
8 await it('Verify average()', () => {
66a7748d
JB
9 expect(average([])).toBe(0)
10 expect(average([0.08])).toBe(0.08)
11 expect(average([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.1642857142857146)
12 expect(average([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.8533333333333335)
13 })
c7ba22b7 14
6c43b441 15 await it('Verify median()', () => {
66a7748d
JB
16 expect(median([])).toBe(0)
17 expect(median([0.08])).toBe(0.08)
18 expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.05)
19 expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.535)
20 })
4884b8d3 21
6c43b441 22 await it('Verify nthPercentile()', () => {
66a7748d
JB
23 expect(nthPercentile([], 25)).toBe(0)
24 expect(nthPercentile([0.08], 50)).toBe(0.08)
25 const array0 = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]
26 expect(nthPercentile(array0, 0)).toBe(0.25)
27 expect(nthPercentile(array0, 50)).toBe(3.05)
28 expect(nthPercentile(array0, 80)).toBe(4.974)
29 expect(nthPercentile(array0, 85)).toBe(5.131)
30 expect(nthPercentile(array0, 90)).toBe(5.434)
31 expect(nthPercentile(array0, 95)).toBe(5.736999999999999)
32 expect(nthPercentile(array0, 100)).toBe(6.04)
33 })
4884b8d3 34
6c43b441 35 await it('Verify stdDeviation()', () => {
66a7748d
JB
36 expect(stdDeviation([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(2.1879050645374383)
37 })
38})