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 |
|
---|
9 | import { PackedArray } from "../packedarray/PackedArray";
|
---|
10 |
|
---|
11 | describe("Packed Array", () => {
|
---|
12 | it("should store a byte without extending array", () => {
|
---|
13 | // given
|
---|
14 | const packed = new PackedArray(1024);
|
---|
15 | // when
|
---|
16 | packed.set(42, 123);
|
---|
17 | // then
|
---|
18 | expect(packed.get(42)).toBe(123);
|
---|
19 | });
|
---|
20 |
|
---|
21 | it("should resize array when storing data", () => {
|
---|
22 | // given
|
---|
23 | const array = new PackedArray(1024, 16);
|
---|
24 |
|
---|
25 | // when
|
---|
26 | array.set(12, u64.MAX_VALUE);
|
---|
27 |
|
---|
28 | // then
|
---|
29 | const storedData = array.get(12);
|
---|
30 | expect(storedData).toBe(u64.MAX_VALUE);
|
---|
31 | });
|
---|
32 | it("should store a big number", () => {
|
---|
33 | // given
|
---|
34 | const array = new PackedArray(45056, 16);
|
---|
35 |
|
---|
36 | // when
|
---|
37 | array.set(32768, 1);
|
---|
38 |
|
---|
39 | // then
|
---|
40 | const storedData = array.get(32768);
|
---|
41 | expect(storedData).toBe(1);
|
---|
42 | const storedDataAt0 = array.get(0);
|
---|
43 | expect(storedDataAt0).toBe(0);
|
---|
44 | });
|
---|
45 | });
|
---|