source: trip-planner-front/node_modules/hdr-histogram-percentiles-obj/test/hdr-js.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1'use strict'
2
3const test = require('tap').test
4const hdr = require('hdr-histogram-js')
5const histPercentileObj = require('../')
6
7test('should return a valid hist as object', (t) => {
8 t.plan(24)
9 const histogram = hdr.build({
10 lowestDiscernibleValue: 1,
11 highestTrackableValue: 100
12 })
13 let total = 0
14 for (let i = 0; i < 10000; i++) {
15 const num = Math.floor(Math.random() * 100)
16 histogram.recordValue(num)
17 total += num
18 }
19
20 // any of the numbers below _could_ be 0, so we do a type test instead of t.ok
21 const result = histPercentileObj.histAsObj(histogram, total)
22 t.ok(result)
23 t.type(result.average, 'number')
24 t.type(result.mean, 'number')
25 t.type(result.stddev, 'number')
26 t.type(result.min, 'number')
27 t.type(result.max, 'number')
28 t.type(result.total, 'number')
29
30 const withPercentiles = histPercentileObj.addPercentiles(histogram, result)
31 t.ok(withPercentiles)
32 t.type(withPercentiles.average, 'number')
33 t.type(withPercentiles.p0_001, 'number')
34 t.type(withPercentiles.p0_01, 'number')
35 t.type(withPercentiles.p0_1, 'number')
36 t.type(withPercentiles.p1, 'number')
37 t.type(withPercentiles.p2_5, 'number')
38 t.type(withPercentiles.p10, 'number')
39 t.type(withPercentiles.p25, 'number')
40 t.type(withPercentiles.p50, 'number')
41 t.type(withPercentiles.p75, 'number')
42 t.type(withPercentiles.p90, 'number')
43 t.type(withPercentiles.p97_5, 'number')
44 t.type(withPercentiles.p99, 'number')
45 t.type(withPercentiles.p99_9, 'number')
46 t.type(withPercentiles.p99_99, 'number')
47 t.type(withPercentiles.p99_999, 'number')
48})
49
50test('should return expected numbers', (t) => {
51 t.plan(18)
52 const histogram = hdr.build({
53 lowestDiscernibleValue: 1,
54 highestTrackableValue: 10
55 })
56
57 histogram.recordValue(4)
58 histogram.recordValue(5)
59 histogram.recordValue(6)
60
61 // any of the numbers below _could_ be 0, so we do a type test instead of t.ok
62 const result = histPercentileObj.histAsObj(histogram, 15)
63 t.ok(result)
64 t.equal(result.average, 5)
65 t.equal(result.mean, 5)
66 t.equal(result.stddev, 0.82)
67 t.equal(result.min, 4)
68 t.equal(result.max, 6)
69 t.equal(result.total, 15)
70
71 const withPercentiles = histPercentileObj.addPercentiles(histogram, result)
72 t.ok(withPercentiles)
73 t.equal(withPercentiles.average, 5)
74 t.equal(withPercentiles.p2_5, 4)
75 t.equal(withPercentiles.p50, 5)
76 t.equal(withPercentiles.p75, 6)
77 t.equal(withPercentiles.p90, 6)
78 t.equal(withPercentiles.p97_5, 6)
79 t.equal(withPercentiles.p99, 6)
80 t.equal(withPercentiles.p99_9, 6)
81 t.equal(withPercentiles.p99_99, 6)
82 t.equal(withPercentiles.p99_999, 6)
83})
84
85test('should return a valid hist as object from a WASM histogram', (t) => {
86 t.plan(1)
87 hdr.initWebAssemblySync()
88 const histogram = hdr.build({
89 useWebAssembly: true
90 })
91 t.ok(histPercentileObj.histAsObj(histogram))
92})
Note: See TracBrowser for help on using the repository browser.