source: trip-planner-front/node_modules/hdr-histogram-js/assembly/__tests__/encoding.spec.ts@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * This is a AssemblyScript port of the original Java version, which was written by
3 * Gil Tene as described in
4 * https://github.com/HdrHistogram/HdrHistogram
5 * and released to the public domain, as explained at
6 * http://creativecommons.org/publicdomain/zero/1.0/
7 */
8
9import { decodeFromByteBuffer, encodeIntoByteBuffer } from "../encoding";
10import { Histogram32, Uint32Storage } from "../Histogram";
11import ByteBuffer from "../ByteBuffer";
12
13describe("Histogram encoding", () => {
14 it("should encode filling a byte buffer", () => {
15 // given
16 const histogram = new Histogram32(1, 9007199254740991, 2);
17 histogram.recordValue(42);
18 const buffer = ByteBuffer.allocate();
19 // when
20 const encodedSize = encodeIntoByteBuffer<Uint32Storage, u32>(
21 histogram,
22 buffer
23 );
24 // then
25 expect(encodedSize).toBe(42);
26 });
27
28 it("should encode / decode", () => {
29 // given
30 const histogram = new Histogram32(1, 9007199254740991, 2);
31 histogram.recordValue(42);
32 histogram.recordValue(7);
33 histogram.recordValue(77);
34 const buffer = ByteBuffer.allocate();
35 const encodedSize = encodeIntoByteBuffer<Uint32Storage, u32>(
36 histogram,
37 buffer
38 );
39 buffer.position = 0;
40 // when
41 const result = decodeFromByteBuffer<Uint32Storage, u32>(buffer, 0);
42 // then
43 expect(result.outputPercentileDistribution()).toBe(
44 histogram.outputPercentileDistribution()
45 );
46 });
47 it("should encode / decode bis", () => {
48 // given
49 const histogram = new Histogram32(1, 9007199254740991, 2);
50 histogram.recordValue(42);
51 histogram.recordValue(7);
52 histogram.recordValue(77);
53 const data = histogram.encode();
54 // when
55 const buffer = ByteBuffer.allocate();
56 buffer.data = data;
57 buffer.position = 0;
58 const result = decodeFromByteBuffer<Uint32Storage, u32>(buffer, 0);
59 // then
60 expect(result.outputPercentileDistribution()).toBe(
61 histogram.outputPercentileDistribution()
62 );
63 });
64 xit("should encode / decode without any assemblyscript crash", () => {
65 // given
66 const histogram = new Histogram32(1, 9007199254740991, 3);
67 histogram.autoResize = true;
68 histogram.recordValue(32415482);
69 const data = histogram.encode();
70 // when
71 const buffer = ByteBuffer.allocate();
72 buffer.data = data;
73 buffer.position = 0;
74 const result = decodeFromByteBuffer<Uint32Storage, u32>(buffer, 0);
75 // then
76 expect(result.outputPercentileDistribution()).toBe(
77 histogram.outputPercentileDistribution()
78 );
79 });
80});
Note: See TracBrowser for help on using the repository browser.