source: trip-planner-front/node_modules/hdr-histogram-js/dist/PackedHistogram.spec.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const PackedHistogram_1 = require("./PackedHistogram");
4describe("Packed histogram", () => {
5 it("should compute median value in first bucket", () => {
6 // given
7 const histogram = new PackedHistogram_1.default(1, Number.MAX_SAFE_INTEGER, 3);
8 histogram.recordValue(123456);
9 histogram.recordValue(127);
10 histogram.recordValue(42);
11 // when
12 const medianValue = histogram.getValueAtPercentile(50);
13 // then
14 expect(medianValue).toBe(127);
15 });
16 it("should compute same values when new or reseted", () => {
17 // given
18 const histogram = new PackedHistogram_1.default(1, 2, 3);
19 const histogram2 = new PackedHistogram_1.default(1, 2, 3);
20 histogram.autoResize = true;
21 histogram2.autoResize = true;
22 [1, 49026].forEach((v) => histogram.recordValue(v));
23 // when
24 histogram.reset();
25 [7, 67, 42357, 805017].forEach((v) => {
26 histogram.recordValue(v);
27 histogram2.recordValue(v);
28 });
29 // then
30 expect(histogram.getValueAtPercentile(5)).toBe(histogram2.getValueAtPercentile(5));
31 });
32 it("should compute value outside first bucket with an error less than 1000", () => {
33 // given
34 const histogram = new PackedHistogram_1.default(1, 123456, 2);
35 histogram.recordValue(5234);
36 histogram.recordValue(127);
37 histogram.recordValue(42);
38 // when
39 const percentileValue = histogram.getValueAtPercentile(90);
40 // then
41 expect(Math.abs(percentileValue - 5234)).toBeLessThan(100);
42 });
43 it("should resize underlying packed array when recording an out of bound value", () => {
44 // given
45 const histogram = new PackedHistogram_1.default(1, 2, 3);
46 histogram.autoResize = true;
47 // when
48 histogram.recordValue(123456);
49 // then
50 expect(histogram.totalCount).toBe(1);
51 });
52});
53describe("Histogram clearing support", () => {
54 it("should reset data in order to reuse histogram", () => {
55 // given
56 const histogram = new PackedHistogram_1.default(1, Number.MAX_SAFE_INTEGER, 2);
57 const histogram2 = new PackedHistogram_1.default(1, Number.MAX_SAFE_INTEGER, 2);
58 histogram.startTimeStampMsec = 42;
59 histogram.endTimeStampMsec = 56;
60 histogram.tag = "blabla";
61 histogram.recordValue(10);
62 histogram.recordValue(1000);
63 histogram.recordValue(10000000);
64 // when
65 histogram.reset();
66 // then
67 expect(histogram.totalCount).toBe(0);
68 expect(histogram.startTimeStampMsec).toBe(0);
69 expect(histogram.endTimeStampMsec).toBe(0);
70 //expect(histogram.tag).toBe(NO_TAG);
71 expect(histogram.maxValue).toBe(0);
72 expect(histogram.minNonZeroValue).toBe(Number.MAX_SAFE_INTEGER);
73 expect(histogram.getValueAtPercentile(99.999)).toBe(0);
74 });
75});
76//# sourceMappingURL=PackedHistogram.spec.js.map
Note: See TracBrowser for help on using the repository browser.