test: add updateMeasurementStatistics() behavior test
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 18 Jul 2023 20:58:37 +0000 (22:58 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 18 Jul 2023 20:58:37 +0000 (22:58 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/utils.test.js

index f220927edc9cc180ba9740d4e191508194dd40b6..6518ca924f188fc69d7de8d58adc9219c2ce311e 100644 (file)
@@ -5,7 +5,8 @@ const {
   isKillBehavior,
   isPlainObject,
   median,
-  round
+  round,
+  updateMeasurementStatistics
 } = require('../lib/utils')
 const { KillBehaviors } = require('../lib/worker/worker-options')
 
@@ -125,4 +126,42 @@ describe('Utils test suite', () => {
     expect(isAsyncFunction(async function () {})).toBe(true)
     expect(isAsyncFunction(async function named () {})).toBe(true)
   })
+
+  it('Verify updateMeasurementStatistics() behavior', () => {
+    const measurementStatistics = {}
+    updateMeasurementStatistics(
+      measurementStatistics,
+      { aggregate: true, average: false, median: false },
+      0.01,
+      1
+    )
+    expect(measurementStatistics).toEqual({
+      aggregate: 0.01,
+      maximum: 0.01,
+      minimum: 0.01
+    })
+    updateMeasurementStatistics(
+      measurementStatistics,
+      { aggregate: true, average: false, median: false },
+      0.02,
+      2
+    )
+    expect(measurementStatistics).toEqual({
+      aggregate: 0.03,
+      maximum: 0.02,
+      minimum: 0.01
+    })
+    updateMeasurementStatistics(
+      measurementStatistics,
+      { aggregate: true, average: true, median: false },
+      0.001,
+      3
+    )
+    expect(measurementStatistics).toEqual({
+      aggregate: 0.031,
+      maximum: 0.02,
+      minimum: 0.001,
+      average: 0.010333333333333333
+    })
+  })
 })