How to use the fast-check.tuple 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 CJex / regulex / test / KitSpec.ts View on Github external
describe('CharRange', () => {
    it('compareFullUnicode', () => {
      // String.fromCodePoint(0x1F437) == "🐷" == "\uD83D\uDC37" == "\u{1F437}"
      let c1 = '\uD83D\uDC37';
      let c2 = '\uFA16';
      assert(K.compareFullUnicode(c1, c2) > 0);
    });

    testProp('subtract join intersect', C.tuple(charRangeGen(), charRangeGen()), a => {
      let [r1, r2] = a;
      assert(K.CharRange.subtract(r1, r1) === undefined);
      assert(K.CharRange.join(r1, r1) === r1);

      let inter = K.CharRange.intersect(r1, r2);
      if (inter === undefined) {
        assert(K.CharRange.subtract(r1, r2) === r1);
        assert(K.CharRange.subtract(r2, r1) === r2);
      } else {
        let join = K.CharRange.join(r1, r2);
        if (join === undefined) return assert(join !== undefined);

        let j1 = K.CharRange.subtract(join, r1);
        if (j1 === undefined) return assert(join === r1 && K.CharRange.isSubsetOf(r2, r1));
        let j2 = K.CharRange.subtract(join, r2);
        if (j2 === undefined) return assert(join === r2 && K.CharRange.isSubsetOf(r1, r2));
github rzeigler / waveguide / test / tools.spec.ts View on Github external
.chain((ioStep) => {
      if (ioStep === "succeed") {
        return arb.map((a) => pure(a) as Wave); // force downcast
      } else if (ioStep === "complete") {
        return arb.map((a) => completed(done(a)));
      } else if (ioStep === "suspend") {
        // We now need to do recursion... wooo
        return arbIO(arb)
          .map((nestedIO) => suspended(() => nestedIO));
      } else { // async with random delay
        return fc.tuple(fc.nat(50), arb)
          .map(
            ([delay, val]) =>
              asyncTotal((callback) => {
                const handle = setTimeout(() => callback(val), delay);
                return () => {
                  clearTimeout(handle);
                };
              }));
      }
    });
}
github rzeigler / waveguide / test / queue.spec.ts View on Github external
it("elements are always consumed completely in the order they are produced", () =>
    fc.assert(
      fc.asyncProperty(
        fc.array(fc.tuple(fc.string(), fc.nat(20), fc.nat(20))),
        fc.nat(100),
        fc.nat(100),
        (ops, delayWrite, delayRead) =>
          io.runToPromise(Do(io.instances)
            .bind("q", unboundedQueue())
            .bindL("writeFiber",
              ({q}) =>
                pipe(
                  array.traverse(io.instances)(ops, ([v, d]) =>
                    io.delay(q.offer(v), d)),
                  io.liftDelay(delayWrite),
                  io.fork
                )
            )
            .bindL("readFiber",
              ({q}) =>
github rzeigler / waveguide / test / semaphore.spec.ts View on Github external
it("never deadlocks", () =>
      fc.assert(
        fc.asyncProperty(
          fc.array(fc.tuple(fc.nat(100), fc.nat(10), fc.nat(10), fc.boolean()), 100),
          (acquires) => {
            const eff = io.chain(makeSemaphore(100),
              (sem) =>
                pipe(
                  array.traverse(io.instances)(acquires, ([n, pre, post, int]) =>
                    sem.withPermitsN(n, pipe(
                      (int ? io.raiseInterrupt : io.after(post)),
                      io.liftDelay(pre),
                      io.fork
                    ))
                  ),
                  io.chainWith((fibers) => array.traverse(io.instances)(fibers, (f) => f.wait)),
                  (result) => io.applySecond(result, sem.available)
                )
            );
            return expectExit(eff, done(100));
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
it('should serialize non recursive', () => {
			const refs = pipe(
				tuple($refArbitrary, $refArbitrary),
				arbitrary.filterMap(([from, to]) =>
					to.$ref !== from.$ref
						? some({
								from,
								to,
						  })
						: none,
				),
			);
			assert(
				property(refs, refs => {
					const { from, to } = refs;
					const serialized = getSerializedRefType(from)(to);
					const type = getTypeName(to.name);
					const io = getIOName(to.name);
					const p = getRelativePath(from, to);
github aiden / rpc_ts / src / protocol / grpc_web / __tests__ / client_server.it.ts View on Github external
const lowerCamelCase = () =>
  fc
    .tuple(
      fc.constantFrom(...'abcdefghijklmnopqrstuvwxyz'.split('')),
      fc.stringOf(
        fc.constantFrom(
          ...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split(
            '',
          ),
        ),
      ),
    )
    .map(([firstLetter, remaining]) => `${firstLetter}${remaining}`);
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
getSerializedRefType,
	getSerializedUnionType,
	intercalateSerializedTypes,
	serializedType,
} from '../serialized-type';
import { serializedDependency } from '../serialized-dependency';
import { $refArbitrary } from '../../../../../utils/__tests__/ref.spec';
import { getRelativePath } from '../../../../../utils/ref';
import { pipe } from 'fp-ts/lib/pipeable';
import { arbitrary, nonEmptyArray } from '../../../../../utils/fast-check';
import { none, some } from 'fp-ts/lib/Option';
import { getIOName, getTypeName, UNSAFE_PROPERTY_PATTERN } from '../../utils';
import { when } from '../../../../../utils/string';
import { head } from 'fp-ts/lib/NonEmptyArray';

const serializedDependencyArbitrary = tuple(string(), string()).map(([name, path]) => serializedDependency(name, path));

export const serializedTypeArbitrary = tuple(
	string(),
	string(),
	array(serializedDependencyArbitrary),
	pipe(array($refArbitrary)),
).map(([type, io, dependencies, refs]) => serializedType(type, io, dependencies, refs));

const name = oneof(string(), constant(undefined));

describe('SerializedType', () => {
	it('getSerializedArrayType', () => {
		assert(
			property(serializedTypeArbitrary, name, (s, name) => {
				expect(pipe(s, getSerializedArrayType(name))).toEqual(
					serializedType(
github CJex / regulex / test / KitSpec.ts View on Github external
describe('Charset', function() {
    this.timeout(60000);

    testProp('fromPattern toPattern equal', listOfCharRange(), a => {
      let charset = new K.Charset(a);
      assert(K.Charset.fromPattern(charset.toPattern()).equals(charset));
    });

    testProp('should include/exclude chars', C.tuple(listOfCharRange(10), C.boolean()), ([a, toExclude]) => {
      let charset = new K.Charset(a);
      if (toExclude) {
        charset = K.Charset.fromPattern('^' + charset.toPattern());
      }
      for (let range of a) {
        for (let c of sampleInCharRange(range)) {
          assert(charset.includeChar(c) !== toExclude);
        }
      }
    });

    testProp('union intersect subtract', C.tuple(listOfCharRange(), listOfCharRange()), ([ranges1, ranges2]) => {
      let charset1 = new K.Charset(ranges1);
      let charset2 = new K.Charset(ranges2);
      assert(charset1.union(charset1).equals(charset1));
      let union = charset1.union(charset2);
github CJex / regulex / test / KitSpec.ts View on Github external
const charPairGen = () => C.tuple(C.fullUnicode(), C.fullUnicode());
const charRangeGen = () =>
github dubzzz / fast-check / example / 005-race / dependencyTree / main.spec.ts View on Github external
packageNames.map(pname =>
        fc.tuple(fc.constant(pname), fc.record({
          dependencies: fc.dictionary(fc.constantFrom(...packageNames), fc.constant('1.0.0'))
        }) as fc.Arbitrary)
      )