How to use the fast-check.property 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
it('should have only non-isolated path, start, end', () => {
    fc.assert(
      fc.property(seedArb, inputsArb, (seed, ins) => {
        const maze: (CellType | 'Visited')[][] = mazeGenerator(seed, ins.dim, ins.startPt, ins.endPt);

        const ptsToVisit = [ins.startPt, ins.endPt];
        while (ptsToVisit.length > 0) {
          const [pt] = ptsToVisit.splice(ptsToVisit.length - 1);
          maze[pt.y][pt.x] = 'Visited';

          ptsToVisit.push(
            ...neighboorsFor(pt).filter(nPt => {
              const cell = cellTypeAt(maze, nPt);
              return cell !== null && cell !== CellType.Wall && cell !== 'Visited';
            })
          );
        }
        // All cells are either Walls or marked as visited
        expect(_.flatten(maze).filter(c => c !== CellType.Wall && c !== 'Visited')).toHaveLength(0);
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
it('should skip self-reference dependencies', () => {
			assert(
				property($refArbitrary, ref => {
					const type = getTypeName(ref.name);
					const io = getIOName(ref.name);
					const expected = serializedType(type, io, [], [ref]);
					const serialized = getSerializedRefType(ref)(ref);
					expect(serialized).toEqual(expected);
				}),
			);
		});
	});
github CJex / regulex / test / utils.ts View on Github external
return () => {
    let params: any = {};
    if (process.env.seedpath) {
      params = JSON.parse(process.env.seedpath.replace(/seed|path/g, '"$&"'));
      params.endOnFailure = true;
    }
    let prop = C.property(arb, f);
    const out = C.check(prop, params);
    if (out instanceof Promise) {
      return out.then(_throwIfFailed);
    } else {
      _throwIfFailed(out);
    }
  };
}
github bitauth / bitcoin-ts / src / lib / crypto / secp256k1.spec.ts View on Github external
test('crypto: secp256k1.derivePublicKeyCompressed', async t => {
  const secp256k1 = await secp256k1Promise;
  t.deepEqual(secp256k1.derivePublicKeyCompressed(privkey), pubkeyCompressed);
  t.throws(() => secp256k1.derivePublicKeyCompressed(secp256k1OrderN));
  const isEquivalentToDeriveUncompressedThenCompress = fc.property(
    fcValidPrivateKey(secp256k1),
    privateKey => {
      const pubkeyU = secp256k1.derivePublicKeyUncompressed(privateKey);
      const pubkeyC = secp256k1.derivePublicKeyCompressed(privateKey);
      t.deepEqual(pubkeyC, secp256k1.compressPublicKey(pubkeyU));
    }
  );
  t.notThrows(() => {
    fc.assert(isEquivalentToDeriveUncompressedThenCompress);
  });
  const equivalentToSecp256k1Node = fc.property(
    fcValidPrivateKey(secp256k1),
    privateKey => {
      t.deepEqual(
        secp256k1.derivePublicKeyCompressed(privateKey),
        new Uint8Array(
github bitauth / bitcoin-ts / src / lib / crypto / secp256k1.spec.ts View on Github external
const equivalentToSecp256k1Node = fc.property(
    fcValidPrivateKey(secp256k1),
    privateKey => {
      const pubkeyU = secp256k1.derivePublicKeyUncompressed(privateKey);
      t.deepEqual(
        secp256k1.compressPublicKey(pubkeyU),
        new Uint8Array(
          secp256k1Node.publicKeyConvert(Buffer.from(pubkeyU), true)
        )
      );
    }
  );
  t.notThrows(() => {
    fc.assert(equivalentToSecp256k1Node);
  });
  const equivalentToElliptic = fc.property(
    fcValidPrivateKey(secp256k1),
    privateKey => {
      const pubkeyU = secp256k1.derivePublicKeyUncompressed(privateKey);
      t.deepEqual(
        secp256k1.compressPublicKey(pubkeyU),
        new Uint8Array(
          ec
            .keyFromPublic(pubkeyU)
            .getPublic()
            .encodeCompressed()
        )
      );
    }
  );
  t.notThrows(() => {
    fc.assert(equivalentToElliptic);
github gcanti / fp-ts-laws / src / index.ts View on Github external
return (lift, liftEq) => {
    applyF(lift, liftEq)

    const arbFa = lift(fc.string())
    const Sa = liftEq(eqString)
    const Sb = liftEq(eqNumber)
    const identity = fc.property(arbFa, laws.applicative.identity(F, Sa))
    const ab = (s: string) => s.length
    const homomorphism = fc.property(fc.string(), laws.applicative.homomorphism(F, Sb, ab))
    const arbFab = lift(fc.constant(ab))
    const interchange = fc.property(fc.string(), arbFab, laws.applicative.interchange(F, Sb))
    const derivedMap = fc.property(arbFa, laws.applicative.derivedMap(F, Sb, ab))

    fc.assert(identity)
    fc.assert(homomorphism)
    fc.assert(interchange)
    fc.assert(derivedMap)
  }
}
github gcanti / fp-ts-laws / src / index.ts View on Github external
export const semiring = <a>(S: Semiring</a><a>, E: Eq</a><a>, arb: fc.Arbitrary</a><a>, seed?: number): void =&gt; {
  const addAssociativity = fc.property(arb, arb, arb, laws.semiring.addAssociativity(S, E))
  const addIdentity = fc.property(arb, laws.semiring.addIdentity(S, E))
  const commutativity = fc.property(arb, arb, laws.semiring.commutativity(S, E))
  const mulAssociativity = fc.property(arb, arb, arb, laws.semiring.mulAssociativity(S, E))
  const mulIdentity = fc.property(arb, laws.semiring.mulIdentity(S, E))
  const leftDistributivity = fc.property(arb, arb, arb, laws.semiring.leftDistributivity(S, E))
  const rightDistributivity = fc.property(arb, arb, arb, laws.semiring.rightDistributivity(S, E))
  const annihilation = fc.property(arb, laws.semiring.annihilation(S, E))
  fc.assert(addAssociativity, { seed })
  fc.assert(addIdentity, { seed })
  fc.assert(commutativity, { seed })
  fc.assert(mulAssociativity, { seed })
  fc.assert(mulIdentity, { seed })
  fc.assert(leftDistributivity, { seed })
  fc.assert(rightDistributivity, { seed })
  fc.assert(annihilation, { seed })
}
</a>
github gcanti / fp-ts-laws / src / index.ts View on Github external
export const field = <a>(F: Field</a><a>, S: Eq</a><a>, arb: fc.Arbitrary</a><a>, seed?: number): void =&gt; {
  ring(F, S, arb, seed)
  if (S.equals(F.zero, F.one)) {
    throw new Error(`one should not be equal to zero`)
  }
  const commutativity = fc.property(arb, arb, laws.field.commutativity(F, S))
  const integralDomain = fc.property(arb, arb, laws.field.integralDomain(F, S))
  const nonNegativity = fc.property(arb, laws.field.nonNegativity(F, S))
  const quotient = fc.property(arb, arb, laws.field.quotient(F, S))
  const reminder = fc.property(arb, arb, laws.field.reminder(F, S))
  const submultiplicative = fc.property(arb, arb, laws.field.submultiplicative(F, S))
  const inverse = fc.property(arb, laws.field.inverse(F, S))
  fc.assert(commutativity, { seed })
  fc.assert(integralDomain, { seed })
  fc.assert(nonNegativity, { seed })
  fc.assert(quotient, { seed })
  fc.assert(reminder, { seed })
  fc.assert(submultiplicative, { seed })
  fc.assert(inverse, { seed })
}
</a>
github gcanti / fp-ts-laws / src / index.ts View on Github external
return liftEq => {
    applicativeM(arb => arb.map(M.of), liftEq)

    const Sc = liftEq(eqBoolean)
    const arbFa = fc.string().map(M.of)
    const afb = (s: string) => M.of(s.length)
    const bfc = (n: number) => M.of(n > 2)
    const associativity = fc.property(arbFa, laws.chain.associativity(M, Sc, afb, bfc))
    const Sb = liftEq(eqNumber)
    const fab = M.of((a: string) => a.length)
    const derivedAp = fc.property(arbFa, laws.chain.derivedAp(M, Sb, fab))

    fc.assert(associativity)
    fc.assert(derivedAp)

    const arb = fc.string().map(M.of)
    const Sa = liftEq(eqString)
    const leftIdentity = fc.property(fc.string(), laws.monad.leftIdentity(M, Sb, afb))
    const rightIdentity = fc.property(arb, laws.monad.rightIdentity(M, Sa))
    const ab = (s: string) => s.length
    const derivedMap = fc.property(arb, laws.monad.derivedMap(M, Sb, ab))

    fc.assert(leftIdentity)
    fc.assert(rightIdentity)
github gcanti / fp-ts-laws / src / index.ts View on Github external
return liftEq => {
    applicativeM(arb => arb.map(M.of), liftEq)

    const Sc = liftEq(eqBoolean)
    const arbFa = fc.string().map(M.of)
    const afb = (s: string) => M.of(s.length)
    const bfc = (n: number) => M.of(n > 2)
    const associativity = fc.property(arbFa, laws.chain.associativity(M, Sc, afb, bfc))
    const Sb = liftEq(eqNumber)
    const fab = M.of((a: string) => a.length)
    const derivedAp = fc.property(arbFa, laws.chain.derivedAp(M, Sb, fab))

    fc.assert(associativity)
    fc.assert(derivedAp)

    const arb = fc.string().map(M.of)
    const Sa = liftEq(eqString)
    const leftIdentity = fc.property(fc.string(), laws.monad.leftIdentity(M, Sb, afb))
    const rightIdentity = fc.property(arb, laws.monad.rightIdentity(M, Sa))
    const ab = (s: string) => s.length
    const derivedMap = fc.property(arb, laws.monad.derivedMap(M, Sb, ab))

    fc.assert(leftIdentity)
    fc.assert(rightIdentity)
    fc.assert(derivedMap)
  }
}