How to use the fast-check.integer function in fast-check

To help you get started, we’ve selected a few fast-check examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dubzzz / fast-check / example / 003-misc / mazeGenerator / main.spec.ts View on Github external
expect(_.flatten(maze).filter(c => c !== CellType.Wall && c !== 'Visited')).toHaveLength(0);
      })
    );
  });
});

// Helpers

const seedArb = fc
  .integer()
  .noBias()
  .noShrink();

const dimensionArb = fc.record({
  width: fc.integer(2, 20),
  height: fc.integer(2, 20)
});

const inputsArb = dimensionArb
  .chain(dim => {
    return fc.record({
      dim: fc.constant(dim),
      startPt: fc.record({ x: fc.nat(dim.width - 1), y: fc.nat(dim.height - 1) }),
      endPt: fc.record({ x: fc.nat(dim.width - 1), y: fc.nat(dim.height - 1) })
    });
  })
  .filter(ins => ins.startPt.x !== ins.endPt.x || ins.startPt.y !== ins.endPt.y);

const neighboorsFor = (pt: Point): Point[] => {
  return [{ x: pt.x - 1, y: pt.y }, { x: pt.x + 1, y: pt.y }, { x: pt.x, y: pt.y - 1 }, { x: pt.x, y: pt.y + 1 }];
};
const nonWallNeighboorsFor = (maze: CellType[][], pt: Point): Point[] => {
github dubzzz / fast-check / example / 003-misc / mazeGenerator / main.spec.ts View on Github external
// All cells are either Walls or marked as visited
        expect(_.flatten(maze).filter(c => c !== CellType.Wall && c !== 'Visited')).toHaveLength(0);
      })
    );
  });
});

// Helpers

const seedArb = fc
  .integer()
  .noBias()
  .noShrink();

const dimensionArb = fc.record({
  width: fc.integer(2, 20),
  height: fc.integer(2, 20)
});

const inputsArb = dimensionArb
  .chain(dim => {
    return fc.record({
      dim: fc.constant(dim),
      startPt: fc.record({ x: fc.nat(dim.width - 1), y: fc.nat(dim.height - 1) }),
      endPt: fc.record({ x: fc.nat(dim.width - 1), y: fc.nat(dim.height - 1) })
    });
  })
  .filter(ins => ins.startPt.x !== ins.endPt.x || ins.startPt.y !== ins.endPt.y);

const neighboorsFor = (pt: Point): Point[] => {
  return [{ x: pt.x - 1, y: pt.y }, { x: pt.x + 1, y: pt.y }, { x: pt.x, y: pt.y - 1 }, { x: pt.x, y: pt.y + 1 }];
};
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it("- identity", () =>
        fc.assert(fc.asyncProperty(arbIO(fc.integer()), functor.identity))
      );
github CJex / regulex / test / utils.ts View on Github external
return C.constantFrom(...ch.ranges).chain(range =>
    C.integer(K.CharRange.begin(range), K.CharRange.end(range)).map(String.fromCodePoint)
  );
github HdrHistogram / HdrHistogramJS / src / Histogram.jsverify.spec.ts View on Github external
const arbData = (size: number) =>
  fc.array(fc.integer(1, Number.MAX_SAFE_INTEGER), size, size);
github dubzzz / fast-check / example / binary-trees / arbitraries / BinaryTreeArbitrary.ts View on Github external
export const binaryTree = (maxDepth: number): fc.Arbitrary> => {
  const valueArbitrary = fc.integer();
  if (maxDepth <= 0) {
    return fc.record({
      value: valueArbitrary,
      left: fc.constant(null),
      right: fc.constant(null)
    });
  }
  const subTree = fc.oneof(fc.constant(null), binaryTree(maxDepth - 1));
  return fc.record({
    value: valueArbitrary,
    left: subTree,
    right: subTree
  });
};
github dubzzz / fast-check / example / binary-trees / arbitraries / FullBinaryTreeArbitrary.ts View on Github external
export const fullBinaryTree = (maxDepth: number): fc.Arbitrary> => {
  const valueArbitrary = fc.integer();
  if (maxDepth <= 0) {
    return fc.record({
      value: valueArbitrary,
      left: fc.constant(null),
      right: fc.constant(null)
    });
  }
  const subTree = fullBinaryTree(maxDepth - 1);
  return fc.boolean().chain(
    (hasChildren: boolean): fc.Arbitrary> => {
      if (hasChildren) {
        return fc.record({
          value: valueArbitrary,
          left: subTree,
          right: subTree
        });
github dubzzz / fast-check / example / 003-misc / knight / arbitraries / SpaceArbitrary.ts View on Github external
import fc from 'fast-check';
import { SpaceBuilder, Space } from '../src/space';

export const SpaceArbitrary = fc
  .record({
    w: fc.integer(1, 1000),
    h: fc.integer(1, 1000),
    cx: fc.integer(1, 1000),
    cy: fc.integer(1, 1000),
    sx: fc.integer(1, 1000),
    sy: fc.integer(1, 1000)
  })
  .filter(({ w, h, cx, cy, sx, sy }) => cx < w && sx < w && cy < h && sy < h)
  .map(({ w, h, cx, cy, sx, sy }) =>
    new SpaceBuilder()
      .withDimension(w, h)
      .withSolution(cx, cy)
      .withCurrent(sx, sy)
      .build()
  )
  .map(space => [space, Math.ceil(Math.log(Math.max(space.dim_x, space.dim_y)) / Math.log(2))] as [Space, number]);
github dubzzz / fast-check / example / binary-trees / arbitraries / PerfectBinaryTreeArbitrary.ts View on Github external
export const perfectBinaryTree = (depth: number): fc.Arbitrary> => {
  const valueArbitrary = fc.integer();
  if (depth <= 0) {
    return fc.record({
      value: valueArbitrary,
      left: fc.constant(null),
      right: fc.constant(null)
    });
  }
  const subTree = perfectBinaryTree(depth - 1);
  return fc.record({
    value: valueArbitrary,
    left: subTree,
    right: subTree
  });
};
github dubzzz / fast-check / example / 003-misc / knight / arbitraries / SpaceArbitrary.ts View on Github external
import fc from 'fast-check';
import { SpaceBuilder, Space } from '../src/space';

export const SpaceArbitrary = fc
  .record({
    w: fc.integer(1, 1000),
    h: fc.integer(1, 1000),
    cx: fc.integer(1, 1000),
    cy: fc.integer(1, 1000),
    sx: fc.integer(1, 1000),
    sy: fc.integer(1, 1000)
  })
  .filter(({ w, h, cx, cy, sx, sy }) => cx < w && sx < w && cy < h && sy < h)
  .map(({ w, h, cx, cy, sx, sy }) =>
    new SpaceBuilder()
      .withDimension(w, h)
      .withSolution(cx, cy)
      .withCurrent(sx, sy)
      .build()
  )
  .map(space => [space, Math.ceil(Math.log(Math.max(space.dim_x, space.dim_y)) / Math.log(2))] as [Space, number]);