chore: switch coding style to JS standard
[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 { average, median, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils.js'
6
7 await describe('StatisticUtils test suite', async () => {
8 await it('Verify average()', () => {
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 })
14
15 await it('Verify median()', () => {
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 })
21
22 await it('Verify nthPercentile()', () => {
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 })
34
35 await it('Verify stdDeviation()', () => {
36 expect(stdDeviation([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(2.1879050645374383)
37 })
38 })