How to use the fast-check.constant 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 rzeigler / waveguide / test / wave.spec.ts View on Github external
it("- associaive composition", () =>
        fc.assert(
          fc.asyncProperty(
            arbIO(fc.string()),
            fc.constant(strlen).map(io.pure),
            fc.constant(even).map(io.pure),
            apply.associativeComposition
          )
        )
      );
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it("- associaive composition", () =>
        fc.assert(
          fc.asyncProperty(
            arbIO(fc.string()),
            fc.constant(strlen).map(io.pure),
            fc.constant(even).map(io.pure),
            apply.associativeComposition
          )
        )
      );
github devexperts / swagger-codegen-ts / src / language / typescript / 3.0 / serializers / __tests__ / schema-object.spec.ts View on Github external
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);
					}),
github rzeigler / waveguide / test / tools.spec.ts View on Github external
export function arbConstIO(a: A): Arbitrary> {
  return arbIO(fc.constant(a));
}
github dubzzz / fast-check / example / binary-trees / arbitraries / BinarySearchTreeArbitrary.ts View on Github external
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)
    });
  });
};
github giogonzo / fast-check-io-ts / src / index.ts View on Github external
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)))
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 / BinarySearchTreeArbitrary.ts View on Github external
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)
    });
  });
};
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 / 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
  });
};