[6a3a178] | 1 | /*
|
---|
| 2 | * This is a TypeScript 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 | import * as fc from "fast-check";
|
---|
| 9 | import { PackedArray } from "./PackedArray";
|
---|
| 10 |
|
---|
| 11 | const runFromStryker = __dirname.includes("stryker");
|
---|
| 12 |
|
---|
| 13 | const runnerOptions = {
|
---|
| 14 | numRuns: runFromStryker ? 10 : 1000,
|
---|
| 15 | verbose: true
|
---|
| 16 | };
|
---|
| 17 |
|
---|
| 18 | describe("Packed array", () => {
|
---|
| 19 | it("should store data as a regular sparse array", () => {
|
---|
| 20 | const SIZE = 1000;
|
---|
| 21 | fc.assert(
|
---|
| 22 | fc.property(arbData(SIZE), entries => {
|
---|
| 23 | const packedArray = new PackedArray(SIZE + 1);
|
---|
| 24 | const sparseArray = new Array();
|
---|
| 25 | entries.forEach(([index, value]) => packedArray.add(index, value));
|
---|
| 26 | entries.forEach(([index, value]) => {
|
---|
| 27 | if (sparseArray[index]) {
|
---|
| 28 | sparseArray[index] = sparseArray[index] + value;
|
---|
| 29 | } else {
|
---|
| 30 | sparseArray[index] = value;
|
---|
| 31 | }
|
---|
| 32 | });
|
---|
| 33 | return entries.every(
|
---|
| 34 | ([index]) => sparseArray[index] === packedArray.get(index)
|
---|
| 35 | );
|
---|
| 36 | }),
|
---|
| 37 | runnerOptions
|
---|
| 38 | );
|
---|
| 39 | });
|
---|
| 40 | });
|
---|
| 41 |
|
---|
| 42 | const arbData = (size: number) =>
|
---|
| 43 | fc.array(fc.tuple(fc.integer(1, size), fc.integer(1, 100000000)), 1, size);
|
---|