How to use the fast-check.assert 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 / 005-race / dependencyTree / main.spec.ts View on Github external
it('should be able to compute a dependency tree for any package of the registry', () =>
    fc.assert(
      fc.asyncProperty(AllPackagesArbitrary, fc.scheduler(), async (packages, s) => {
        // Arrange
        const selectedPackage = Object.keys(packages)[0];
        const fetch: (name: string) => Promise = s.scheduleFunction(function fetch(packageName) {
          return Promise.resolve(packages[packageName]);
        });

        // Act
        dependencyTree(selectedPackage, fetch); // without bugs
        // dependencyTree(selectedPackage, fetch, true); // or with bugs

        // Assert
        let numQueries = 0;
        while (s.count() !== 0) {
          if (++numQueries > 2 * Object.keys(packages).length) {
            throw new Error(`Too many queries`);
github rzeigler / waveguide / test / fiber.spec.ts View on Github external
it("fork/join is the same result as initial", () =>
      fc.assert(
        fc.asyncProperty(
          arbEitherIO(fc.string(), fc.integer()),
          (inner) => eqvIO(
            io.result(inner),
            io.chain(io.fork(inner), (fiber) => fiber.wait)
          )
        ),
        { verbose: true }
      )
    );
github bitauth / bitcoin-ts / src / lib / crypto / secp256k1.spec.ts View on Github external
t.notThrows(() => {
    fc.assert(isEquivalentToDeriveUncompressedThenCompress);
  });
  const equivalentToSecp256k1Node = fc.property(
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)
  }
}
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 bitauth / bitcoin-ts / src / lib / crypto / secp256k1.spec.ts View on Github external
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 bitauth / bitcoin-ts / src / lib / utils / utf8.spec.ts View on Github external
t.notThrows(() => {
    fc.assert(inverse);
  });
});
github dubzzz / ava-fast-check / src / ava-fast-check.ts View on Github external
testFn(`${label} (with seed=${customParams.seed})`, async t => {
    await fc.assert((fc.asyncProperty as any)(...arbitraries, promiseProp), params);
    t.pass();
  });
}