Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("- associaive composition", () =>
fc.assert(
fc.asyncProperty(
arbIO(fc.string()),
fc.constant(strlen).map(io.pure),
fc.constant(even).map(io.pure),
apply.associativeComposition
)
)
);
it("- associaive composition", () =>
fc.assert(
fc.asyncProperty(
arbIO(fc.string()),
fc.constant(strlen).map(io.pure),
fc.constant(even).map(io.pure),
apply.associativeComposition
)
)
);
it('should serialize using getSerializedArrayType', () => {
const schema = record({
type: constant<'array'>('array'),
items: record({
type: constant<'string'>('string'),
format: constant(none),
deprecated: constant(none),
}),
format: constant(none),
deprecated: constant(none),
});
assert(
property($refArbitrary, schema, string(), (from, schema, name) => {
const expected = pipe(
schema.items,
serializeSchemaObject(from, name),
either.map(getSerializedArrayType(name)),
);
const serialized = pipe(schema, serializeSchemaObject(from, name));
expect(serialized).toEqual(expected);
}),
export function arbConstIO(a: A): Arbitrary> {
return arbIO(fc.constant(a));
}
return valueArbitrary.chain(rootValue => {
const leftArb = binarySearchTree(maxDepth - 1, minValue, rootValue);
const rightArb = rootValue < maxValue ? binarySearchTree(maxDepth - 1, rootValue + 1, maxValue) : fc.constant(null);
return fc.record({
value: fc.constant(rootValue),
left: fc.oneof(fc.constant(null), leftArb),
right: fc.oneof(fc.constant(null), rightArb)
});
});
};
return fc.anything();
case 'UndefinedType':
case 'VoidType':
return fc.constant(undefined) as any;
case 'NullType':
return fc.constant(null) as any;
case 'StringType':
return fc.string() as any;
case 'NumberType':
return fc.float() as any;
case 'BooleanType':
return fc.boolean() as any;
case 'KeyofType':
return fc.oneof(...keys(type.keys).map(fc.constant)) as any;
case 'LiteralType':
return fc.constant(type.value);
case 'ArrayType':
return fc.array(getArbitrary(type.type)) as any;
case 'DictionaryType':
return fc.dictionary(getArbitrary(type.domain), getArbitrary(type.codomain)) as any;
case 'InterfaceType':
case 'PartialType':
case 'ExactType':
return fc.record(record.map(getProps(type), getArbitrary as any) as any) as any;
case 'TupleType':
return (fc.tuple as any)(...type.types.map(getArbitrary));
case 'UnionType':
return fc.oneof(...type.types.map(getArbitrary)) as any;
case 'IntersectionType':
const isObjectIntersection = objectTypes.includes(type.types[0]._tag);
return isObjectIntersection
? (fc.tuple as any)(...type.types.map(t => getArbitrary(t)))
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 binarySearchTree = (
maxDepth: number,
minValue: number = Number.MIN_SAFE_INTEGER,
maxValue: number = Number.MAX_SAFE_INTEGER
): fc.Arbitrary> => {
const valueArbitrary = fc.integer(minValue, maxValue);
if (maxDepth <= 0) {
return fc.record({
value: valueArbitrary,
left: fc.constant(null),
right: fc.constant(null)
});
}
return valueArbitrary.chain(rootValue => {
const leftArb = binarySearchTree(maxDepth - 1, minValue, rootValue);
const rightArb = rootValue < maxValue ? binarySearchTree(maxDepth - 1, rootValue + 1, maxValue) : fc.constant(null);
return fc.record({
value: fc.constant(rootValue),
left: fc.oneof(fc.constant(null), leftArb),
right: fc.oneof(fc.constant(null), rightArb)
});
});
};
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 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
});
};