How to use sizeRelatedGlobalConfigArb method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

uniqueArray.spec.ts

Source:uniqueArray.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { uniqueArray, UniqueArrayConstraints } from '../../../src/arbitrary/uniqueArray';3import { FakeIntegerArbitrary, fakeArbitrary } from './__test-helpers__/ArbitraryHelpers';4import * as ArrayArbitraryMock from '../../../src/arbitrary/_internals/ArrayArbitrary';5import {6 assertProduceCorrectValues,7 assertProduceSameValueGivenSameSeed,8 assertProduceValuesShrinkableWithoutContext,9 assertShrinkProducesSameValueWithoutInitialContext,10} from './__test-helpers__/ArbitraryAssertions';11import { Value } from '../../../src/check/arbitrary/definition/Value';12import { buildShrinkTree, renderTree } from './__test-helpers__/ShrinkTree';13import { sizeRelatedGlobalConfigArb } from './__test-helpers__/SizeHelpers';14import { withConfiguredGlobal } from './__test-helpers__/GlobalSettingsHelpers';15function beforeEachHook() {16 jest.resetModules();17 jest.restoreAllMocks();18 fc.configureGlobal({ beforeEach: beforeEachHook });19}20beforeEach(beforeEachHook);21describe('uniqueArray', () => {22 it('should instantiate ArrayArbitrary(arb, 0, ?, 0x7fffffff, n.a, <default>) for uniqueArray(arb)', () => {23 fc.assert(24 fc.property(sizeRelatedGlobalConfigArb, (config) => {25 // Arrange26 const { instance: childInstance } = fakeArbitrary<unknown>();27 const { instance } = fakeArbitrary<unknown[]>();28 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');29 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);30 // Act31 const arb = withConfiguredGlobal(config, () => uniqueArray(childInstance));32 // Assert33 expect(ArrayArbitrary).toHaveBeenCalledWith(34 childInstance,35 0,36 expect.any(Number),37 0x7fffffff,38 undefined,39 expect.any(Function),40 []41 );42 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail43 expect(receivedGeneratedMaxLength).toBeGreaterThan(0);44 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(2 ** 31 - 1);45 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);46 expect(arb).toBe(instance);47 })48 );49 });50 it('should instantiate ArrayArbitrary(arb, 0, ?, maxLength, n.a, <default>) for uniqueArray(set, {maxLength})', () => {51 fc.assert(52 fc.property(sizeRelatedGlobalConfigArb, fc.nat({ max: 2 ** 31 - 1 }), (config, maxLength) => {53 // Arrange54 const { instance: childInstance } = fakeArbitrary<unknown>();55 const { instance } = fakeArbitrary<unknown[]>();56 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');57 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);58 // Act59 const arb = withConfiguredGlobal(config, () => uniqueArray(childInstance, { maxLength }));60 // Assert61 expect(ArrayArbitrary).toHaveBeenCalledWith(62 childInstance,63 0,64 expect.any(Number),65 maxLength,66 undefined,67 expect.any(Function),68 []69 );70 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail71 expect(receivedGeneratedMaxLength).toBeGreaterThanOrEqual(0);72 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(maxLength);73 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);74 if (config.defaultSizeToMaxWhenMaxSpecified) {75 expect(ArrayArbitrary).toHaveBeenCalledWith(76 childInstance,77 0,78 maxLength,79 maxLength,80 undefined,81 expect.any(Function),82 []83 );84 }85 expect(arb).toBe(instance);86 })87 );88 });89 it('should instantiate ArrayArbitrary(arb, minLength, ?, 0x7fffffff, n.a, <default>) for uniqueArray(arb, {minLength})', () => {90 fc.assert(91 fc.property(sizeRelatedGlobalConfigArb, fc.nat({ max: 2 ** 31 - 1 }), (config, minLength) => {92 // Arrange93 const { instance: childInstance } = fakeArbitrary<unknown>();94 const { instance, filter } = fakeArbitrary<unknown[]>();95 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');96 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);97 filter.mockReturnValue(instance);98 // Act99 const arb = withConfiguredGlobal(config, () => uniqueArray(childInstance, { minLength }));100 // Assert101 expect(ArrayArbitrary).toHaveBeenCalledWith(102 childInstance,103 minLength,104 expect.any(Number),105 0x7fffffff,106 undefined,107 expect.any(Function),108 []109 );110 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail111 if (minLength !== 2 ** 31 - 1) {112 expect(receivedGeneratedMaxLength).toBeGreaterThan(minLength);113 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(2 ** 31 - 1);114 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);115 } else {116 expect(receivedGeneratedMaxLength).toEqual(minLength);117 }118 expect(arb).toBe(instance);119 })120 );121 });122 it('should instantiate ArrayArbitrary(arb, minLength, ?, maxLength, n.a, <default>) for uniqueArray(arb, {minLength,maxLength})', () => {123 fc.assert(124 fc.property(125 sizeRelatedGlobalConfigArb,126 fc.nat({ max: 2 ** 31 - 1 }),127 fc.nat({ max: 2 ** 31 - 1 }),128 (config, aLength, bLength) => {129 // Arrange130 const [minLength, maxLength] = aLength < bLength ? [aLength, bLength] : [bLength, aLength];131 const { instance: childInstance } = fakeArbitrary<unknown>();132 const { instance, filter } = fakeArbitrary<unknown[]>();133 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');134 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);135 filter.mockReturnValue(instance);136 // Act137 const arb = withConfiguredGlobal(config, () => uniqueArray(childInstance, { minLength, maxLength }));138 // Assert139 expect(ArrayArbitrary).toHaveBeenCalledWith(140 childInstance,141 minLength,142 expect.any(Number),143 maxLength,144 undefined,145 expect.any(Function),146 []147 );148 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail149 expect(receivedGeneratedMaxLength).toBeGreaterThanOrEqual(minLength);150 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(maxLength);151 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);152 if (config.defaultSizeToMaxWhenMaxSpecified) {153 expect(ArrayArbitrary).toHaveBeenCalledWith(154 childInstance,155 minLength,156 maxLength,157 maxLength,158 undefined,159 expect.any(Function),160 []161 );162 }163 expect(arb).toBe(instance);164 }165 )166 );167 });168 it('should accept custom comparator or selector or both at the same time or none', () => {169 fc.assert(170 fc.property(171 sizeRelatedGlobalConfigArb,172 fc173 .record(174 {175 minLength: fc.nat({ max: 2 ** 31 - 1 }),176 maxLength: fc.nat({ max: 2 ** 31 - 1 }),177 comparator: comparatorArbitrary(),178 selector: selectorArbitrary(),179 depthIdentifier: fc.string(),180 },181 { requiredKeys: [] }182 )183 .map((constraints) =>184 constraints.minLength !== undefined &&185 constraints.maxLength !== undefined &&186 constraints.minLength > constraints.maxLength187 ? ({188 ...constraints,189 minLength: constraints.maxLength,190 maxLength: constraints.minLength,191 } as UniqueArrayConstraints<unknown, unknown>)192 : ({ ...constraints } as UniqueArrayConstraints<unknown, unknown>)193 ),194 (config, constraints) => {195 // Arrange196 const { instance: childInstance } = fakeArbitrary<unknown>();197 const { instance, filter } = fakeArbitrary<unknown[]>();198 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');199 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);200 filter.mockReturnValue(instance);201 // Act202 const arb = withConfiguredGlobal(config, () => uniqueArray(childInstance, constraints));203 // Assert204 expect(ArrayArbitrary).toHaveBeenCalledWith(205 childInstance,206 constraints.minLength !== undefined ? constraints.minLength : expect.any(Number),207 expect.any(Number),208 constraints.maxLength !== undefined ? constraints.maxLength : expect.any(Number),209 constraints.depthIdentifier,210 expect.any(Function),211 []212 );213 expect(arb).toBe(instance);214 }215 )216 );217 });218 it('should throw when minimum length is greater than maximum one', () => {219 fc.assert(220 fc.property(221 sizeRelatedGlobalConfigArb,222 fc.nat({ max: 2 ** 31 - 1 }),223 fc.nat({ max: 2 ** 31 - 1 }),224 fc.option(comparatorArbitrary(), { nil: undefined }),225 fc.option(selectorArbitrary(), { nil: undefined }),226 (config, aLength, bLength, comparator, selector) => {227 // Arrange228 fc.pre(aLength !== bLength);229 const [minLength, maxLength] = aLength < bLength ? [bLength, aLength] : [aLength, bLength];230 const { instance: childInstance } = fakeArbitrary<unknown>();231 // Act / Assert232 expect(() =>233 withConfiguredGlobal(config, () =>234 uniqueArray(childInstance, { minLength, maxLength, comparator, selector })235 )236 ).toThrowError();237 }238 )239 );240 });241});242describe('uniqueArray (integration)', () => {243 type Extra = UniqueArrayConstraints<unknown, unknown>;244 const extraParameters: fc.Arbitrary<Extra> = fc245 .tuple(246 fc.nat({ max: 5 }),247 fc.nat({ max: 30 }),248 fc.boolean(),249 fc.boolean(),250 fc.option(fc.func(fc.integer()), { nil: undefined }),251 fc.option(comparatorArbitrary(), { nil: undefined })252 )253 .map(([min, gap, withMin, withMax, selector, comparator]) => {254 // We only apply selector/comparator in case the minimal number of items requested can be reached with the selector/comparator.255 // eg.: selector = v => 0, means that we will have at most 1 value in the array, never more, so it cannot be used with min > 1256 const requestedMin = withMin ? min : 0;257 let selectorEnabled = requestedMin === 0 || selector === undefined;258 let comparatorEnabled = requestedMin === 0 || comparator === undefined;259 const sampleSize = 50;260 const sampledSelectedValues = new Set<unknown>();261 const sampledSelectedAndComparedValues: unknown[] = [];262 const resolvedSelector = resolveSelectorFunction(selector);263 const resolvedComparator = resolveComparatorFunction(comparator);264 for (let v = 0; v !== sampleSize && (!selectorEnabled || !comparatorEnabled); ++v) {265 const selected = resolvedSelector(v); // either v (integer in 0..sampleSize) or an integer (by construct of selector)266 sampledSelectedValues.add(selected);267 selectorEnabled = selectorEnabled || sampledSelectedValues.size >= requestedMin;268 if (!comparatorEnabled && comparator !== undefined) {269 if (sampledSelectedAndComparedValues.every((p) => !resolvedComparator(p, selected))) {270 // Selected is "different" from all the other known values271 sampledSelectedAndComparedValues.push(selected);272 comparatorEnabled = comparatorEnabled || sampledSelectedAndComparedValues.length >= requestedMin;273 selectorEnabled = selectorEnabled || comparatorEnabled; // comparator enabled unlocks selector too274 }275 }276 }277 return {278 minLength: withMin ? min : undefined,279 maxLength: withMax ? min + gap : undefined,280 selector: selectorEnabled ? selector : undefined,281 comparator: comparatorEnabled ? comparator : undefined,282 };283 });284 const isCorrect = (value: number[], extra: Extra) => {285 if (extra.minLength !== undefined) {286 expect(value.length).toBeGreaterThanOrEqual(extra.minLength);287 }288 if (extra.maxLength !== undefined) {289 expect(value.length).toBeLessThanOrEqual(extra.maxLength);290 }291 for (const v of value) {292 expect(typeof v).toBe('number');293 }294 const resolvedSelector = resolveSelectorFunction(extra.selector);295 const resolvedComparator = resolveComparatorFunction(extra.comparator);296 const alreadySeen: unknown[] = [];297 for (const v of value) {298 const selected = resolvedSelector(v);299 const matchingEntry = alreadySeen.some((e) => resolvedComparator(e, selected));300 expect(matchingEntry).toBe(false);301 alreadySeen.push(selected);302 }303 };304 const integerUpTo10000AndNaNOrMinusZero = new FakeIntegerArbitrary(-2, 10000).map(305 (v) => (v === -2 ? Number.NaN : v === -1 ? -0 : v),306 (v) => {307 if (typeof v !== 'number' || v === -1 || v === -2) throw new Error('');308 return Object.is(v, Number.NaN) ? -2 : Object.is(v, -0) ? -1 : v;309 }310 );311 const uniqueArrayBuilder = (extra: Extra) => uniqueArray(integerUpTo10000AndNaNOrMinusZero, extra);312 it('should produce the same values given the same seed', () => {313 assertProduceSameValueGivenSameSeed(uniqueArrayBuilder, { extraParameters });314 });315 it('should only produce correct values', () => {316 assertProduceCorrectValues(uniqueArrayBuilder, isCorrect, { extraParameters });317 });318 it('should produce values seen as shrinkable without any context', () => {319 assertProduceValuesShrinkableWithoutContext(uniqueArrayBuilder, { extraParameters });320 });321 it('should be able to shrink to the same values without initial context', () => {322 assertShrinkProducesSameValueWithoutInitialContext(uniqueArrayBuilder, { extraParameters });323 });324 // Property: should preserve strictly smaller ordering in shrink325 // Is not applicable in the case of `set` as some values may not be in the "before" version326 // of the array while they can suddenly appear on shrink. They might have been hidden because327 // another value inside the array shadowed them. While on shrink those entries shadowing others328 // may have disappear.329 it.each`330 source | constraints331 ${[2, 4, 8] /* not large enough */} | ${{ minLength: 4 }}332 ${[2, 4, 8] /* too large */} | ${{ maxLength: 2 }}333 ${[2, 4, 8] /* not unique for selector */} | ${{ selector: (item: number) => Math.floor(item / 5) }}334 ${[2, 4, 8] /* not unique for comparator */} | ${{ comparator: (a: number, b: number) => Math.abs(a - b) <= 2 }}335 `('should not be able to generate $source with fc.uniqueArray(arb, $constraints)', ({ source, constraints }) => {336 // Arrange / Act337 const arb = uniqueArray(new FakeIntegerArbitrary(0, 1000), constraints);338 const out = arb.canShrinkWithoutContext(source);339 // Assert340 expect(out).toBe(false);341 });342 it.each`343 rawValue | constraints344 ${[2, 4, 8, 16, 32, 64]} | ${{}}345 ${[2, 4, 8]} | ${{}}346 ${[2, 4, 8]} | ${{ minLength: 2 }}347 ${[2, 4, 8]} | ${{ minLength: 3 }}348 ${[2, 8]} | ${{ selector: (item: number) => Math.floor(item / 5) }}349 ${[2, 8]} | ${{ comparator: (a: number, b: number) => Math.abs(a - b) <= 2 }}350 `('should be able to shrink $rawValue with fc.uniqueArray(arb, $constraints)', ({ rawValue, constraints }) => {351 // Arrange352 const arb = uniqueArray(new FakeIntegerArbitrary(0, 1000), constraints);353 const value = new Value(rawValue, undefined);354 // Act355 const renderedTree = renderTree(buildShrinkTree(arb, value, { numItems: 100 })).join('\n');356 // Assert357 expect(arb.canShrinkWithoutContext(rawValue)).toBe(true);358 expect(renderedTree).toMatchSnapshot();359 });360});361// Helpers362type ComparatorType<T = unknown, U = unknown> = UniqueArrayConstraints<T, U>['comparator'];363function comparatorArbitrary(): fc.Arbitrary<ComparatorType> {364 return fc.oneof(365 fc.constantFrom<ComparatorType>('IsStrictlyEqual', 'SameValue', 'SameValueZero'),366 fc.compareFunc().map((f) => (a: unknown, b: unknown) => f(a, b) === 0)367 );368}369function resolveComparatorFunction<T, U>(370 comparator: ComparatorType<T, U> | undefined371): (a: unknown, b: unknown) => boolean {372 if (comparator === undefined) {373 return (a, b) => Object.is(a, b);374 }375 if (typeof comparator === 'function') {376 return comparator as (a: unknown, b: unknown) => boolean;377 }378 switch (comparator) {379 case 'IsStrictlyEqual':380 return (a, b) => a === b;381 case 'SameValue':382 return (a, b) => Object.is(a, b);383 case 'SameValueZero':384 return (a, b) => (a === 0 && b === 0) || Object.is(a, b);385 }386}387type SelectorType<T = unknown, U = unknown> = UniqueArrayConstraints<T, U>['selector'];388function selectorArbitrary(): fc.Arbitrary<SelectorType> {389 return fc.func(fc.anything());390}391function resolveSelectorFunction<T, U>(selector: SelectorType<T, U> | undefined): (a: unknown) => unknown {392 if (selector === undefined) {393 return (a) => a;394 }395 return selector as (a: unknown) => unknown;...

Full Screen

Full Screen

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

array.spec.ts

Source:array.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { array } from '../../../src/arbitrary/array';3import { FakeIntegerArbitrary, fakeArbitrary } from './__test-helpers__/ArbitraryHelpers';4import * as ArrayArbitraryMock from '../../../src/arbitrary/_internals/ArrayArbitrary';5import {6 assertProduceCorrectValues,7 assertProduceSameValueGivenSameSeed,8 assertProduceValuesShrinkableWithoutContext,9 assertShrinkProducesSameValueWithoutInitialContext,10 assertShrinkProducesStrictlySmallerValue,11} from './__test-helpers__/ArbitraryAssertions';12import { isStrictlySmallerArray } from './__test-helpers__/ArrayHelpers';13import { Value } from '../../../src/check/arbitrary/definition/Value';14import { buildShrinkTree, renderTree } from './__test-helpers__/ShrinkTree';15import { sizeRelatedGlobalConfigArb } from './__test-helpers__/SizeHelpers';16import { withConfiguredGlobal } from './__test-helpers__/GlobalSettingsHelpers';17function beforeEachHook() {18 jest.resetModules();19 jest.restoreAllMocks();20 fc.configureGlobal({ beforeEach: beforeEachHook });21}22beforeEach(beforeEachHook);23describe('array', () => {24 it('should instantiate ArrayArbitrary(arb, 0, ?, 0x7fffffff, n.a) for array(arb)', () => {25 fc.assert(26 fc.property(sizeRelatedGlobalConfigArb, (config) => {27 // Arrange28 const { instance: childInstance } = fakeArbitrary<unknown>();29 const { instance } = fakeArbitrary<unknown[]>();30 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');31 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);32 // Act33 const arb = withConfiguredGlobal(config, () => array(childInstance));34 // Assert35 expect(ArrayArbitrary).toHaveBeenCalledWith(36 childInstance,37 0,38 expect.any(Number),39 0x7fffffff,40 undefined,41 undefined,42 []43 );44 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail45 expect(receivedGeneratedMaxLength).toBeGreaterThan(0);46 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(2 ** 31 - 1);47 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);48 expect(arb).toBe(instance);49 })50 );51 });52 it('should instantiate ArrayArbitrary(arb, 0, ?, maxLength, n.a) for array(arb, {maxLength})', () => {53 fc.assert(54 fc.property(sizeRelatedGlobalConfigArb, fc.nat({ max: 2 ** 31 - 1 }), (config, maxLength) => {55 // Arrange56 const { instance: childInstance } = fakeArbitrary<unknown>();57 const { instance } = fakeArbitrary<unknown[]>();58 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');59 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);60 // Act61 const arb = withConfiguredGlobal(config, () => array(childInstance, { maxLength }));62 // Assert63 expect(ArrayArbitrary).toHaveBeenCalledWith(64 childInstance,65 0,66 expect.any(Number),67 maxLength,68 undefined,69 undefined,70 []71 );72 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail73 expect(receivedGeneratedMaxLength).toBeGreaterThanOrEqual(0);74 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(maxLength);75 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);76 if (config.defaultSizeToMaxWhenMaxSpecified) {77 expect(ArrayArbitrary).toHaveBeenCalledWith(childInstance, 0, maxLength, maxLength, undefined, undefined, []);78 }79 expect(arb).toBe(instance);80 })81 );82 });83 it('should instantiate ArrayArbitrary(arb, minLength, ?, 0x7fffffff, n.a) for array(arb, {minLength})', () => {84 fc.assert(85 fc.property(sizeRelatedGlobalConfigArb, fc.nat({ max: 2 ** 31 - 1 }), (config, minLength) => {86 // Arrange87 const { instance: childInstance } = fakeArbitrary<unknown>();88 const { instance } = fakeArbitrary<unknown[]>();89 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');90 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);91 // Act92 const arb = withConfiguredGlobal(config, () => array(childInstance, { minLength }));93 // Assert94 expect(ArrayArbitrary).toHaveBeenCalledWith(95 childInstance,96 minLength,97 expect.any(Number),98 0x7fffffff,99 undefined,100 undefined,101 []102 );103 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail104 if (minLength !== 2 ** 31 - 1) {105 expect(receivedGeneratedMaxLength).toBeGreaterThan(minLength);106 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(2 ** 31 - 1);107 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);108 } else {109 expect(receivedGeneratedMaxLength).toEqual(minLength);110 }111 expect(arb).toBe(instance);112 })113 );114 });115 it('should instantiate ArrayArbitrary(arb, minLength, ?, maxLength, n.a) for array(arb, {minLength,maxLength})', () => {116 fc.assert(117 fc.property(118 sizeRelatedGlobalConfigArb,119 fc.nat({ max: 2 ** 31 - 1 }),120 fc.nat({ max: 2 ** 31 - 1 }),121 (config, aLength, bLength) => {122 // Arrange123 const [minLength, maxLength] = aLength < bLength ? [aLength, bLength] : [bLength, aLength];124 const { instance: childInstance } = fakeArbitrary<unknown>();125 const { instance } = fakeArbitrary<unknown[]>();126 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');127 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);128 // Act129 const arb = withConfiguredGlobal(config, () => array(childInstance, { minLength, maxLength }));130 // Assert131 expect(ArrayArbitrary).toHaveBeenCalledWith(132 childInstance,133 minLength,134 expect.any(Number),135 maxLength,136 undefined,137 undefined,138 []139 );140 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail141 expect(receivedGeneratedMaxLength).toBeGreaterThanOrEqual(minLength);142 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(maxLength);143 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);144 if (config.defaultSizeToMaxWhenMaxSpecified) {145 expect(ArrayArbitrary).toHaveBeenCalledWith(146 childInstance,147 minLength,148 maxLength,149 maxLength,150 undefined,151 undefined,152 []153 );154 }155 expect(arb).toBe(instance);156 }157 )158 );159 });160 it('should instantiate ArrayArbitrary(arb, minLength, ?, maxLength, identifier) for array(arb, {minLength,maxLength, depthIdentifier})', () => {161 fc.assert(162 fc.property(163 sizeRelatedGlobalConfigArb,164 fc.nat({ max: 2 ** 31 - 1 }),165 fc.nat({ max: 2 ** 31 - 1 }),166 fc.string(),167 (config, aLength, bLength, depthIdentifier) => {168 // Arrange169 const [minLength, maxLength] = aLength < bLength ? [aLength, bLength] : [bLength, aLength];170 const { instance: childInstance } = fakeArbitrary<unknown>();171 const { instance } = fakeArbitrary<unknown[]>();172 const ArrayArbitrary = jest.spyOn(ArrayArbitraryMock, 'ArrayArbitrary');173 ArrayArbitrary.mockImplementation(() => instance as ArrayArbitraryMock.ArrayArbitrary<unknown>);174 // Act175 const arb = withConfiguredGlobal(config, () =>176 array(childInstance, { minLength, maxLength, depthIdentifier })177 );178 // Assert179 expect(ArrayArbitrary).toHaveBeenCalledWith(180 childInstance,181 minLength,182 expect.any(Number),183 maxLength,184 depthIdentifier,185 undefined,186 []187 );188 const receivedGeneratedMaxLength = ArrayArbitrary.mock.calls[0][2]; // Expecting the real value would check an implementation detail189 expect(receivedGeneratedMaxLength).toBeGreaterThanOrEqual(minLength);190 expect(receivedGeneratedMaxLength).toBeLessThanOrEqual(maxLength);191 expect(Number.isInteger(receivedGeneratedMaxLength)).toBe(true);192 if (config.defaultSizeToMaxWhenMaxSpecified) {193 expect(ArrayArbitrary).toHaveBeenCalledWith(194 childInstance,195 minLength,196 maxLength,197 maxLength,198 depthIdentifier,199 undefined,200 []201 );202 }203 expect(arb).toBe(instance);204 }205 )206 );207 });208 it('should throw when minimum length is greater than maximum one', () => {209 fc.assert(210 fc.property(211 sizeRelatedGlobalConfigArb,212 fc.nat({ max: 2 ** 31 - 1 }),213 fc.nat({ max: 2 ** 31 - 1 }),214 (config, aLength, bLength) => {215 // Arrange216 fc.pre(aLength !== bLength);217 const [minLength, maxLength] = aLength < bLength ? [bLength, aLength] : [aLength, bLength];218 const { instance: childInstance } = fakeArbitrary<unknown>();219 // Act / Assert220 expect(() =>221 withConfiguredGlobal(config, () => array(childInstance, { minLength, maxLength }))222 ).toThrowError();223 }224 )225 );226 });227});228describe('array (integration)', () => {229 type Extra = { minLength?: number; maxLength?: number };230 const extraParameters: fc.Arbitrary<Extra> = fc231 .tuple(fc.nat({ max: 5 }), fc.nat({ max: 30 }), fc.boolean(), fc.boolean())232 .map(([min, gap, withMin, withMax]) => ({233 minLength: withMin ? min : undefined,234 maxLength: withMax ? min + gap : undefined,235 }));236 const isCorrect = (value: number[], extra: Extra) => {237 if (extra.minLength !== undefined) {238 expect(value.length).toBeGreaterThanOrEqual(extra.minLength);239 }240 if (extra.maxLength !== undefined) {241 expect(value.length).toBeLessThanOrEqual(extra.maxLength);242 }243 for (const v of value) {244 expect(typeof v).toBe('number');245 }246 };247 const isStrictlySmaller = isStrictlySmallerArray;248 const arrayBuilder = (extra: Extra) => array(new FakeIntegerArbitrary(), extra);249 it('should produce the same values given the same seed', () => {250 assertProduceSameValueGivenSameSeed(arrayBuilder, { extraParameters });251 });252 it('should only produce correct values', () => {253 assertProduceCorrectValues(arrayBuilder, isCorrect, { extraParameters });254 });255 it('should produce values seen as shrinkable without any context', () => {256 assertProduceValuesShrinkableWithoutContext(arrayBuilder, { extraParameters });257 });258 it('should be able to shrink to the same values without initial context', () => {259 assertShrinkProducesSameValueWithoutInitialContext(arrayBuilder, { extraParameters });260 });261 it('should preserve strictly smaller ordering in shrink', () => {262 assertShrinkProducesStrictlySmallerValue(arrayBuilder, isStrictlySmaller, { extraParameters });263 });264 it.each`265 rawValue | minLength266 ${[2, 4, 8, 16, 32, 64]} | ${undefined}267 ${[2, 4, 8]} | ${undefined}268 ${[2, 4, 8]} | ${2}269 ${[2, 4, 8]} | ${3}270 `('should be able to shrink $rawValue given constraints minLength:$minLength', ({ rawValue, minLength }) => {271 // Arrange272 const constraints = { minLength };273 const arb = array(new FakeIntegerArbitrary(0, 1000), constraints);274 const value = new Value(rawValue, undefined);275 // Act276 const renderedTree = renderTree(buildShrinkTree(arb, value, { numItems: 100 })).join('\n');277 // Assert278 expect(arb.canShrinkWithoutContext(rawValue)).toBe(true);279 expect(renderedTree).toMatchSnapshot();280 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { sizeRelatedGlobalConfigArb } = require('fast-check');3fc.assert(4 fc.property(5 sizeRelatedGlobalConfigArb(),6 (config) => {7 console.log(config);8 return true;9 }10);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const sizeRelatedGlobalConfigArb = require("fast-check-monorepo").sizeRelatedGlobalConfigArb;3const config = fc.sample(fc.integer(), sizeRelatedGlobalConfigArb);4console.log(config);5const fc = require("fast-check");6const sizeRelatedGlobalConfigArb = require("fast-check-monorepo").sizeRelatedGlobalConfigArb;7const config = fc.sample(fc.integer(), sizeRelatedGlobalConfigArb);8console.log(config);9const fc = require("fast-check");10const sizeRelatedGlobalConfigArb = require("fast-check-monorepo").sizeRelatedGlobalConfigArb;11const config = fc.sample(fc.integer(), sizeRelatedGlobalConfigArb);12console.log(config);13const fc = require("fast-check");14const sizeRelatedGlobalConfigArb = require("fast-check-monorepo").sizeRelatedGlobalConfigArb;15const config = fc.sample(fc.integer(), sizeRelatedGlobalConfigArb);16console.log(config);17const fc = require("fast-check");18const sizeRelatedGlobalConfigArb = require("fast-check-monorepo").sizeRelatedGlobalConfigArb;19const config = fc.sample(fc.integer(), sizeRelatedGlobalConfigArb);20console.log(config);21const fc = require("fast-check");22const sizeRelatedGlobalConfigArb = require("

Full Screen

Using AI Code Generation

copy

Full Screen

1const {sizeRelatedGlobalConfigArb} = require('fast-check');2const globalConfig = sizeRelatedGlobalConfigArb().generate();3console.log(globalConfig);4const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');5const globalConfig = sizeRelatedGlobalConfigArb().generate();6console.log(globalConfig);7const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');8const globalConfig = sizeRelatedGlobalConfigArb().generate();9console.log(globalConfig);10const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');11const globalConfig = sizeRelatedGlobalConfigArb().generate();12console.log(globalConfig);13const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');14const globalConfig = sizeRelatedGlobalConfigArb().generate();15console.log(globalConfig);16const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');17const globalConfig = sizeRelatedGlobalConfigArb().generate();18console.log(globalConfig);19const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');20const globalConfig = sizeRelatedGlobalConfigArb().generate();21console.log(globalConfig);22const {sizeRelatedGlobalConfigArb} = require('fast-check-monorepo');23const globalConfig = sizeRelatedGlobalConfigArb().generate();24console.log(globalConfig);25const {sizeRelatedGlobalConfigArb} = require('fast

Full Screen

Using AI Code Generation

copy

Full Screen

1import { sizeRelatedGlobalConfigArb } from 'fast-check-monorepo';2import { integer } from 'fast-check';3const sizeArb = integer(0, 100);4const configArb = sizeRelatedGlobalConfigArb(sizeArb);5const result = configArb.generate(mrng);6console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check-monorepo");2const sizeRelatedGlobalConfigArb = fc.sizeRelatedGlobalConfigArb;3const arb = sizeRelatedGlobalConfigArb();4fc.assert(5 fc.property(arb, (config) => {6 console.log("config: ", config);7 return true;8 })9);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { sizeRelatedGlobalConfigArb } = require('fast-check-monorepo');2const config = sizeRelatedGlobalConfigArb(3).generate();3console.log(config);4console.log(config.size);5console.log(config.maxDepth);6console.log(config.maxNumElements);7console.log(config.maxNumElements);8const { sizeRelatedGlobalConfigArb } = require('fast-check-monorepo');9const config = sizeRelatedGlobalConfigArb(5).generate();10console.log(config);11console.log(config.size);12console.log(config.maxDepth);13console.log(config.maxNumElements);14console.log(config.maxNumElements);15const { sizeRelatedGlobalConfigArb } = require('fast-check-monorepo');16const config = sizeRelatedGlobalConfigArb(7).generate();17console.log(config);18console.log(config.size);19console.log(config.maxDepth);20console.log(config.maxNumElements);21console.log(config.maxNumElements);22const { sizeRelatedGlobalConfigArb } = require('fast-check-monorepo');23const config = sizeRelatedGlobalConfigArb(9).generate();24console.log(config);25console.log(config.size);26console.log(config.maxDepth);27console.log(config.maxNumElements);28console.log(config.maxNumElements);

Full Screen

Using AI Code Generation

copy

Full Screen

1const {sizeRelatedGlobalConfigArb} = require("fast-check-monorepo");2const fc = require("fast-check");3const {pathExistsSync} = require("fs-extra");4const {createGlobalConfig} = require("@jest/types");5const {tmpdir} = require("os");6const {join} = require("path");7const {writeFile} = require("fs/promises");8const tempDir = tmpdir();9const tempFile = join(tempDir, "temp.json");10describe("global config", () => {11 it("global config should be generated", async () => {12 const globalConfig = await fc.assert(13 fc.property(sizeRelatedGlobalConfigArb(), async (gConfig) => {14 const globalConfig = createGlobalConfig(gConfig);15 await writeFile(tempFile, JSON.stringify(globalConfig));16 expect(pathExistsSync(tempFile)).toBe(true);17 })18 );19 });20});21I also tried to use the latest version of fast-check-monorepo (1.1.0) but it fails with the error:22I have also tried to use the latest version of fast-check-monorepo (1.1.0) but it fails with the error:

Full Screen

Using AI Code Generation

copy

Full Screen

1const sizeRelatedGlobalConfigArb = require('./sizeRelatedGlobalConfigArb');2const fc = require('fast-check');3const sizeRelatedGlobalConfigArbGen = sizeRelatedGlobalConfigArb();4fc.assert(5 fc.property(sizeRelatedGlobalConfigArbGen, (config) => {6 console.log('config', config);7 return true;8 })9);10const fc = require('fast-check');11const sizeRelatedGlobalConfigArb = () => {12 .tuple(13 fc.boolean(),14 fc.boolean(),15 fc.boolean(),

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const path = require("path");3const test1 = require("./test1.js");4const sizeRelatedGlobalConfigArb = test1.sizeRelatedGlobalConfigArb;5const globalConfigArb = sizeRelatedGlobalConfigArb(6 path.join(__dirname, "test3.js")7);8fc.assert(9 fc.property(globalConfigArb, (globalConfig) => {10 return globalConfig.maxWorkers === 5;11 })12);13const fc = require("fast-check");14const path = require("path");15const test1 = require("./test1.js");16const sizeRelatedGlobalConfigArb = test1.sizeRelatedGlobalConfigArb;17const globalConfigArb = sizeRelatedGlobalConfigArb(18 path.join(__dirname, "test4.js")19);20fc.assert(21 fc.property(globalConfigArb, (globalConfig) => {22 return globalConfig.maxWorkers === 10;23 })24);25const fc = require("fast-check");26const path = require("path");27const test1 = require("./test1.js");28const sizeRelatedGlobalConfigArb = test1.sizeRelatedGlobalConfigArb;29const globalConfigArb = sizeRelatedGlobalConfigArb(30 path.join(__dirname, "test5.js")31);32fc.assert(33 fc.property(globalConfigArb, (globalConfig) => {34 return globalConfig.maxWorkers === 10;35 })36);37const fc = require("fast-check");38const path = require("path");39const test1 = require("./test1.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