source: trip-planner-front/node_modules/hdr-histogram-js/dist/TypedArrayHistogram.spec.js@ ceaed42

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

initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Int8Histogram_1 = require("./Int8Histogram");
4const Int16Histogram_1 = require("./Int16Histogram");
5const Int32Histogram_1 = require("./Int32Histogram");
6const Float64Histogram_1 = require("./Float64Histogram");
7[Int8Histogram_1.default, Int16Histogram_1.default, Int32Histogram_1.default, Float64Histogram_1.default].forEach((Histogram) => {
8 describe(`${Histogram} histogram`, () => {
9 it("should record a value", () => {
10 // given
11 const histogram = new Histogram(1, Number.MAX_SAFE_INTEGER, 3);
12 // when
13 histogram.recordValue(123456);
14 // then
15 expect(histogram.getCountAtIndex(8073)).toBe(1);
16 });
17 it("should compute median value in first bucket", () => {
18 // given
19 const histogram = new Histogram(1, Number.MAX_SAFE_INTEGER, 3);
20 histogram.recordValue(123456);
21 histogram.recordValue(127);
22 histogram.recordValue(42);
23 // when
24 const medianValue = histogram.getValueAtPercentile(50);
25 // then
26 expect(medianValue).toBe(127);
27 });
28 it("should compute value outside first bucket with an error less than 1000", () => {
29 // given
30 const histogram = new Histogram(1, Number.MAX_SAFE_INTEGER, 3);
31 histogram.recordValue(123456);
32 histogram.recordValue(122777);
33 histogram.recordValue(127);
34 histogram.recordValue(42);
35 // when
36 const percentileValue = histogram.getValueAtPercentile(99.9);
37 // then
38 expect(Math.abs(percentileValue - 123456)).toBeLessThan(1000);
39 // TODO the value is 123519 > max, ask Gil if it is a bug
40 });
41 it("should resize recording values above max", () => {
42 // given
43 const histogram = new Histogram(1, 2, 3);
44 histogram.autoResize = true;
45 // when
46 histogram.recordValue(123456);
47 histogram.recordValue(127000);
48 histogram.recordValue(420000);
49 // then
50 const medianValue = histogram.getValueAtPercentile(50);
51 expect(Math.abs(medianValue - 127000)).toBeLessThan(1000);
52 });
53 it("should compute proper value at percentile even with rounding issues", () => {
54 // given
55 const histogram = new Histogram(1, Number.MAX_SAFE_INTEGER, 3);
56 histogram.recordValue(1);
57 histogram.recordValue(2);
58 // when & then
59 expect(histogram.getValueAtPercentile(50.0)).toBe(1);
60 expect(histogram.getValueAtPercentile(50.00000000000001)).toBe(1);
61 expect(histogram.getValueAtPercentile(50.0000000000001)).toBe(2);
62 });
63 });
64});
65//# sourceMappingURL=TypedArrayHistogram.spec.js.map
Note: See TracBrowser for help on using the repository browser.