source: trip-planner-front/node_modules/hdr-histogram-js/dist/encoding.spec.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 12.2 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/*
4 * This is a TypeScript port of the original Java version, which was written by
5 * Gil Tene as described in
6 * https://github.com/HdrHistogram/HdrHistogram
7 * and released to the public domain, as explained at
8 * http://creativecommons.org/publicdomain/zero/1.0/
9 */
10const index_1 = require("./index");
11const wasm_1 = require("./wasm");
12const encoding_1 = require("./encoding");
13describe("Histogram encoding", () => {
14 it("should encode and decode an histogram", () => {
15 // given
16 const histogram = new index_1.Int32Histogram(1, 2, 3);
17 histogram.autoResize = true;
18 histogram.recordValue(32415);
19 // when
20 const b64 = encoding_1.encodeIntoCompressedBase64(histogram);
21 // then
22 const decodedHistogram = encoding_1.decodeFromCompressedBase64(b64);
23 expect(decodedHistogram.toJSON()).toStrictEqual(histogram.toJSON());
24 });
25 it("should decode and decompress reading a base64 string", () => {
26 // given
27 const base64String = "HISTFAAAAB542pNpmSzMwMDAxAABzFCaEUoz2X+AMIKZAEARAtM=";
28 // when
29 const histogram = encoding_1.decodeFromCompressedBase64(base64String);
30 // then
31 expect(histogram.mean).toBe(42);
32 expect(histogram.totalCount).toBe(1);
33 });
34 it("should decode and decompress a big base64 string", () => {
35 // given
36 const base64String = "HISTFAAACGB42j1WQY4cuRGks7KzWWwOh1NTGo1GEmzBWCx0EAxjsdiTsdiTD4ZPfoa/4R/4o/7BOiKSrWnNVBWLzIyMiMzWp//897mUA7/62db1D/n3999//V8umBW74POTPds7+4In2/xq722zv9huj/bRbvZH+2oPdrV3vtu//AOeP9if8Ra7H7DlhlcPePyo+w1xrrh+84uZFzd7QkyEL/ZXJPgN295jC5bsii0FN084/BXXDQH+jqPMlhn5eYf1D/beb9h7BdSfseMJGG5C94h3BRFveibyZ9x9wR1KeaebR0P8J/vVfsCbHevv7DO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qzgx5zE6/ImJQKMN3OFYe5mQ9qxv/RyvzY854QpIM/AX2/w8xoluoETnnONtvowxZjuPjiLbS61vwydCAu4x2tlfz47U3A75zonNmEHgZbzM3pAIaNuJQYbFMY8GaMjjAyv1PNtLf208c87XPlBEsLVeZ5/HGfWIAwyjodoJwmYMR6HH2SfcVnGnsYbTfPiENP316K8Dr8+K4hpIgdlHBUdgox3jBSk6K0YP9qMBzZzRX0CQgwTYPXBw1IHCQDLeI1kDG/0E0nqOA5+O8EA+XhFytKO1E5MJlZ4dvNY5zzpeHFkhH9K8sS/npFjIZZ8aM4e/NGjUx/BjvCHA0QnkBTHwFqGO2Y+jw24T0rNF/oT3/Zx06P8BChhtKw==";
37 // when
38 const histogram = encoding_1.decodeFromCompressedBase64(base64String);
39 // then
40 expect(histogram.totalCount).toBe(10000);
41 });
42 it("should encode and compress an histogram to a base64 string", () => {
43 // given
44 const histogram = new index_1.Int32Histogram(1, 2, 3);
45 histogram.recordValue(42);
46 // when
47 const base64Histogram = encoding_1.encodeIntoCompressedBase64(histogram);
48 // then
49 expect(base64Histogram).toBe("HISTFAAAAB94nJNpmSzMwMDABMSMQMzMAAGMUJoJxg9mAgA1TQGm");
50 });
51 it("should throw an error when trying to decompress an histogram using V1 encoding", () => {
52 // given
53 const base64V1EncodingString = "HISTIgAAAFd42pNpmazIwMAYxgABTBDKT4GBgdnNYMcCBvsPUBkeBkYGZqA8MwMbAzsDC5DFBCTZgJCDQY1BjkGLQZRBlUEPCB8zWDCYMxgDZZkZhgJgHDibAY8JB/A=";
54 // when & then
55 expect(() => encoding_1.decodeFromCompressedBase64(base64V1EncodingString)).toThrowError("Encoding not supported");
56 });
57});
58describe("WASM Histogram encoding", () => {
59 let histogram;
60 beforeAll(wasm_1.initWebAssembly);
61 afterEach(() => {
62 if (histogram) {
63 histogram.destroy();
64 }
65 });
66 it("should decode and decompress a big base64 string", () => {
67 // given
68 const base64String = "HISTFAAACGB42j1WQY4cuRGks7KzWWwOh1NTGo1GE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g2+ik/eGO0Jzgg1Zw++iJBgEpWcGl10sUqFw6hd+vp+S0xOHIqC5fGrRIRq0IxTUZtloyDI9aP8kagP6fmk/us9HEos4YEzrEOCk1BWBtkYk6OXKObwHgMfN81sVnpdliHDPKLDnoWGRJGiK4xPzhjKruu9UYpQYh6ASv0lbe0DOdX6ayAmNEkyFoLv7JoQH6o/+CDoS3xt5wqjSpJhHjtjZr1OCA+Ys5ZDzYx/DL6iI4eG8dr6bOPA7hnbccc53gbPNJHqzgx5zE6/ImJQKMN3OFYe5mQ9qxv/RyvzY854QpIM/AX2/w8xoluoETnnONtvowxZjuPjiLbS61vwydCAu4x2tlfz47U3A75zonNmEHgZbzM3pAIaNuJQYbFMY8GaMjjAyv1PNtLf208c87XPlBEsLVeZ5/HGfWIAwyjodoJwmYMR6HH2SfcVnGnsYbTfPiENP316K8Dr8+K4hpIgdlHBUdgox3jBSk6K0YP9qMBzZzRX0CQgwTYPXBw1IHCQDLeI1kDG/0E0nqOA5+O8EA+XhFytKO1E5MJlZ4dvNY5zzpeHFkhH9K8sS/npFjIZZ8aM4e/NGjUx/BjvCHA0QnkBTHwFqGO2Y+jw24T0rNF/oT3/Zx06P8BChhtKw==";
69 // when
70 histogram = encoding_1.decodeFromCompressedBase64(base64String, 32, true);
71 // then
72 //console.log(histogram);
73 expect(histogram.totalCount).toBe(10000);
74 });
75 it("should decode and decompress a big base64 string to a wasm packed histogram", () => {
76 // given
77 const base64String = "HISTFAAACGB42j1WQY4cuRGks7KzWWwOh1NTGo1GEmzBWCx0EAxjsdiTsdiTD4ZPfoa/4R/4o/7BOiKSrWnNVBWLzIyMiMzWp//897mUA7/62db1D/n3999//V8umBW74POTPds7+4In2/xq722zv9huj/bRbvZH+2oPdrV3vtu//AOeP9if8Ra7H7DlhlcPePyo+w1xrrh+84uZFzd7QkyEL/ZXJPgN295jC5bsii0FN084/BXXDQH+jqPMlhn5eYf1D/beb9h7BdSfseMJGG5C94h3BRFveibyZ9x9wR1KeaebR0P8J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7hnbccc53gbPNJHqzgx5zE6/ImJQKMN3OFYe5mQ9qxv/RyvzY854QpIM/AX2/w8xoluoETnnONtvowxZjuPjiLbS61vwydCAu4x2tlfz47U3A75zonNmEHgZbzM3pAIaNuJQYbFMY8GaMjjAyv1PNtLf208c87XPlBEsLVeZ5/HGfWIAwyjodoJwmYMR6HH2SfcVnGnsYbTfPiENP316K8Dr8+K4hpIgdlHBUdgox3jBSk6K0YP9qMBzZzRX0CQgwTYPXBw1IHCQDLeI1kDG/0E0nqOA5+O8EA+XhFytKO1E5MJlZ4dvNY5zzpeHFkhH9K8sS/npFjIZZ8aM4e/NGjUx/BjvCHA0QnkBTHwFqGO2Y+jw24T0rNF/oT3/Zx06P8BChhtKw==";
78 // when
79 histogram = encoding_1.decodeFromCompressedBase64(base64String, "packed", true);
80 // then
81 expect(histogram.totalCount).toBe(10000);
82 });
83 it("should encode and decode an histogram", () => {
84 // given
85 histogram = index_1.WasmHistogram.build();
86 histogram.recordValue(32415482);
87 // when
88 const b64 = encoding_1.encodeIntoCompressedBase64(histogram);
89 // then
90 const decodedHistogram = encoding_1.decodeFromCompressedBase64(b64);
91 expect(decodedHistogram.getValueAtPercentile(50)).toBe(histogram.getValueAtPercentile(50));
92 });
93});
94//# sourceMappingURL=encoding.spec.js.map
Note: See TracBrowser for help on using the repository browser.