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

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

initial commit

  • Property mode set to 100644
File size: 7.3 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Recorder_1 = require("./Recorder");
4const Int32Histogram_1 = require("./Int32Histogram");
5const PackedHistogram_1 = require("./PackedHistogram");
6const wasm_1 = require("./wasm");
7describe("Recorder", () => {
8 beforeAll(wasm_1.initWebAssembly);
9 it("should record value", () => {
10 // given
11 const recorder = new Recorder_1.default();
12 // when
13 recorder.recordValue(123);
14 // then
15 const histogram = recorder.getIntervalHistogram();
16 expect(histogram.totalCount).toBe(1);
17 });
18 it("should record value in a packed histogram", () => {
19 // given
20 const recorder = new Recorder_1.default({
21 numberOfSignificantValueDigits: 5,
22 bitBucketSize: "packed",
23 });
24 // when
25 recorder.recordValue(123);
26 // then
27 expect(recorder.getIntervalHistogram() instanceof PackedHistogram_1.default).toBe(true);
28 expect(recorder.getIntervalHistogram() instanceof PackedHistogram_1.default).toBe(true);
29 });
30 it("should record value in a WASM histogram", () => {
31 // given
32 const recorder = new Recorder_1.default({
33 numberOfSignificantValueDigits: 5,
34 bitBucketSize: "packed",
35 useWebAssembly: true,
36 });
37 try {
38 // when
39 recorder.recordValue(123);
40 // then
41 expect(recorder.getIntervalHistogram() instanceof wasm_1.WasmHistogram).toBe(true);
42 }
43 finally {
44 recorder.destroy();
45 }
46 });
47 it("should record value with count", () => {
48 // given
49 const recorder = new Recorder_1.default();
50 // when
51 recorder.recordValueWithCount(123, 3);
52 // then
53 const histogram = recorder.getIntervalHistogram();
54 expect(histogram.totalCount).toBe(3);
55 });
56 it("should record value with expected interval", () => {
57 // given
58 const recorder = new Recorder_1.default();
59 // when
60 recorder.recordValueWithExpectedInterval(223, 100);
61 // then
62 const histogram = recorder.getIntervalHistogram();
63 expect(histogram.totalCount).toBe(2);
64 });
65 it("should record value in a packed histogram", () => {
66 // given
67 const recorder = new Recorder_1.default({ bitBucketSize: "packed" });
68 recorder.recordValue(42);
69 // when
70 const histogram = recorder.getIntervalHistogram();
71 // then
72 expect(histogram instanceof PackedHistogram_1.default).toBe(true);
73 });
74 it("should record value only on one interval histogram", () => {
75 // given
76 const recorder = new Recorder_1.default();
77 // when
78 recorder.recordValue(123);
79 const firstHistogram = recorder.getIntervalHistogram();
80 // then
81 const secondHistogram = recorder.getIntervalHistogram();
82 expect(secondHistogram.totalCount).toBe(0);
83 });
84 it("should not record value on returned interval histogram", () => {
85 // given
86 const recorder = new Recorder_1.default();
87 const firstHistogram = recorder.getIntervalHistogram();
88 const secondHistogram = recorder.getIntervalHistogram();
89 // when
90 firstHistogram.recordValue(42); // should have 0 impact on recorder
91 const thirdHistogram = recorder.getIntervalHistogram();
92 // then
93 expect(thirdHistogram.totalCount).toBe(0);
94 });
95 it("should return interval histograms with expected significant digits", () => {
96 // given
97 const recorder = new Recorder_1.default({ numberOfSignificantValueDigits: 4 });
98 const firstHistogram = recorder.getIntervalHistogram();
99 const secondHistogram = recorder.getIntervalHistogram();
100 // when
101 const thirdHistogram = recorder.getIntervalHistogram();
102 // then
103 expect(thirdHistogram.numberOfSignificantValueDigits).toBe(4);
104 });
105 it("should return recycled histograms when asking for interval histogram", () => {
106 // given
107 const recorder = new Recorder_1.default();
108 const firstHistogram = recorder.getIntervalHistogram();
109 // when
110 const secondHistogram = recorder.getIntervalHistogram(firstHistogram);
111 const thirdHistogram = recorder.getIntervalHistogram();
112 // then
113 expect(thirdHistogram === firstHistogram).toBe(true);
114 });
115 it("should throw an error when trying to recycle an histogram not created by the recorder", () => {
116 // given
117 const recorder = new Recorder_1.default();
118 const somehistogram = new Int32Histogram_1.default(1, 2, 3);
119 // when & then
120 expect(() => recorder.getIntervalHistogram(somehistogram)).toThrowError();
121 });
122 it("should reset histogram when recycling", () => {
123 // given
124 const recorder = new Recorder_1.default();
125 recorder.recordValue(42);
126 const firstHistogram = recorder.getIntervalHistogram();
127 // when
128 const secondHistogram = recorder.getIntervalHistogram(firstHistogram);
129 const thirdHistogram = recorder.getIntervalHistogram();
130 // then
131 expect(thirdHistogram.totalCount).toBe(0);
132 });
133 it("should set timestamps on first interval histogram", () => {
134 // given
135 let currentTime = 42;
136 let clock = () => currentTime;
137 const recorder = new Recorder_1.default({}, clock);
138 // when
139 currentTime = 123;
140 const histogram = recorder.getIntervalHistogram();
141 // then
142 expect(histogram.startTimeStampMsec).toBe(42);
143 expect(histogram.endTimeStampMsec).toBe(123);
144 });
145 it("should set timestamps on any interval histogram", () => {
146 // given
147 let currentTime = 42;
148 let clock = () => currentTime;
149 const recorder = new Recorder_1.default({}, clock);
150 currentTime = 51;
151 const firstHistogram = recorder.getIntervalHistogram();
152 // when
153 currentTime = 56;
154 const secondHistogram = recorder.getIntervalHistogram();
155 // then
156 expect(secondHistogram.startTimeStampMsec).toBe(51);
157 expect(secondHistogram.endTimeStampMsec).toBe(56);
158 });
159 it("should copy interval histogram", () => {
160 // given
161 let currentTime = 42;
162 let clock = () => currentTime;
163 const recorder = new Recorder_1.default({ numberOfSignificantValueDigits: 4 }, clock);
164 recorder.recordValue(123);
165 // when
166 const histogram = new Int32Histogram_1.default(1, Number.MAX_SAFE_INTEGER, 3);
167 currentTime = 51;
168 recorder.getIntervalHistogramInto(histogram);
169 // then
170 expect(histogram.totalCount).toBe(1);
171 expect(histogram.startTimeStampMsec).toBe(42);
172 expect(histogram.endTimeStampMsec).toBe(51);
173 });
174 it("should reset values and timestamp", () => {
175 // given
176 let currentTime = 42;
177 let clock = () => currentTime;
178 const recorder = new Recorder_1.default({ numberOfSignificantValueDigits: 4 }, clock);
179 recorder.recordValue(123);
180 // when
181 currentTime = 55;
182 recorder.reset();
183 const histogram = recorder.getIntervalHistogram();
184 // then
185 expect(histogram.totalCount).toBe(0);
186 expect(histogram.startTimeStampMsec).toBe(55);
187 });
188});
189//# sourceMappingURL=Recorder.spec.js.map
Note: See TracBrowser for help on using the repository browser.