source: trip-planner-front/node_modules/hdr-histogram-js/src/packedarray/PackedArray.fc.spec.ts@ 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: 1.3 KB
RevLine 
[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 */
8import * as fc from "fast-check";
9import { PackedArray } from "./PackedArray";
10
11const runFromStryker = __dirname.includes("stryker");
12
13const runnerOptions = {
14 numRuns: runFromStryker ? 10 : 1000,
15 verbose: true
16};
17
18describe("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
42const arbData = (size: number) =>
43 fc.array(fc.tuple(fc.integer(1, size), fc.integer(1, 100000000)), 1, size);
Note: See TracBrowser for help on using the repository browser.