How to use sizeForArbitraryArb method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

MaxLengthFromMinLength.spec.ts

Source:MaxLengthFromMinLength.spec.ts Github

copy

Full Screen

1import fc from 'fast-check';2import {3 DefaultSize,4 depthBiasFromSizeForArbitrary,5 maxGeneratedLengthFromSizeForArbitrary,6 maxLengthFromMinLength,7 MaxLengthUpperBound,8 relativeSizeToSize,9 resolveSize,10} from '../../../../../src/arbitrary/_internals/helpers/MaxLengthFromMinLength';11import { withConfiguredGlobal } from '../../__test-helpers__/GlobalSettingsHelpers';12import {13 sizeArb,14 isSmallerSize,15 relativeSizeArb,16 sizeForArbitraryArb,17 sizeRelatedGlobalConfigArb,18} from '../../__test-helpers__/SizeHelpers';19describe('maxLengthFromMinLength', () => {20 it('should result into higher or equal maxLength given higher size', () => {21 fc.assert(22 fc.property(sizeArb, sizeArb, fc.integer({ min: 0, max: MaxLengthUpperBound }), (sa, sb, minLength) => {23 // Arrange24 const [smallSize, largeSize] = isSmallerSize(sa, sb) ? [sa, sb] : [sb, sa];25 // Act / Assert26 expect(maxLengthFromMinLength(minLength, smallSize)).toBeLessThanOrEqual(27 maxLengthFromMinLength(minLength, largeSize)28 );29 })30 );31 });32 it('should result into higher or equal maxLength given higher minLength', () => {33 fc.assert(34 fc.property(35 sizeArb,36 fc.integer({ min: 0, max: MaxLengthUpperBound }),37 fc.integer({ min: 0, max: MaxLengthUpperBound }),38 (size, minLengthA, minLengthB) => {39 // Arrange40 const [smallMinLength, largeMinLength] =41 minLengthA < minLengthB ? [minLengthA, minLengthB] : [minLengthB, minLengthA];42 // Act / Assert43 expect(maxLengthFromMinLength(smallMinLength, size)).toBeLessThanOrEqual(44 maxLengthFromMinLength(largeMinLength, size)45 );46 }47 )48 );49 });50});51describe('maxGeneratedLengthFromSizeForArbitrary', () => {52 it('should only consider the received size when set to Size', () => {53 fc.assert(54 fc.property(55 sizeRelatedGlobalConfigArb,56 sizeArb,57 fc.integer({ min: 0, max: MaxLengthUpperBound }),58 fc.integer({ min: 0, max: MaxLengthUpperBound }),59 fc.boolean(),60 (config, size, lengthA, lengthB, specifiedMaxLength) => {61 // Arrange62 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];63 // Act64 const computedLength = withConfiguredGlobal(config, () =>65 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength)66 );67 const expectedLength = Math.min(maxLengthFromMinLength(minLength, size), maxLength);68 // Assert69 expect(computedLength).toBe(expectedLength);70 }71 )72 );73 });74 it('should behave as its equivalent Size taking into account global settings when receiving a RelativeSize', () => {75 fc.assert(76 fc.property(77 sizeRelatedGlobalConfigArb,78 relativeSizeArb,79 fc.integer({ min: 0, max: MaxLengthUpperBound }),80 fc.integer({ min: 0, max: MaxLengthUpperBound }),81 fc.boolean(),82 (config, size, lengthA, lengthB, specifiedMaxLength) => {83 // Arrange84 const { baseSize: defaultSize = DefaultSize } = config;85 const equivalentSize = relativeSizeToSize(size, defaultSize);86 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];87 // Act88 const computedLength = withConfiguredGlobal(config, () =>89 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength)90 );91 const expectedLength = maxGeneratedLengthFromSizeForArbitrary(92 equivalentSize,93 minLength,94 maxLength,95 specifiedMaxLength96 );97 // Assert98 expect(computedLength).toBe(expectedLength);99 }100 )101 );102 });103 it('should behave as its resolved Size when in unspecified max mode', () => {104 fc.assert(105 fc.property(106 sizeRelatedGlobalConfigArb,107 fc.oneof(sizeArb, relativeSizeArb),108 fc.integer({ min: 0, max: MaxLengthUpperBound }),109 fc.integer({ min: 0, max: MaxLengthUpperBound }),110 (config, size, lengthA, lengthB) => {111 // Arrange112 const resolvedSize = withConfiguredGlobal(config, () => resolveSize(size));113 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];114 // Act115 const computedLength = withConfiguredGlobal(config, () =>116 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, false)117 );118 const expectedLength = withConfiguredGlobal(config, () =>119 maxGeneratedLengthFromSizeForArbitrary(resolvedSize, minLength, maxLength, false)120 );121 // Assert122 expect(computedLength).toBe(expectedLength);123 }124 )125 );126 });127 it('should only consider the received maxLength when set to "max"', () => {128 fc.assert(129 fc.property(130 sizeRelatedGlobalConfigArb,131 fc.integer({ min: 0, max: MaxLengthUpperBound }),132 fc.integer({ min: 0, max: MaxLengthUpperBound }),133 fc.boolean(),134 (config, lengthA, lengthB, specifiedMaxLength) => {135 // Arrange136 const size = 'max';137 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];138 // Act139 const computedLength = withConfiguredGlobal(config, () =>140 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength)141 );142 // Assert143 expect(computedLength).toBe(maxLength);144 }145 )146 );147 });148 it('should ignore specifiedMaxLength whenever size specified', () => {149 fc.assert(150 fc.property(151 sizeRelatedGlobalConfigArb,152 sizeForArbitraryArb,153 fc.integer({ min: 0, max: MaxLengthUpperBound }),154 fc.integer({ min: 0, max: MaxLengthUpperBound }),155 (config, size, lengthA, lengthB) => {156 // Arrange157 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];158 // Act159 const computedLength = withConfiguredGlobal(config, () =>160 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, false)161 );162 const expectedLength = withConfiguredGlobal(config, () =>163 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, true)164 );165 // Assert166 expect(computedLength).toBe(expectedLength);167 }168 )169 );170 });171 it('should fallback to "max" whenever no size specified but maxLength specified when defaultSizeToMaxWhenMaxSpecified true or unset', () => {172 fc.assert(173 fc.property(174 sizeRelatedGlobalConfigArb,175 fc.integer({ min: 0, max: MaxLengthUpperBound }),176 fc.integer({ min: 0, max: MaxLengthUpperBound }),177 (incompleteConfig, lengthA, lengthB) => {178 // Arrange179 const config = { ...incompleteConfig, defaultSizeToMaxWhenMaxSpecified: true };180 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];181 // Act182 const computedLength = withConfiguredGlobal(config, () =>183 maxGeneratedLengthFromSizeForArbitrary(undefined, minLength, maxLength, true)184 );185 const expectedLength = withConfiguredGlobal(config, () =>186 maxGeneratedLengthFromSizeForArbitrary('max', minLength, maxLength, true)187 );188 // Assert189 expect(computedLength).toBe(expectedLength);190 }191 )192 );193 });194 it('should fallback to baseSize (or default) whenever no size specified and no maxLength specified', () => {195 fc.assert(196 fc.property(197 sizeRelatedGlobalConfigArb,198 fc.integer({ min: 0, max: MaxLengthUpperBound }),199 fc.integer({ min: 0, max: MaxLengthUpperBound }),200 (config, lengthA, lengthB) => {201 // Arrange202 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];203 const { baseSize: defaultSize = DefaultSize } = config;204 // Act205 const computedLength = withConfiguredGlobal(config, () =>206 maxGeneratedLengthFromSizeForArbitrary(undefined, minLength, maxLength, false)207 );208 const expectedLength = maxGeneratedLengthFromSizeForArbitrary(defaultSize, minLength, maxLength, false);209 // Assert210 expect(computedLength).toBe(expectedLength);211 }212 )213 );214 });215 it('should always return a length being between minLength and maxLength', () => {216 fc.assert(217 fc.property(218 sizeRelatedGlobalConfigArb,219 fc.option(sizeForArbitraryArb, { nil: undefined }),220 fc.integer({ min: 0, max: MaxLengthUpperBound }),221 fc.integer({ min: 0, max: MaxLengthUpperBound }),222 fc.boolean(),223 (config, size, lengthA, lengthB, specifiedMaxLength) => {224 // Arrange225 const [minLength, maxLength] = lengthA < lengthB ? [lengthA, lengthB] : [lengthB, lengthA];226 // Act227 const computedLength = withConfiguredGlobal(config, () =>228 maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength)229 );230 // Assert231 expect(computedLength).toBeGreaterThanOrEqual(minLength);232 expect(computedLength).toBeLessThanOrEqual(maxLength);233 }234 )235 );236 });237});238describe('depthSizeFromSizeForArbitrary', () => {239 it('should only consider the received depthSize when set to a numeric value', () => {240 fc.assert(241 fc.property(242 sizeRelatedGlobalConfigArb,243 fc.double({ min: 0 }),244 fc.boolean(),245 (config, size, specifiedMaxDepth) => {246 // Arrange / Act247 const computedDepthBias = withConfiguredGlobal(config, () =>248 depthBiasFromSizeForArbitrary(size, specifiedMaxDepth)249 );250 // Assert251 expect(computedDepthBias).toBe(1 / size);252 }253 )254 );255 });256 it('should only consider the received size when set to Size', () => {257 fc.assert(258 fc.property(sizeRelatedGlobalConfigArb, sizeArb, fc.boolean(), (config, size, specifiedMaxDepth) => {259 // Arrange / Act260 const computedDepthBias = withConfiguredGlobal(config, () =>261 depthBiasFromSizeForArbitrary(size, specifiedMaxDepth)262 );263 const expectedDepthBias = { xsmall: 1, small: 1 / 2, medium: 1 / 4, large: 1 / 8, xlarge: 1 / 16 }[size];264 // Assert265 expect(computedDepthBias).toBe(expectedDepthBias);266 })267 );268 });269 it('should behave as its equivalent Size taking into account global settings when receiving a RelativeSize', () => {270 fc.assert(271 fc.property(sizeRelatedGlobalConfigArb, relativeSizeArb, fc.boolean(), (config, size, specifiedMaxDepth) => {272 // Arrange273 const { baseSize: defaultSize = DefaultSize } = config;274 const equivalentSize = relativeSizeToSize(size, defaultSize);275 // Act276 const computedDepthBias = withConfiguredGlobal(config, () =>277 depthBiasFromSizeForArbitrary(size, specifiedMaxDepth)278 );279 const expectedDepthBias = depthBiasFromSizeForArbitrary(equivalentSize, false);280 // Assert281 expect(computedDepthBias).toBe(expectedDepthBias);282 })283 );284 });285 it('should always return 0 if size is max whatever the global configuration', () => {286 fc.assert(287 fc.property(sizeRelatedGlobalConfigArb, fc.boolean(), (config, specifiedMaxDepth) => {288 // Arrange / Act289 const computedDepthBias = withConfiguredGlobal(config, () =>290 depthBiasFromSizeForArbitrary('max', specifiedMaxDepth)291 );292 // Assert293 expect(computedDepthBias).toBe(0);294 })295 );296 });297 it('should always return 0 if both specifiedMaxDepth and defaultSizeToMaxWhenMaxSpecified are true and size unset', () => {298 fc.assert(299 fc.property(sizeRelatedGlobalConfigArb, (config) => {300 // Arrange / Act301 const computedDepthBias = withConfiguredGlobal({ ...config, defaultSizeToMaxWhenMaxSpecified: true }, () =>302 depthBiasFromSizeForArbitrary(undefined, true)303 );304 // Assert305 expect(computedDepthBias).toBe(0);306 })307 );308 });309});310describe('relativeSizeToSize', () => {311 it('should offset by -4 when "-4"', () => {312 const relativeSize = '-4';313 expect(relativeSizeToSize(relativeSize, 'xsmall')).toBe('xsmall');314 expect(relativeSizeToSize(relativeSize, 'small')).toBe('xsmall');315 expect(relativeSizeToSize(relativeSize, 'medium')).toBe('xsmall');316 expect(relativeSizeToSize(relativeSize, 'large')).toBe('xsmall');317 expect(relativeSizeToSize(relativeSize, 'xlarge')).toBe('xsmall');318 });319 it('should offset by -1 when "-1"', () => {320 const relativeSize = '-1';321 expect(relativeSizeToSize(relativeSize, 'xsmall')).toBe('xsmall');322 expect(relativeSizeToSize(relativeSize, 'small')).toBe('xsmall');323 expect(relativeSizeToSize(relativeSize, 'medium')).toBe('small');324 expect(relativeSizeToSize(relativeSize, 'large')).toBe('medium');325 expect(relativeSizeToSize(relativeSize, 'xlarge')).toBe('large');326 });327 it('should not offset when "="', () => {328 const relativeSize = '=';329 expect(relativeSizeToSize(relativeSize, 'xsmall')).toBe('xsmall');330 expect(relativeSizeToSize(relativeSize, 'small')).toBe('small');331 expect(relativeSizeToSize(relativeSize, 'medium')).toBe('medium');332 expect(relativeSizeToSize(relativeSize, 'large')).toBe('large');333 expect(relativeSizeToSize(relativeSize, 'xlarge')).toBe('xlarge');334 });335 it('should offset by +1 when "+1"', () => {336 const relativeSize = '+1';337 expect(relativeSizeToSize(relativeSize, 'xsmall')).toBe('small');338 expect(relativeSizeToSize(relativeSize, 'small')).toBe('medium');339 expect(relativeSizeToSize(relativeSize, 'medium')).toBe('large');340 expect(relativeSizeToSize(relativeSize, 'large')).toBe('xlarge');341 expect(relativeSizeToSize(relativeSize, 'xlarge')).toBe('xlarge');342 });343 it('should offset by +4 when "+4"', () => {344 const relativeSize = '+4';345 expect(relativeSizeToSize(relativeSize, 'xsmall')).toBe('xlarge');346 expect(relativeSizeToSize(relativeSize, 'small')).toBe('xlarge');347 expect(relativeSizeToSize(relativeSize, 'medium')).toBe('xlarge');348 expect(relativeSizeToSize(relativeSize, 'large')).toBe('xlarge');349 expect(relativeSizeToSize(relativeSize, 'xlarge')).toBe('xlarge');350 });...

Full Screen

Full Screen

base64String.spec.ts

Source:base64String.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { base64String } from '../../../src/arbitrary/base64String';3import {4 assertProduceValuesShrinkableWithoutContext,5 assertProduceCorrectValues,6 assertProduceSameValueGivenSameSeed,7} from './__test-helpers__/ArbitraryAssertions';8import * as ArrayMock from '../../../src/arbitrary/array';9import { fakeArbitrary } from './__test-helpers__/ArbitraryHelpers';10import { Value } from '../../../src/check/arbitrary/definition/Value';11import { buildShrinkTree, renderTree } from './__test-helpers__/ShrinkTree';12import { sizeForArbitraryArb } from './__test-helpers__/SizeHelpers';13function beforeEachHook() {14 jest.resetModules();15 jest.restoreAllMocks();16 fc.configureGlobal({ beforeEach: beforeEachHook });17}18beforeEach(beforeEachHook);19describe('base64String', () => {20 it('should accept any constraints accepting at least one length multiple of 4', () =>21 fc.assert(22 fc.property(23 fc.nat({ max: 5 }),24 fc.integer({ min: 3, max: 30 }),25 fc.boolean(),26 fc.boolean(),27 (min, gap, withMin, withMax) => {28 // Arrange29 const constraints = { minLength: withMin ? min : undefined, maxLength: withMax ? min + gap : undefined };30 // Act / Assert31 expect(() => base64String(constraints)).not.toThrowError();32 }33 )34 ));35 it('should reject any constraints not accepting at least one length multiple of 4', () =>36 fc.assert(37 fc.property(fc.nat({ max: 30 }), fc.nat({ max: 2 }), (min, gap) => {38 // Arrange39 const constraints = { minLength: min, maxLength: min + gap };40 let includesMultipleOf4 = false;41 for (let acceptedLength = constraints.minLength; acceptedLength <= constraints.maxLength; ++acceptedLength) {42 includesMultipleOf4 = includesMultipleOf4 || acceptedLength % 4 === 0;43 }44 fc.pre(!includesMultipleOf4);45 // Act / Assert46 expect(() => base64String(constraints)).toThrowError();47 })48 ));49 it('should always query for arrays that will produce length fitting the requested range', () =>50 fc.assert(51 fc.property(52 fc.nat({ max: 30 }),53 fc.integer({ min: 3, max: 30 }),54 fc.boolean(),55 fc.boolean(),56 (min, gap, withMin, withMax) => {57 // Arrange58 const constraints = { minLength: withMin ? min : undefined, maxLength: withMax ? min + gap : undefined };59 const array = jest.spyOn(ArrayMock, 'array');60 const { instance: arrayInstance, map } = fakeArbitrary();61 array.mockReturnValue(arrayInstance);62 map.mockReturnValue(arrayInstance); // fake map63 // Act64 base64String(constraints);65 // Assert66 expect(array).toHaveBeenCalledTimes(1);67 const constraintsOnArray = array.mock.calls[0][1]!;68 const rounded4 = (value: number) => {69 switch (value % 4) {70 case 0:71 return value;72 case 1:73 return value;74 case 2:75 return value + 2;76 case 3:77 return value + 1;78 }79 };80 if (constraints.minLength !== undefined) {81 expect(constraintsOnArray.minLength).toBeDefined();82 expect(rounded4(constraintsOnArray.minLength!)).toBeGreaterThanOrEqual(constraints.minLength);83 }84 if (constraints.maxLength !== undefined) {85 expect(constraintsOnArray.maxLength).toBeDefined();86 expect(rounded4(constraintsOnArray.maxLength!)).toBeLessThanOrEqual(constraints.maxLength);87 }88 if (constraintsOnArray.minLength !== undefined && constraintsOnArray.maxLength !== undefined) {89 expect(constraintsOnArray.maxLength).toBeGreaterThanOrEqual(constraintsOnArray.minLength);90 }91 }92 )93 ));94 it('should always forward constraints on size to the underlying arbitrary when provided', () =>95 fc.assert(96 fc.property(97 fc.nat({ max: 5 }),98 fc.integer({ min: 3, max: 30 }),99 fc.boolean(),100 fc.boolean(),101 sizeForArbitraryArb,102 (min, gap, withMin, withMax, size) => {103 // Arrange104 const constraints = {105 minLength: withMin ? min : undefined,106 maxLength: withMax ? min + gap : undefined,107 size,108 };109 const array = jest.spyOn(ArrayMock, 'array');110 const { instance: arrayInstance, map } = fakeArbitrary();111 array.mockReturnValue(arrayInstance);112 map.mockReturnValue(arrayInstance); // fake map113 // Act114 base64String(constraints);115 // Assert116 expect(array).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ size }));117 }118 )119 ));120});121describe('base64String (integration)', () => {122 type Extra = { minLength?: number; maxLength?: number };123 const extraParameters: fc.Arbitrary<Extra> = fc124 .tuple(fc.nat({ max: 30 }), fc.integer({ min: 3, max: 30 }), fc.boolean(), fc.boolean())125 .map(([min, gap, withMin, withMax]) => ({126 minLength: withMin ? min : undefined,127 // Minimal gap=3 to ensure we have at least one possible multiple of 4 between min and max128 maxLength: withMax ? min + gap : undefined,129 }));130 const isCorrect = (value: string, extra: Extra) => {131 if (extra.minLength !== undefined) {132 expect(value.length).toBeGreaterThanOrEqual(extra.minLength);133 }134 if (extra.maxLength !== undefined) {135 expect(value.length).toBeLessThanOrEqual(extra.maxLength);136 }137 const padStart = value.indexOf('=');138 const beforeEqualValue = value.substr(0, padStart === -1 ? value.length : padStart);139 const afterEqualValue = value.substr(padStart === -1 ? value.length : padStart);140 for (const c of beforeEqualValue.split('')) {141 expect('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/'.split('')).toContainEqual(c);142 }143 expect(['', '=', '==']).toContainEqual(afterEqualValue);144 };145 const base64StringBuilder = (extra: Extra) => base64String(extra);146 it('should produce the same values given the same seed', () => {147 assertProduceSameValueGivenSameSeed(base64StringBuilder, { extraParameters });148 });149 it('should only produce correct values', () => {150 assertProduceCorrectValues(base64StringBuilder, isCorrect, { extraParameters });151 });152 it('should produce values seen as shrinkable without any context', () => {153 assertProduceValuesShrinkableWithoutContext(base64StringBuilder, { extraParameters });154 });155 // assertShrinkProducesSameValueWithoutInitialContext is not applicable for base64String has some values will not shrink exactly the same way.156 // For instance: 'abcde' will be mapped to 'abcd', with default shrink it will try to shrink from 'abcde'. With context-less one it will start from 'abcd'.157 it.each`158 source | constraints159 ${'0123ABC==' /* invalid base 64 */} | ${{}}160 ${'AB==' /* not large enough */} | ${{ minLength: 5 }}161 ${'0123AB==' /* too large */} | ${{ maxLength: 7 }}162 `('should not be able to generate $source with fc.base64String($constraints)', ({ source, constraints }) => {163 // Arrange / Act164 const arb = base64String(constraints);165 const out = arb.canShrinkWithoutContext(source);166 // Assert167 expect(out).toBe(false);168 });169 it.each`170 rawValue171 ${'ABCD'}172 ${'0123AB=='}173 ${'01230123012301230123AB=='}174 ${'ABCD'.repeat(50)}175 `('should be able to shrink $rawValue', ({ rawValue }) => {176 // Arrange177 const arb = base64String();178 const value = new Value(rawValue, undefined);179 // Act180 const renderedTree = renderTree(buildShrinkTree(arb, value, { numItems: 100 })).join('\n');181 // Assert182 expect(arb.canShrinkWithoutContext(rawValue)).toBe(true);183 expect(renderedTree).toMatchSnapshot();184 });...

Full Screen

Full Screen

SizeHelpers.ts

Source:SizeHelpers.ts Github

copy

Full Screen

1import { assert } from 'console';2import fc from 'fast-check';3import {4 RelativeSize,5 Size,6 SizeForArbitrary,7} from '../../../../src/arbitrary/_internals/helpers/MaxLengthFromMinLength';8const allSizeOrdered = ['xsmall', 'small', 'medium', 'large', 'xlarge'] as const;9export const sizeArb = fc.constantFrom<Size>(...allSizeOrdered);10export const isSmallerSize = (sa: Size, sb: Size): boolean => allSizeOrdered.indexOf(sa) < allSizeOrdered.indexOf(sb);11const allRelativeSize = ['-4', '-3', '-2', '-1', '=', '+1', '+2', '+3', '+4'] as const;12export const relativeSizeArb = fc.constantFrom<RelativeSize>(...allRelativeSize);13const allSizeForArbitrary = [...allSizeOrdered, ...allRelativeSize, 'max'] as const; // WARNING: it does not include undefined14export const sizeForArbitraryArb = fc.constantFrom<SizeForArbitrary>(...allSizeForArbitrary);15export const sizeRelatedGlobalConfigArb = fc.record(16 { baseSize: sizeArb, defaultSizeToMaxWhenMaxSpecified: fc.boolean() },17 { requiredKeys: [] }18);19// Type check that helpers are covering all the possibilities20const failIfMissingSize: Size extends typeof allSizeOrdered[number] ? true : never = true;21const failIfMissingRelativeSize: RelativeSize extends typeof allRelativeSize[number] ? true : never = true;22const failIfMissingSizeForArbitrary: NonNullable<SizeForArbitrary> extends typeof allSizeForArbitrary[number]23 ? true24 : never = true;25assert(failIfMissingSize); // just not to appear unused26assert(failIfMissingRelativeSize); // just not to appear unused...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const SizeArbitrary = require("fast-check/lib/check/arbitrary/SizeArbitrary.js");3const sizeArb = new SizeArbitrary.SizeArbitrary();4const size = sizeArb.sizeForArbitraryArb(fc.integer());5const fc = require("fast-check");6const SizeArbitrary = require("fast-check/lib/check/arbitrary/SizeArbitrary.js");7const sizeArb = new SizeArbitrary.SizeArbitrary();8const size = sizeArb.sizeForArbitraryArb(fc.integer());9const fc = require("fast-check");10const SizeArbitrary = require("fast-check/lib/check/arbitrary/SizeArbitrary.js");11const sizeArb = new SizeArbitrary.SizeArbitrary();12const size = sizeArb.sizeForArbitraryArb(fc.integer());13const fc = require("fast-check");14const SizeArbitrary = require("fast-check/lib/check/arbitrary/SizeArbitrary.js");15const sizeArb = new SizeArbitrary.SizeArbitrary();16const size = sizeArb.sizeForArbitraryArb(fc.integer());17const fc = require("fast-check");18const SizeArbitrary = require("fast-check/lib/check/arbitrary/SizeArbitrary.js");19const sizeArb = new SizeArbitrary.SizeArbitrary();20const size = sizeArb.sizeForArbitraryArb(fc.integer());21const fc = require("fast-check");22const SizeArbitrary = require("fast-check/lib/check/arbitrary/SizeArbitrary.js");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { sizeForArbitraryArb } = require('fast-check');2const { array, oneof, string, number, constant } = require('fast-check');3const arb = oneof(4 array(string()),5 array(number()),6 array(oneof(string(), number())),7 array(oneof(constant('a'), constant('b'), constant('c'))),8 array(oneof(constant(1), constant(2), constant(3)))9);10const size = sizeForArbitraryArb(arb);11console.log(size);12const { sizeForArbitraryArb } = require('fast-check');13const { array, oneof, string, number, constant } = require('fast-check');14const arb = oneof(15 array(string()),16 array(number()),17 array(oneof(string(), number())),18 array(oneof(constant('a'), constant('b'), constant('c'))),19 array(oneof(constant(1), constant(2), constant(3)))20);21const size = sizeForArbitraryArb(arb);22console.log(size);23const { sizeForArbitraryArb } = require('fast-check');24const { array, oneof, string, number, constant } = require('fast-check');25const arb = oneof(26 array(string()),27 array(number()),28 array(oneof(string(), number())),29 array(oneof(constant('a'), constant('b'), constant('c'))),30 array(oneof(constant(1), constant(2), constant(3)))31);32const size = sizeForArbitraryArb(arb);33console.log(size);34const { sizeForArbitraryArb } = require('fast-check');35const { array, oneof, string, number, constant } = require('fast-check');36const arb = oneof(37 array(string()),38 array(number()),39 array(oneof(string(), number())),40 array(oneof(constant('a'), constant('b'), constant('c'))),41 array(oneof(constant(1), constant(2), constant(3)))42);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check')2const {sizeForArbitraryArb} = require('fast-check-monorepo')3const arb = fc.array(fc.integer());4const arb1 = sizeForArbitraryArb(arb, 20)5fc.assert(fc.property(arb1, a => a.length === 20))6const fc = require('fast-check')7const {sizeForArbitraryArb} = require('fast-check-monorepo')8const arb = fc.array(fc.integer());9const arb1 = sizeForArbitraryArb(arb, 20)10fc.assert(fc.property(arb1, a => a.length === 20))11const fc = require('fast-check')12const {sizeForArbitraryArb} = require('fast-check-monorepo')13const arb = fc.array(fc.integer());14const arb1 = sizeForArbitraryArb(arb, 20)15fc.assert(fc.property(arb1, a => a.length === 20))16const fc = require('fast-check')17const {sizeForArbitraryArb} = require('fast-check-monorepo')18const arb = fc.array(fc.integer());19const arb1 = sizeForArbitraryArb(arb, 20)20fc.assert(fc.property(arb1, a => a.length === 20))21const fc = require('fast-check')22const {sizeForArbitraryArb} = require('fast-check-monorepo')23const arb = fc.array(fc.integer());24const arb1 = sizeForArbitraryArb(arb, 20)25fc.assert(fc.property(arb1, a => a.length === 20))

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const size = 3;3const type = "number";4const array = fc.sizeForArbitraryArb(size, fc[type]());5console.log(array);6const fc = require("fast-check");7const size = 3;8const type = "string";9const array = fc.sizeForArbitraryArb(size, fc[type]());10console.log(array);11const fc = require("fast-check");12const size = 3;13const type = "boolean";14const array = fc.sizeForArbitraryArb(size, fc[type]());15console.log(array);16const fc = require("fast-check");17const size = 3;18const type = "date";19const array = fc.sizeForArbitraryArb(size, fc[type]());20console.log(array);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const sizeForArbitraryArb = require('fast-check/lib/arbitrary/_internals/SizeForArbitraryArb.js');3const sizeForArbitrary = sizeForArbitraryArb.default;4const sortedArb = sizeForArbitrary(fc.integer(), (size) => {5 return fc.array(fc.integer(), size, size);6}).map((array) => array.sort((a, b) => a - b));7fc.assert(8 fc.property(sortedArb, (array) => {9 for (let idx = 1; idx < array.length; ++idx) {10 if (array[idx - 1] > array[idx]) {11 return false;12 }13 }14 return true;15 })16);17const sortedArb = fc.array(fc.integer(), 10, 20).map((array) => array.sort((a, b) => a - b));18It is not a bug, it is a feature. In the second case, you are using the default export of the module, which is not exported by fast-check. So you need to use the default import syntax to import it:19import sizeForArbitraryArb from 'fast-check/lib/arbitrary/_internals/SizeForArbitraryArb.js';20import { sizeForArbitraryArb } from 'fast-check/lib/arbitrary/_internals/SizeForArbitraryArb.js';

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