bf0c72afadadc78819bd5d938a30f962496f1fee
[poolifier.git] / tests / pools / utils.test.mjs
1 import { expect } from 'expect'
2 import {
3 CircularArray,
4 DEFAULT_CIRCULAR_ARRAY_SIZE
5 } from '../../lib/circular-array.js'
6 import { updateMeasurementStatistics } from '../../lib/pools/utils.js'
7
8 describe('Pool utils test suite', () => {
9 it('Verify updateMeasurementStatistics() behavior', () => {
10 const measurementStatistics = {
11 history: new CircularArray()
12 }
13 updateMeasurementStatistics(
14 measurementStatistics,
15 { aggregate: true, average: false, median: false },
16 0.01
17 )
18 expect(measurementStatistics).toStrictEqual({
19 aggregate: 0.01,
20 maximum: 0.01,
21 minimum: 0.01,
22 history: new CircularArray()
23 })
24 updateMeasurementStatistics(
25 measurementStatistics,
26 { aggregate: true, average: false, median: false },
27 0.02
28 )
29 expect(measurementStatistics).toStrictEqual({
30 aggregate: 0.03,
31 maximum: 0.02,
32 minimum: 0.01,
33 history: new CircularArray()
34 })
35 updateMeasurementStatistics(
36 measurementStatistics,
37 { aggregate: true, average: true, median: false },
38 0.001
39 )
40 expect(measurementStatistics).toStrictEqual({
41 aggregate: 0.031,
42 maximum: 0.02,
43 minimum: 0.001,
44 average: 0.001,
45 history: new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, 0.001)
46 })
47 updateMeasurementStatistics(
48 measurementStatistics,
49 { aggregate: true, average: true, median: false },
50 0.003
51 )
52 expect(measurementStatistics).toStrictEqual({
53 aggregate: 0.034,
54 maximum: 0.02,
55 minimum: 0.001,
56 average: 0.002,
57 history: new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, 0.001, 0.003)
58 })
59 updateMeasurementStatistics(
60 measurementStatistics,
61 { aggregate: true, average: false, median: true },
62 0.006
63 )
64 expect(measurementStatistics).toStrictEqual({
65 aggregate: 0.04,
66 maximum: 0.02,
67 minimum: 0.001,
68 median: 0.003,
69 history: new CircularArray(
70 DEFAULT_CIRCULAR_ARRAY_SIZE,
71 0.001,
72 0.003,
73 0.006
74 )
75 })
76 updateMeasurementStatistics(
77 measurementStatistics,
78 { aggregate: true, average: true, median: false },
79 0.01
80 )
81 expect(measurementStatistics).toStrictEqual({
82 aggregate: 0.05,
83 maximum: 0.02,
84 minimum: 0.001,
85 average: 0.005,
86 history: new CircularArray(
87 DEFAULT_CIRCULAR_ARRAY_SIZE,
88 0.001,
89 0.003,
90 0.006,
91 0.01
92 )
93 })
94 })
95 })