Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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[] => {
// 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 }];
};
it("- identity", () =>
fc.assert(fc.asyncProperty(arbIO(fc.integer()), functor.identity))
);
return C.constantFrom(...ch.ranges).chain(range =>
C.integer(K.CharRange.begin(range), K.CharRange.end(range)).map(String.fromCodePoint)
);
const arbData = (size: number) =>
fc.array(fc.integer(1, Number.MAX_SAFE_INTEGER), size, size);
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
});
};
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
});
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]);
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
});
};
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]);