How to use fullConstraints method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

texture-cache.ts

Source:texture-cache.ts Github

copy

Full Screen

1/**2 * Copyright 2019 Google Inc. All Rights Reserved.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 * http://www.apache.org/licenses/LICENSE-2.07 * Unless required by applicable law or agreed to in writing, software8 * distributed under the License is distributed on an "AS IS" BASIS,9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10 * See the License for the specific language governing permissions and11 * limitations under the License.12 */13import version from "consts:version";14import { del, get, set } from "idb-keyval";15import { noCache } from "src/main/utils/constants";16import { task } from "../../utils/scheduling";17import { staticDevicePixelRatio } from "../utils/static-display";18import { TextureGenerator } from "./texture-generators";19export type TextureDrawer = (20 idx: number,21 ctx: CanvasRenderingContext2D,22 cellSize: number23) => void;24export interface SizeConstraints {25 maxWidth: number;26 maxHeight: number;27}28const defaultSizeConstraints = {29 // Allegedly, Chrome, Firefox and Safari have a maximum canvas size of 32k30 // pixels. We are *definitely* below that, but for some reason the draws to31 // the sprite sheet just seem to stop happening at higher indices when32 // tileSize is big (due to high dPR for exampe). The maxWidth of 8192 has been33 // determined by trial and error and seems to be safe.34 maxWidth: 8192,35 maxHeight: 3276836};37export interface TextureCache {38 drawer: TextureDrawer;39 caches: HTMLImageElement[];40}41const TEXTURE_CACHE_IDB_PREFIX = "texturecache";42// Wraps an existing TextureGenerator and caches the generated43// frames in an img.44export async function cacheTextureGenerator(45 name: string,46 drawTexture: TextureGenerator,47 textureSize: number,48 numFrames: number,49 constraints: Partial<SizeConstraints> = {}50): Promise<TextureCache> {51 const fullConstraints = { ...defaultSizeConstraints, ...constraints };52 const maxFramesPerRow = Math.floor(53 fullConstraints.maxWidth / (textureSize * staticDevicePixelRatio)54 );55 const maxRowsPerSprite = Math.floor(56 fullConstraints.maxHeight / (textureSize * staticDevicePixelRatio)57 );58 const maxFramesPerSprite = maxFramesPerRow * maxRowsPerSprite;59 let buffers: ArrayBuffer[];60 const prefix = `${TEXTURE_CACHE_IDB_PREFIX}:${name}`;61 const expectedVersion = `${version}:${textureSize}:${staticDevicePixelRatio}`;62 const cachedTextureVersion = await get(`${prefix}:version`);63 if (cachedTextureVersion !== expectedVersion || noCache) {64 await del(`${prefix}:version`);65 await del(`${prefix}:buffers`);66 buffers = await createBuffers(67 drawTexture,68 textureSize,69 numFrames,70 fullConstraints71 );72 await set(`${prefix}:version`, expectedVersion);73 await set(`${prefix}:buffers`, buffers);74 } else {75 buffers = await get(`${prefix}:buffers`);76 }77 // Ok, strap in, because this next bit is stupid.78 // iOS devices seem to crash when they have some number of large canvases in memory.79 // But! They seem to handle large images just fine.80 // So, we have to convert our canvas into an image!81 // Hooray! The day is saved.82 const caches = new Array(buffers.length);83 for (let i = 0; i < buffers.length; i++) {84 const image = new Image();85 image.src = URL.createObjectURL(86 new Blob([buffers[i]], { type: "image/png" })87 );88 await new Promise(r => (image.onload = r));89 caches[i] = image;90 await task();91 }92 const drawer = (93 idx: number,94 targetCtx: CanvasRenderingContext2D,95 cellSize: number96 ) => {97 idx = Math.floor(idx % numFrames);98 const sprite = Math.floor(idx / maxFramesPerSprite);99 const idxInSprite = idx % maxFramesPerSprite;100 const xIndex = idxInSprite % maxFramesPerRow;101 const yIndex = Math.floor(idxInSprite / maxFramesPerRow);102 const img = caches[sprite];103 const x = xIndex * textureSize;104 const y = yIndex * textureSize;105 targetCtx.drawImage(106 img,107 x * staticDevicePixelRatio,108 y * staticDevicePixelRatio,109 textureSize * staticDevicePixelRatio,110 textureSize * staticDevicePixelRatio,111 0,112 0,113 cellSize,114 cellSize115 );116 };117 return { drawer, caches };118}119async function createBuffers(120 drawTexture: TextureGenerator,121 textureSize: number,122 numFrames: number,123 constraints: SizeConstraints124) {125 const { maxWidth, maxHeight } = constraints;126 const maxFramesPerRow = Math.floor(127 maxWidth / (textureSize * staticDevicePixelRatio)128 );129 const maxRowsPerSprite = Math.floor(130 maxHeight / (textureSize * staticDevicePixelRatio)131 );132 const maxFramesPerSprite = maxFramesPerRow * maxRowsPerSprite;133 const numSprites = Math.ceil(numFrames / maxFramesPerSprite);134 const buffers: ArrayBuffer[] = [];135 for (let spriteIndex = 0; spriteIndex < numSprites; spriteIndex++) {136 const framesLeftToCache = numFrames - spriteIndex * maxFramesPerSprite;137 const width = maxWidth;138 const height = maxHeight;139 const canvas = document.createElement("canvas");140 canvas.width = width;141 canvas.height = height;142 const ctx = canvas.getContext("2d");143 if (!ctx) {144 throw Error("Could not instantiate 2D rendering context");145 }146 ctx.scale(staticDevicePixelRatio, staticDevicePixelRatio);147 for (148 let indexInSprite = 0;149 indexInSprite < framesLeftToCache && indexInSprite < maxFramesPerSprite;150 indexInSprite++151 ) {152 const frame = spriteIndex * maxFramesPerSprite + indexInSprite;153 const xIndex = indexInSprite % maxFramesPerRow;154 const yIndex = Math.floor(indexInSprite / maxFramesPerRow);155 const x = xIndex * textureSize;156 const y = yIndex * textureSize;157 ctx.save();158 ctx.translate(x, y);159 drawTexture(frame, ctx);160 ctx.restore();161 // Await a task to give the main thread a chance to breathe.162 await task();163 }164 const blob = await new Promise<Blob | null>(r =>165 canvas.toBlob(r, "image/png")166 );167 const buffer = await new Response(blob!).arrayBuffer();168 buffers.push(buffer);169 }170 return buffers;...

Full Screen

Full Screen

integer.ts

Source:integer.ts Github

copy

Full Screen

1import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';2import { IntegerArbitrary } from './_internals/IntegerArbitrary';3const safeNumberIsInteger = Number.isInteger;4/**5 * Constraints to be applied on {@link integer}6 * @remarks Since 2.6.07 * @public8 */9export interface IntegerConstraints {10 /**11 * Lower bound for the generated integers (included)12 * @defaultValue -0x8000000013 * @remarks Since 2.6.014 */15 min?: number;16 /**17 * Upper bound for the generated integers (included)18 * @defaultValue 0x7fffffff19 * @remarks Since 2.6.020 */21 max?: number;22}23/**24 * Build fully set IntegerConstraints from a partial data25 * @internal26 */27function buildCompleteIntegerConstraints(constraints: IntegerConstraints): Required<IntegerConstraints> {28 const min = constraints.min !== undefined ? constraints.min : -0x80000000;29 const max = constraints.max !== undefined ? constraints.max : 0x7fffffff;30 return { min, max };31}32/**33 * For integers between min (included) and max (included)34 *35 * @param constraints - Constraints to apply when building instances (since 2.6.0)36 *37 * @remarks Since 0.0.138 * @public39 */40export function integer(constraints: IntegerConstraints = {}): Arbitrary<number> {41 const fullConstraints = buildCompleteIntegerConstraints(constraints);42 if (fullConstraints.min > fullConstraints.max) {43 throw new Error('fc.integer maximum value should be equal or greater than the minimum one');44 }45 if (!safeNumberIsInteger(fullConstraints.min)) {46 throw new Error('fc.integer minimum value should be an integer');47 }48 if (!safeNumberIsInteger(fullConstraints.max)) {49 throw new Error('fc.integer maximum value should be an integer');50 }51 return new IntegerArbitrary(fullConstraints.min, fullConstraints.max);...

Full Screen

Full Screen

FieldModel.ts

Source:FieldModel.ts Github

copy

Full Screen

1import {2 createPatternConstraint,3 NumberConstraint,4 RequiredConstraint5} from './Constraints'6import {7 FieldErrors,8 FieldType,9 FormValueType,10 FormValues,11 ValueConstraint12} from './types'13export const buildField = <V extends FormValues>({14 name,15 type,16 value,17 required = false,18 pattern,19 constraints20}: {21 name: keyof V22 type: FieldType23 value: FormValueType24 required?: boolean25 pattern?: string26 constraints?: ValueConstraint<string> | ValueConstraint<string>[]27}) => {28 let fullConstraints: ValueConstraint<string>[] = []29 const isDirty = false30 if (required) {31 fullConstraints.push(RequiredConstraint)32 }33 if (type === 'number') {34 fullConstraints.push(NumberConstraint)35 }36 if (!!pattern) {37 fullConstraints.push(createPatternConstraint(pattern))38 }39 if (!!constraints) {40 fullConstraints = fullConstraints.concat(41 Array.isArray(constraints) ? constraints : [constraints]42 )43 }44 const field = {45 name,46 type,47 required,48 value,49 constraints: fullConstraints,50 isDirty,51 get isValid() {52 return !field.errors.has53 },54 errors: {55 has: false56 } as FieldErrors<string>,57 check() {58 field.constraints.forEach(59 constraint =>60 (field.errors[constraint.name] = !constraint.check(field.value))61 )62 field.errors.has = Object.keys(field.errors).some(63 key => key !== 'has' && (field.errors[key] as boolean)64 )65 },66 reset(value: FormValueType) {67 field.constraints.forEach(68 constraint => (field.errors[constraint.name] = false)69 )70 field.errors.has = false71 field.value = value72 }73 }74 return field...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fullConstraints } = require('fast-check');2const fc = fullConstraints();3fc.assert(4 fc.property(fc.integer(), fc.integer(), (a, b) => {5 return a + b >= a && a + b >= b;6 })7);8const { fullConstraints } = require('fast-check');9const fc = fullConstraints();10fc.assert(11 fc.property(fc.integer(), fc.integer(), (a, b) => {12 return a + b >= a && a + b >= b;13 })14);15 at Object.<anonymous> (test3.js:5:22)16 at Module._compile (internal/modules/cjs/loader.js:1138:30)17 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)18 at Module.load (internal/modules/cjs/loader.js:986:32)19 at Function.Module._load (internal/modules/cjs/loader.js:879:14)20 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)21{22 "scripts": {23 },24 "devDependencies": {25 },26}27{

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { fullConstraints } = require('fast-check/lib/types/FullConstraintsArbitrary');3const arb = fc.fullConstraints({4 a: fc.nat(),5 b: fc.nat(),6 c: fc.nat(),7});8fc.assert(fc.property(arb, (val) => {9 console.log(val);10 return true;11}));12const fc = require('fast-check');13const { fullConstraints } = require('fast-check/lib/types/FullConstraintsArbitrary');14const arb = fc.fullConstraints({15 a: fc.nat(),16 b: fc.nat(),17 c: fc.nat(),18});19fc.assert(fc.property(arb, (val) => {20 console.log(val);21 return true;22}));23const fc = require('fast-check');24const { fullConstraints } = require('fast-check/lib/types/FullConstraintsArbitrary');25const arb = fc.fullConstraints({26 a: fc.nat(),27 b: fc.nat(),28 c: fc.nat(),29});30fc.assert(fc.property(arb, (val) => {31 console.log(val);32 return true;33}));34const fc = require('fast-check');35const { fullConstraints } = require('fast-check/lib/types/FullConstraintsArbitrary');36const arb = fc.fullConstraints({37 a: fc.nat(),38 b: fc.nat(),39 c: fc.nat(),40});41fc.assert(fc.property(arb, (val) => {42 console.log(val);43 return true;44}));45const fc = require('fast-check');46const { fullConstraints } = require('fast-check/lib/types/FullConstraintsArbitrary');47const arb = fc.fullConstraints({48 a: fc.nat(),49 b: fc.nat(),50 c: fc.nat(),51});52fc.assert(fc.property(arb, (val) => {53 console.log(val);54 return true;55}));56const fc = require('fast-check');

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const fullConstraints = require("fast-check-monorepo").fullConstraints;3const constraints = {4 a: { type: "number", min: 0, max: 10 },5 b: { type: "number", min: 0, max: 10 },6 c: { type: "number", min: 0, max: 10 },7 d: { type: "number", min: 0, max: 10 },8 e: { type: "number", min: 0, max: 10 },9 f: { type: "number", min: 0, max: 10 },10 g: { type: "number", min: 0, max: 10 },11 h: { type: "number", min: 0, max: 10 },12 i: { type: "number", min: 0, max: 10 },13 j: { type: "number", min: 0, max: 10 },14 k: { type: "number", min: 0, max: 10 },15 l: { type: "number", min: 0, max: 10 },16 m: { type: "number", min: 0, max: 10 },17 n: { type: "number", min: 0, max: 10 },18 o: { type: "number", min: 0, max: 10 },19 p: { type: "number", min: 0, max: 10 },20 q: { type: "number", min: 0, max: 10 },21 r: { type: "number", min: 0, max: 10 },22 s: { type: "number", min: 0, max: 10 },23 t: { type: "number", min: 0, max: 10 },24 u: { type: "number", min: 0, max: 10 },25 v: { type: "number", min: 0, max: 10 },26 w: { type: "number", min: 0, max: 10 },27 x: { type: "number", min: 0, max: 10 },28 y: { type: "number", min

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { fullConstraints } = require('fast-check-monorepo');3const customGenerator = () => {4 return fc.integer().map((x) => x + 1);5};6const customConstraint = (x) => {7 return x > 0;8};9const customShrinker = (x) => {10 return fc.shrinkNumber(x).map((x) => x - 1);11};12const property = (x) => {13 return x > 0;14};15const propertyWithCustom = (x) => {16 return x > 0;17};18const propertyWithCustom2 = (x) => {19 return x > 0;20};21const propertyWithCustom3 = (x) => {22 return x > 0;23};24const propertyWithCustom4 = (x) => {25 return x > 0;26};27const propertyWithCustom5 = (x) => {28 return x > 0;29};30const propertyWithCustom6 = (x) => {31 return x > 0;32};33const propertyWithCustom7 = (x) => {34 return x > 0;35};36const propertyWithCustom8 = (x) => {37 return x > 0;38};39const propertyWithCustom9 = (x) => {40 return x > 0;41};42const propertyWithCustom10 = (x) => {43 return x > 0;44};45const propertyWithCustom11 = (x) => {46 return x > 0;47};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fullConstraints } from 'fast-check';2import { isInteger } from 'lodash';3import { expect } from 'chai';4import 'mocha';5describe('fullConstraints', () => {6 it('should run the test', () => {7 const fc = fullConstraints();8 fc.assert(fc.property(fc.integer(), (n) => {9 expect(isInteger(n)).to.be.true;10 }));11 });12});13import { fullConstraints } from 'fast-check';14import { isInteger } from 'lodash';15import { expect } from 'chai';16import 'mocha';17describe('fullConstraints', () => {18 it('should run the test', () => {19 const fc = fullConstraints();20 fc.assert(fc.property(fc.integer(), (n) => {21 expect(isInteger(n)).to.be.true;22 }));23 });24});25const response = await getResponse();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful