How to use expectedShrinks method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

BigIntArbitrary.spec.ts

Source:BigIntArbitrary.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { BigIntArbitrary } from '../../../../src/arbitrary/_internals/BigIntArbitrary';3import { Value } from '../../../../src/check/arbitrary/definition/Value';4import { fakeRandom } from '../__test-helpers__/RandomHelpers';5import {6 assertProduceValuesShrinkableWithoutContext,7 assertProduceCorrectValues,8 assertShrinkProducesSameValueWithoutInitialContext,9 assertShrinkProducesStrictlySmallerValue,10 assertProduceSameValueGivenSameSeed,11} from '../__test-helpers__/ArbitraryAssertions';12import { buildShrinkTree, renderTree, walkTree } from '../__test-helpers__/ShrinkTree';13import { Stream } from '../../../../src/stream/Stream';14import * as BiasNumericRangeMock from '../../../../src/arbitrary/_internals/helpers/BiasNumericRange';15import * as ShrinkBigIntMock from '../../../../src/arbitrary/_internals/helpers/ShrinkBigInt';16function beforeEachHook() {17 jest.resetModules();18 jest.restoreAllMocks();19 fc.configureGlobal({ beforeEach: beforeEachHook });20}21beforeEach(beforeEachHook);22describe('BigIntArbitrary', () => {23 if (typeof BigInt === 'undefined') {24 it('no test', () => {25 expect(true).toBe(true);26 });27 return;28 }29 describe('generate', () => {30 it('should never bias and generate the full range when biasFactor is not specified', () =>31 fc.assert(32 fc.property(fc.bigInt(), fc.bigInt(), fc.bigInt(), (a, b, c) => {33 // Arrange34 const [min, mid, max] = [a, b, c].sort((v1, v2) => Number(v1 - v2));35 const { instance: mrng, nextBigInt } = fakeRandom();36 nextBigInt.mockReturnValueOnce(mid);37 // Act38 const arb = new BigIntArbitrary(min, max);39 const out = arb.generate(mrng, undefined);40 // Assert41 expect(out.value).toBe(mid);42 expect(nextBigInt).toHaveBeenCalledTimes(1);43 expect(nextBigInt).toHaveBeenCalledWith(min, max);44 })45 ));46 it('should not always bias values (expect 1 times over biasFreq) and still generate full range when unbiased', () =>47 fc.assert(48 fc.property(fc.bigInt(), fc.bigInt(), fc.bigInt(), fc.maxSafeInteger(), (a, b, c, biasFactor) => {49 // Arrange50 const [min, mid, max] = [a, b, c].sort((v1, v2) => Number(v1 - v2));51 const { instance: mrng, nextInt, nextBigInt } = fakeRandom();52 nextInt.mockReturnValueOnce(2); // 1 means bias, all others are unbiased53 nextBigInt.mockReturnValueOnce(mid);54 // Act55 const arb = new BigIntArbitrary(min, max);56 const out = arb.generate(mrng, biasFactor);57 // Assert58 expect(out.value).toBe(mid);59 expect(nextInt).toHaveBeenCalledTimes(1);60 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);61 expect(nextBigInt).toHaveBeenCalledTimes(1);62 expect(nextBigInt).toHaveBeenCalledWith(min, max);63 })64 ));65 it('should bias values (1 times over biasFreq) by using one of the ranges from biasNumericRange', () =>66 fc.assert(67 fc.property(68 fc.bigInt(),69 fc.bigInt(),70 fc.bigInt(),71 fc.maxSafeInteger(),72 fc.maxSafeInteger(),73 // Remark:74 // Following biasNumericRange is not fully identical to the onces that would be provided.75 // Range (in this stub) can be larger than the requested one. Not impacting from a unit-test point of view.76 fc.array(77 fc.tuple(fc.bigInt(), fc.bigInt()).map(([a, b]) => (a < b ? { min: a, max: b } : { min: b, max: a })),78 { minLength: 1 }79 ),80 (a, b, c, biasFactor, mod, ranges) => {81 // Arrange82 const [min, mid, max] = [a, b, c].sort((v1, v2) => Number(v1 - v2));83 const { instance: mrng, nextInt, nextBigInt } = fakeRandom();84 nextInt.mockReturnValueOnce(1); // 1 means bias85 if (ranges.length !== 1) {86 nextInt.mockImplementationOnce((min, max) => min + (mod % (max - min + 1)));87 }88 nextBigInt.mockReturnValueOnce(mid); // Remark: this value will most of the time be outside of requested range89 const biasNumericRange = jest.spyOn(90 BiasNumericRangeMock,91 'biasNumericRange'92 ) as unknown as jest.SpyInstance<{ min: bigint; max: bigint }[], [bigint, bigint, () => bigint]>;93 biasNumericRange.mockReturnValueOnce(ranges);94 // Act95 const arb = new BigIntArbitrary(min, max);96 const out = arb.generate(mrng, biasFactor);97 // Assert98 expect(out.value).toBe(mid);99 expect(biasNumericRange).toHaveBeenCalledTimes(1);100 expect(biasNumericRange).toHaveBeenCalledWith(min, max, expect.any(Function));101 if (ranges.length === 1) {102 expect(nextInt).toHaveBeenCalledTimes(1);103 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);104 expect(nextBigInt).toHaveBeenCalledTimes(1);105 expect(nextBigInt).toHaveBeenCalledWith(ranges[0].min, ranges[0].max);106 } else {107 expect(nextInt).toHaveBeenCalledTimes(2);108 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);109 const secondNextIntParams = nextInt.mock.calls[1];110 expect(secondNextIntParams[0]).toBeLessThan(0); // arbitrary is supposed to prefer the first entry111 expect(secondNextIntParams[1]).toBe(ranges.length - 2); // other entries do not have any special treatments112 // negative values for [0], positive value n means ranges[n+1]113 const secondNextIntResult = nextInt.mock.results[1].value;114 const selectedRange = secondNextIntResult < 0 ? 0 : secondNextIntResult + 1;115 expect(nextBigInt).toHaveBeenCalledWith(ranges[selectedRange].min, ranges[selectedRange].max);116 }117 }118 )119 ));120 });121 describe('canShrinkWithoutContext', () => {122 it('should always tells it can generate values included in the requested range', () =>123 fc.assert(124 fc.property(fc.bigInt(), fc.bigInt(), fc.bigInt(), (a, b, c) => {125 // Arrange126 const [min, mid, max] = [a, b, c].sort((v1, v2) => Number(v1 - v2));127 // Act128 const arb = new BigIntArbitrary(min, max);129 const out = arb.canShrinkWithoutContext(mid);130 // Assert131 expect(out).toBe(true);132 })133 ));134 it('should always reject values outside of the requested range', () =>135 fc.assert(136 fc.property(137 fc.bigInt(),138 fc.bigInt(),139 fc.bigInt(),140 fc.constantFrom(...(['lower', 'higher'] as const)),141 (a, b, c, position) => {142 // Arrange143 const s = [a, b, c].sort((v1, v2) => Number(v1 - v2));144 const [min, max, requested] = position === 'lower' ? [s[1], s[2], s[0]] : [s[0], s[1], s[2]];145 fc.pre(requested !== min && requested !== max);146 // Act147 const arb = new BigIntArbitrary(min, max);148 const out = arb.canShrinkWithoutContext(requested);149 // Assert150 expect(out).toBe(false);151 }152 )153 ));154 it.each`155 requested156 ${'1'}157 ${1}158 ${'1n'}159 ${1.5}160 ${-0}161 ${Number.NaN}162 ${''}163 ${{}}164 `('should always reject non bigint values like $requested', ({ requested }) => {165 // Arrange166 const min = BigInt(0);167 const max = BigInt(100);168 // Act169 const arb = new BigIntArbitrary(min, max);170 const out = arb.canShrinkWithoutContext(requested);171 // Assert172 expect(out).toBe(false);173 });174 });175 describe('shrink', () => {176 it('should always call shrink helper when no context provided', () =>177 fc.assert(178 fc.property(fc.bigInt(), fc.bigInt(), fc.bigInt(), (a, b, c) => {179 // Arrange180 const [min, mid, max] = [a, b, c].sort((v1, v2) => Number(v1 - v2));181 const expectedShrinks = Stream.nil<Value<bigint>>();182 const shrinkBigInt = jest.spyOn(ShrinkBigIntMock, 'shrinkBigInt');183 shrinkBigInt.mockReturnValueOnce(expectedShrinks);184 // Act185 const arb = new BigIntArbitrary(min, max);186 const shrinks = arb.shrink(mid, undefined);187 // Assert188 expect(shrinks).toBe(expectedShrinks);189 expect(shrinkBigInt).toHaveBeenCalledTimes(1);190 expect(shrinkBigInt).toHaveBeenCalledWith(mid, expect.any(BigInt), true);191 })192 ));193 });194});195describe('BigIntArbitrary (integration)', () => {196 if (typeof BigInt === 'undefined') {197 it('no test', () => {198 expect(true).toBe(true);199 });200 return;201 }202 type Extra = { min: bigint; max: bigint };203 const extraParameters: fc.Arbitrary<Extra> = fc204 .tuple(fc.bigInt(), fc.bigInt())205 .map(([a, b]) => (a < b ? { min: a, max: b } : { min: b, max: a }));206 const isCorrect = (value: bigint, extra: Extra) =>207 typeof value === 'bigint' && extra.min <= value && value <= extra.max;208 const isStrictlySmaller = (v1: bigint, v2: bigint) => {209 const absV1 = v1 < BigInt(0) ? -v1 : v1;210 const absV2 = v2 < BigInt(0) ? -v2 : v2;211 return absV1 < absV2;212 };213 const bigIntBuilder = (extra: Extra) => new BigIntArbitrary(extra.min, extra.max);214 it('should produce the same values given the same seed', () => {215 assertProduceSameValueGivenSameSeed(bigIntBuilder, { extraParameters });216 });217 it('should only produce correct values', () => {218 assertProduceCorrectValues(bigIntBuilder, isCorrect, { extraParameters });219 });220 it('should produce values seen as shrinkable without any context', () => {221 assertProduceValuesShrinkableWithoutContext(bigIntBuilder, { extraParameters });222 });223 it('should be able to shrink to the same values without initial context', () => {224 assertShrinkProducesSameValueWithoutInitialContext(bigIntBuilder, { extraParameters });225 });226 it('should shrink towards strictly smaller values', () => {227 assertShrinkProducesStrictlySmallerValue(bigIntBuilder, isStrictlySmaller, { extraParameters });228 });229 describe('shrink', () => {230 it('should build a mirrored version of the shrinking tree if we negate all the values', () =>231 fc.assert(232 fc.property(233 fc.bigInt(),234 fc.bigUint({ max: BigInt(20) }), // larger trees might be too wide235 fc.bigUint({ max: BigInt(20) }),236 (start, o1, o2) => {237 // Arrange238 const min = start;239 const [mid, max] = o1 < o2 ? [min + o1, min + o2] : [min + o2, min + o1];240 const arb = new BigIntArbitrary(min, max);241 const arbNegate = new BigIntArbitrary(-max, -min);242 // Act243 const source = new Value(mid, undefined);244 const sourceNegate = new Value(-mid, undefined);245 const tree = buildShrinkTree(arb, source);246 const treeNegate = buildShrinkTree(arbNegate, sourceNegate);247 const flat: bigint[] = [];248 const flatNegate: bigint[] = [];249 walkTree(tree, (v) => flat.push(v));250 walkTree(treeNegate, (v) => flatNegate.push(-v));251 // Assert252 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);253 expect(arbNegate.canShrinkWithoutContext(sourceNegate.value)).toBe(true);254 expect(flatNegate).toEqual(flat);255 }256 )257 ));258 it('should build an offset version of the shrinking tree if we offset all the values (keep every value >=0)', () =>259 fc.assert(260 fc.property(261 fc.bigUint(),262 fc.bigUint({ max: BigInt(20) }), // larger trees might be too wide263 fc.bigUint({ max: BigInt(20) }),264 fc.bigUint(),265 (start, o1, o2, offset) => {266 // Arrange267 fc.pre(start + o1 + offset <= Number.MAX_SAFE_INTEGER);268 fc.pre(start + o2 + offset <= Number.MAX_SAFE_INTEGER);269 const min = start;270 const [mid, max] = o1 < o2 ? [min + o1, min + o2] : [min + o2, min + o1];271 const arb = new BigIntArbitrary(min, max);272 const arbOffset = new BigIntArbitrary(min + offset, max + offset);273 // Act274 const source = new Value(mid, undefined);275 const sourceOffset = new Value(mid + offset, undefined);276 const tree = buildShrinkTree(arb, source);277 const treeOffset = buildShrinkTree(arbOffset, sourceOffset);278 const flat: bigint[] = [];279 const flatOffset: bigint[] = [];280 walkTree(tree, (v) => flat.push(v));281 walkTree(treeOffset, (v) => flatOffset.push(v - offset));282 // Assert283 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);284 expect(arbOffset.canShrinkWithoutContext(sourceOffset.value)).toBe(true);285 expect(flatOffset).toEqual(flat);286 }287 )288 ));289 it('should shrink strictly positive value for positive range including zero', () => {290 // Arrange291 const arb = new BigIntArbitrary(BigInt(0), BigInt(10));292 const source = new Value(BigInt(8), undefined);293 // Act294 const tree = buildShrinkTree(arb, source);295 const renderedTree = renderTree(tree).join('\n');296 // Assert297 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);298 // When there is no more option, the shrinker retry one time with the value299 // current-1 to check if something that changed outside (another value not itself)300 // may have changed the situation.301 expect(renderedTree).toMatchInlineSnapshot(`302 "8n303 ├> 0n304 ├> 4n305 | ├> 2n306 | | └> 1n307 | | └> 0n308 | └> 3n309 | └> 2n310 | ├> 0n311 | └> 1n312 | └> 0n313 ├> 6n314 | └> 5n315 | └> 4n316 | ├> 0n317 | ├> 2n318 | | └> 1n319 | | └> 0n320 | └> 3n321 | └> 2n322 | ├> 0n323 | └> 1n324 | └> 0n325 └> 7n326 └> 6n327 ├> 0n328 ├> 3n329 | └> 2n330 | └> 1n331 | └> 0n332 └> 5n333 └> 4n334 └> 3n335 ├> 0n336 └> 2n337 └> 1n338 └> 0n"339 `);340 // Remarks:341 // * When we shrink 5 in path 8 > 6 > 5342 // we already now that 4 passed so we now that the smallest failing case343 // to look for is >= 5344 // * Same thing when we shrink 6 in path 8 > 6345 // * When we shrink 7 in path 8 > 7346 // we already now that 6 passed so we now that the smallest failing case347 // to look for is >= 7348 });349 it('should shrink strictly positive value for range not including zero', () => {350 // Arrange351 const arb = new BigIntArbitrary(BigInt(10), BigInt(20));352 const source = new Value(BigInt(18), undefined);353 // Act354 const tree = buildShrinkTree(arb, source);355 const renderedTree = renderTree(tree).join('\n');356 // Assert357 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);358 // As the range [10, 20] and the value 18359 // are just offset by +10 compared to the first case,360 // the rendered tree will be offset by 10 too361 expect(renderedTree).toMatchInlineSnapshot(`362 "18n363 ├> 10n364 ├> 14n365 | ├> 12n366 | | └> 11n367 | | └> 10n368 | └> 13n369 | └> 12n370 | ├> 10n371 | └> 11n372 | └> 10n373 ├> 16n374 | └> 15n375 | └> 14n376 | ├> 10n377 | ├> 12n378 | | └> 11n379 | | └> 10n380 | └> 13n381 | └> 12n382 | ├> 10n383 | └> 11n384 | └> 10n385 └> 17n386 └> 16n387 ├> 10n388 ├> 13n389 | └> 12n390 | └> 11n391 | └> 10n392 └> 15n393 └> 14n394 └> 13n395 ├> 10n396 └> 12n397 └> 11n398 └> 10n"399 `);400 });401 it('should shrink strictly negative value for negative range including zero', () => {402 // Arrange403 const arb = new BigIntArbitrary(BigInt(-10), BigInt(0));404 const source = new Value(BigInt(-8), undefined);405 // Act406 const tree = buildShrinkTree(arb, source);407 const renderedTree = renderTree(tree).join('\n');408 // Assert409 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);410 // As the range [-10, 0] and the value -8411 // are the opposite of first case, the rendered tree will be the same except412 // it contains opposite values413 expect(renderedTree).toMatchInlineSnapshot(`414 "-8n415 ├> 0n416 ├> -4n417 | ├> -2n418 | | └> -1n419 | | └> 0n420 | └> -3n421 | └> -2n422 | ├> 0n423 | └> -1n424 | └> 0n425 ├> -6n426 | └> -5n427 | └> -4n428 | ├> 0n429 | ├> -2n430 | | └> -1n431 | | └> 0n432 | └> -3n433 | └> -2n434 | ├> 0n435 | └> -1n436 | └> 0n437 └> -7n438 └> -6n439 ├> 0n440 ├> -3n441 | └> -2n442 | └> -1n443 | └> 0n444 └> -5n445 └> -4n446 └> -3n447 ├> 0n448 └> -2n449 └> -1n450 └> 0n"451 `);452 });453 });...

Full Screen

Full Screen

IntegerArbitrary.spec.ts

Source:IntegerArbitrary.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { IntegerArbitrary } from '../../../../src/arbitrary/_internals/IntegerArbitrary';3import { Value } from '../../../../src/check/arbitrary/definition/Value';4import { fakeRandom } from '../__test-helpers__/RandomHelpers';5import {6 assertProduceValuesShrinkableWithoutContext,7 assertProduceCorrectValues,8 assertShrinkProducesSameValueWithoutInitialContext,9 assertShrinkProducesStrictlySmallerValue,10 assertProduceSameValueGivenSameSeed,11} from '../__test-helpers__/ArbitraryAssertions';12import { buildShrinkTree, renderTree, walkTree } from '../__test-helpers__/ShrinkTree';13import * as BiasNumericRangeMock from '../../../../src/arbitrary/_internals/helpers/BiasNumericRange';14import * as ShrinkIntegerMock from '../../../../src/arbitrary/_internals/helpers/ShrinkInteger';15import { Stream } from '../../../../src/stream/Stream';16function beforeEachHook() {17 jest.resetModules();18 jest.restoreAllMocks();19 fc.configureGlobal({ beforeEach: beforeEachHook });20}21beforeEach(beforeEachHook);22describe('IntegerArbitrary', () => {23 describe('generate', () => {24 it('should never bias and generate the full range when biasFactor is not specified', () =>25 fc.assert(26 fc.property(fc.maxSafeInteger(), fc.maxSafeInteger(), fc.maxSafeInteger(), (a, b, c) => {27 // Arrange28 const [min, mid, max] = [a, b, c].sort((v1, v2) => v1 - v2);29 const { instance: mrng, nextInt } = fakeRandom();30 nextInt.mockReturnValueOnce(mid);31 // Act32 const arb = new IntegerArbitrary(min, max);33 const out = arb.generate(mrng, undefined);34 // Assert35 expect(out.value).toBe(mid);36 expect(nextInt).toHaveBeenCalledTimes(1);37 expect(nextInt).toHaveBeenCalledWith(min, max);38 })39 ));40 it('should not always bias values (expect 1 times over biasFreq) and still generate full range when unbiased', () =>41 fc.assert(42 fc.property(43 fc.maxSafeInteger(),44 fc.maxSafeInteger(),45 fc.maxSafeInteger(),46 fc.maxSafeInteger(),47 (a, b, c, biasFactor) => {48 // Arrange49 const [min, mid, max] = [a, b, c].sort((v1, v2) => v1 - v2);50 const { instance: mrng, nextInt } = fakeRandom();51 nextInt.mockReturnValueOnce(2); // 1 means bias, all others are unbiased52 nextInt.mockReturnValueOnce(mid);53 // Act54 const arb = new IntegerArbitrary(min, max);55 const out = arb.generate(mrng, biasFactor);56 // Assert57 expect(out.value).toBe(mid);58 expect(nextInt).toHaveBeenCalledTimes(2);59 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);60 expect(nextInt).toHaveBeenCalledWith(min, max);61 }62 )63 ));64 it('should bias values (1 times over biasFreq) by using one of the ranges from biasNumericRange', () =>65 fc.assert(66 fc.property(67 fc.maxSafeInteger(),68 fc.maxSafeInteger(),69 fc.maxSafeInteger(),70 fc.maxSafeInteger(),71 fc.maxSafeInteger(),72 // Remark:73 // Following biasNumericRange is not fully identical to the onces that would be provided.74 // Range (in this stub) can be larger than the requested one. Not impacting from a unit-test point of view.75 fc.array(76 fc77 .tuple(fc.maxSafeInteger(), fc.maxSafeInteger())78 .map(([a, b]) => (a < b ? { min: a, max: b } : { min: b, max: a })),79 { minLength: 1 }80 ),81 (a, b, c, biasFactor, mod, ranges) => {82 // Arrange83 const [min, mid, max] = [a, b, c].sort((v1, v2) => v1 - v2);84 const { instance: mrng, nextInt } = fakeRandom();85 nextInt.mockReturnValueOnce(1); // 1 means bias86 if (ranges.length !== 1) {87 nextInt.mockImplementationOnce((min, max) => min + (mod % (max - min + 1)));88 }89 nextInt.mockReturnValueOnce(mid); // Remark: this value will most of the time be outside of requested range90 const biasNumericRange = jest.spyOn(91 BiasNumericRangeMock,92 'biasNumericRange'93 ) as unknown as jest.SpyInstance<{ min: number; max: number }[], [number, number, () => number]>;94 biasNumericRange.mockReturnValueOnce(ranges);95 // Act96 const arb = new IntegerArbitrary(min, max);97 const out = arb.generate(mrng, biasFactor);98 // Assert99 expect(out.value).toBe(mid);100 expect(biasNumericRange).toHaveBeenCalledTimes(1);101 expect(biasNumericRange).toHaveBeenCalledWith(min, max, expect.any(Function));102 if (ranges.length === 1) {103 expect(nextInt).toHaveBeenCalledTimes(2);104 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);105 expect(nextInt).toHaveBeenCalledWith(ranges[0].min, ranges[0].max);106 } else {107 expect(nextInt).toHaveBeenCalledTimes(3);108 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);109 const secondNextIntParams = nextInt.mock.calls[1];110 expect(secondNextIntParams[0]).toBeLessThan(0); // arbitrary is supposed to prefer the first entry111 expect(secondNextIntParams[1]).toBe(ranges.length - 2); // other entries do not have any special treatments112 // negative values for [0], positive value n means ranges[n+1]113 const secondNextIntResult = nextInt.mock.results[1].value;114 const selectedRange = secondNextIntResult < 0 ? 0 : secondNextIntResult + 1;115 expect(nextInt).toHaveBeenCalledWith(ranges[selectedRange].min, ranges[selectedRange].max);116 }117 }118 )119 ));120 });121 describe('canShrinkWithoutContext', () => {122 it('should always tells it can generate values included in the requested range', () =>123 fc.assert(124 fc.property(fc.maxSafeInteger(), fc.maxSafeInteger(), fc.maxSafeInteger(), (a, b, c) => {125 // Arrange126 const [min, mid, max] = [a, b, c].sort((v1, v2) => v1 - v2);127 // Act128 const arb = new IntegerArbitrary(min, max);129 const out = arb.canShrinkWithoutContext(mid);130 // Assert131 expect(out).toBe(true);132 })133 ));134 it('should always reject values outside of the requested range', () =>135 fc.assert(136 fc.property(137 fc.maxSafeInteger(),138 fc.maxSafeInteger(),139 fc.maxSafeInteger(),140 fc.constantFrom(...(['lower', 'higher'] as const)),141 (a, b, c, position) => {142 // Arrange143 const s = [a, b, c].sort((v1, v2) => v1 - v2);144 const [min, max, requested] = position === 'lower' ? [s[1], s[2], s[0]] : [s[0], s[1], s[2]];145 fc.pre(requested !== min && requested !== max);146 // Act147 const arb = new IntegerArbitrary(min, max);148 const out = arb.canShrinkWithoutContext(requested);149 // Assert150 expect(out).toBe(false);151 }152 )153 ));154 it.each`155 requested156 ${'1'}157 ${1.5}158 ${-0}159 ${Number.NaN}160 ${''}161 ${{}}162 `('should always reject non integral values like $requested', ({ requested }) => {163 // Arrange164 const min = 0;165 const max = 100;166 // Act167 const arb = new IntegerArbitrary(min, max);168 const out = arb.canShrinkWithoutContext(requested);169 // Assert170 expect(out).toBe(false);171 });172 });173 describe('shrink', () => {174 it('should always call shrink helper when no context provided', () =>175 fc.assert(176 fc.property(fc.maxSafeNat(), fc.maxSafeNat(), fc.maxSafeNat(), (a, b, c) => {177 // Arrange178 const [min, mid, max] = [a, b, c].sort((v1, v2) => v1 - v2);179 const expectedShrinks = Stream.nil<Value<number>>();180 const shrinkInteger = jest.spyOn(ShrinkIntegerMock, 'shrinkInteger');181 shrinkInteger.mockReturnValueOnce(expectedShrinks);182 // Act183 const arb = new IntegerArbitrary(min, max);184 const shrinks = arb.shrink(mid, undefined);185 // Assert186 expect(shrinks).toBe(expectedShrinks);187 expect(shrinkInteger).toHaveBeenCalledTimes(1);188 expect(shrinkInteger).toHaveBeenCalledWith(mid, expect.any(Number), true);189 })190 ));191 });192});193describe('IntegerArbitrary (integration)', () => {194 type Extra = { min: number; max: number };195 const extraParameters: fc.Arbitrary<Extra> = fc196 .tuple(fc.maxSafeInteger(), fc.maxSafeInteger())197 .map(([a, b]) => (a < b ? { min: a, max: b } : { min: b, max: a }));198 const isCorrect = (value: number, extra: Extra) =>199 typeof value === 'number' &&200 Number.isInteger(value) &&201 !Object.is(value, -0) &&202 extra.min <= value &&203 value <= extra.max;204 const isStrictlySmaller = (v1: number, v2: number) => Math.abs(v1) < Math.abs(v2);205 const integerBuilder = (extra: Extra) => new IntegerArbitrary(extra.min, extra.max);206 it('should produce the same values given the same seed', () => {207 assertProduceSameValueGivenSameSeed(integerBuilder, { extraParameters });208 });209 it('should only produce correct values', () => {210 assertProduceCorrectValues(integerBuilder, isCorrect, { extraParameters });211 });212 it('should produce values seen as shrinkable without any context', () => {213 assertProduceValuesShrinkableWithoutContext(integerBuilder, { extraParameters });214 });215 it('should be able to shrink to the same values without initial context', () => {216 assertShrinkProducesSameValueWithoutInitialContext(integerBuilder, { extraParameters });217 });218 it('should shrink towards strictly smaller values', () => {219 assertShrinkProducesStrictlySmallerValue(integerBuilder, isStrictlySmaller, { extraParameters });220 });221 describe('shrink', () => {222 it('should build a mirrored version of the shrinking tree if we negate all the values', () =>223 fc.assert(224 fc.property(225 fc.maxSafeInteger(),226 fc.integer({ min: 0, max: 20 }), // larger trees might be too wide227 fc.integer({ min: 0, max: 20 }),228 (start, o1, o2) => {229 // Arrange230 fc.pre(start + o1 <= Number.MAX_SAFE_INTEGER);231 fc.pre(start + o2 <= Number.MAX_SAFE_INTEGER);232 const min = start;233 const [mid, max] = o1 < o2 ? [min + o1, min + o2] : [min + o2, min + o1];234 const arb = new IntegerArbitrary(min, max);235 const arbNegate = new IntegerArbitrary(max !== 0 ? -max : 0, min !== 0 ? -min : min); // !==0 to avoid -0236 // Act237 const source = new Value(mid, undefined);238 const sourceNegate = new Value(mid !== 0 ? -mid : 0, undefined); // !==0 to avoid -0239 const tree = buildShrinkTree(arb, source);240 const treeNegate = buildShrinkTree(arbNegate, sourceNegate);241 const flat: number[] = [];242 const flatNegate: number[] = [];243 walkTree(tree, (v) => flat.push(v));244 walkTree(treeNegate, (v) => flatNegate.push(v !== 0 ? -v : 0));245 // Assert246 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);247 expect(arbNegate.canShrinkWithoutContext(sourceNegate.value)).toBe(true);248 expect(flatNegate).toEqual(flat);249 }250 )251 ));252 it('should build an offset version of the shrinking tree if we offset all the values (keep every value >=0)', () =>253 fc.assert(254 fc.property(255 fc.integer({ min: 0, max: Number.MAX_SAFE_INTEGER }),256 fc.integer({ min: 0, max: 20 }), // larger trees might be too wide257 fc.integer({ min: 0, max: 20 }),258 fc.integer({ min: 0, max: Number.MAX_SAFE_INTEGER }),259 (start, o1, o2, offset) => {260 // Arrange261 fc.pre(start + o1 + offset <= Number.MAX_SAFE_INTEGER);262 fc.pre(start + o2 + offset <= Number.MAX_SAFE_INTEGER);263 const min = start;264 const [mid, max] = o1 < o2 ? [min + o1, min + o2] : [min + o2, min + o1];265 const arb = new IntegerArbitrary(min, max);266 const arbOffset = new IntegerArbitrary(min + offset, max + offset);267 // Act268 const source = new Value(mid, undefined);269 const sourceOffset = new Value(mid + offset, undefined);270 const tree = buildShrinkTree(arb, source);271 const treeOffset = buildShrinkTree(arbOffset, sourceOffset);272 const flat: number[] = [];273 const flatOffset: number[] = [];274 walkTree(tree, (v) => flat.push(v));275 walkTree(treeOffset, (v) => flatOffset.push(v - offset));276 // Assert277 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);278 expect(arbOffset.canShrinkWithoutContext(sourceOffset.value)).toBe(true);279 expect(flatOffset).toEqual(flat);280 }281 )282 ));283 it('should shrink strictly positive value for positive range including zero', () => {284 // Arrange285 const arb = new IntegerArbitrary(0, 10);286 const source = new Value(8, undefined);287 // Act288 const tree = buildShrinkTree(arb, source);289 const renderedTree = renderTree(tree).join('\n');290 // Assert291 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);292 // When there is no more option, the shrinker retry one time with the value293 // current-1 to check if something that changed outside (another value not itself)294 // may have changed the situation.295 expect(renderedTree).toMatchInlineSnapshot(`296 "8297 ├> 0298 ├> 4299 | ├> 2300 | | └> 1301 | | └> 0302 | └> 3303 | └> 2304 | ├> 0305 | └> 1306 | └> 0307 ├> 6308 | └> 5309 | └> 4310 | ├> 0311 | ├> 2312 | | └> 1313 | | └> 0314 | └> 3315 | └> 2316 | ├> 0317 | └> 1318 | └> 0319 └> 7320 └> 6321 ├> 0322 ├> 3323 | └> 2324 | └> 1325 | └> 0326 └> 5327 └> 4328 └> 3329 ├> 0330 └> 2331 └> 1332 └> 0"333 `);334 // Remarks:335 // * When we shrink 5 in path 8 > 6 > 5336 // we already now that 4 passed so we now that the smallest failing case337 // to look for is >= 5338 // * Same thing when we shrink 6 in path 8 > 6339 // * When we shrink 7 in path 8 > 7340 // we already now that 6 passed so we now that the smallest failing case341 // to look for is >= 7342 });343 it('should shrink strictly positive value for range not including zero', () => {344 // Arrange345 const arb = new IntegerArbitrary(10, 20);346 const source = new Value(18, undefined);347 // Act348 const tree = buildShrinkTree(arb, source);349 const renderedTree = renderTree(tree).join('\n');350 // Assert351 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);352 // As the range [10, 20] and the value 18353 // are just offset by +10 compared to the first case,354 // the rendered tree will be offset by 10 too355 expect(renderedTree).toMatchInlineSnapshot(`356 "18357 ├> 10358 ├> 14359 | ├> 12360 | | └> 11361 | | └> 10362 | └> 13363 | └> 12364 | ├> 10365 | └> 11366 | └> 10367 ├> 16368 | └> 15369 | └> 14370 | ├> 10371 | ├> 12372 | | └> 11373 | | └> 10374 | └> 13375 | └> 12376 | ├> 10377 | └> 11378 | └> 10379 └> 17380 └> 16381 ├> 10382 ├> 13383 | └> 12384 | └> 11385 | └> 10386 └> 15387 └> 14388 └> 13389 ├> 10390 └> 12391 └> 11392 └> 10"393 `);394 });395 it('should shrink strictly negative value for negative range including zero', () => {396 // Arrange397 const arb = new IntegerArbitrary(-10, 0);398 const source = new Value(-8, undefined);399 // Act400 const tree = buildShrinkTree(arb, source);401 const renderedTree = renderTree(tree).join('\n');402 // Assert403 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);404 // As the range [-10, 0] and the value -8405 // are the opposite of first case, the rendered tree will be the same except406 // it contains opposite values407 expect(renderedTree).toMatchInlineSnapshot(`408 "-8409 ├> 0410 ├> -4411 | ├> -2412 | | └> -1413 | | └> 0414 | └> -3415 | └> -2416 | ├> 0417 | └> -1418 | └> 0419 ├> -6420 | └> -5421 | └> -4422 | ├> 0423 | ├> -2424 | | └> -1425 | | └> 0426 | └> -3427 | └> -2428 | ├> 0429 | └> -1430 | └> 0431 └> -7432 └> -6433 ├> 0434 ├> -3435 | └> -2436 | └> -1437 | └> 0438 └> -5439 └> -4440 └> -3441 ├> 0442 └> -2443 └> -1444 └> 0"445 `);446 });447 });...

Full Screen

Full Screen

Shrink.test.ts

Source:Shrink.test.ts Github

copy

Full Screen

1import * as dev from '../../src';2import { nativeCalculator } from '../../src/Number';3test.each([4 { value: 0, target: 0, expectedShrinks: [] },5 { value: 100, target: 0, expectedShrinks: [0, 50, 75, 87, 93, 96, 98, 99] },6 { value: 200, target: 0, expectedShrinks: [0, 100, 150, 175, 187, 193, 196, 198, 199] },7 { value: 100, target: 10, expectedShrinks: [10, 55, 77, 88, 94, 97, 98, 99] },8 { value: 100, target: -10, expectedShrinks: [-10, 45, 72, 86, 93, 96, 98, 99] },9 { value: -100, target: 0, expectedShrinks: [0, -50, -75, -87, -93, -96, -98, -99] },10 { value: 0, target: -10, expectedShrinks: [-10, -5, -3, -2, -1] },11])('towardsNumber', ({ value, target, expectedShrinks }) => {12 const shrinker = dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.loadIntegerUnchecked(target));13 const shrinks = Array.from(shrinker(nativeCalculator.loadIntegerUnchecked(value))).map(14 nativeCalculator.unloadInteger,15 );16 expect(shrinks).toEqual(expectedShrinks);17});18test.each([19 { value: [], size: 0, expectedShrinks: [] },20 { value: [], size: 1, expectedShrinks: [] },21 { value: ['a'], size: 0, expectedShrinks: [] },22 { value: ['a', 'b'], size: 0, expectedShrinks: [] },23 { value: ['a', 'b'], size: 1, expectedShrinks: [['a'], ['b']] },24 { value: ['a', 'b', 'c'], size: 1, expectedShrinks: [['a'], ['b'], ['c']] },25 {26 value: ['a', 'b', 'c'],27 size: 2,28 expectedShrinks: [29 ['a', 'b'],30 ['a', 'c'],31 ['b', 'c'],32 ],33 },34 {35 value: ['a', 'b', 'c', 'd'],36 size: 2,37 expectedShrinks: [38 ['a', 'b'],39 ['a', 'c'],40 ['a', 'd'],41 ['b', 'c'],42 ['b', 'd'],43 ['c', 'd'],44 ],45 },46 {47 value: ['a', 'b', 'c', 'd'],48 size: 3,49 expectedShrinks: [50 ['a', 'b', 'c'],51 ['a', 'b', 'd'],52 ['a', 'c', 'd'],53 ['b', 'c', 'd'],54 ],55 },56])('combinations', ({ value, size, expectedShrinks }) => {57 const shrinker = dev.Shrink.combinations(size);58 const shrinks = Array.from(shrinker(value));59 expect(shrinks).toEqual(expectedShrinks);60});61test.each([62 { value: [], targetLength: 0, expectedShrinks: [] },63 { value: ['a'], targetLength: 0, expectedShrinks: [[]] },64 { value: ['a', 'b'], targetLength: 0, expectedShrinks: [[], ['a'], ['b']] },65 { value: ['a', 'b'], targetLength: 1, expectedShrinks: [['a'], ['b']] },66 {67 value: ['a', 'b', 'c'],68 targetLength: 0,69 expectedShrinks: [[], ['a'], ['a', 'b'], ['b'], ['c'], ['a', 'c'], ['b', 'c']],70 },71 {72 value: ['a', 'b', 'c'],73 targetLength: 2,74 expectedShrinks: [75 ['a', 'b'],76 ['a', 'c'],77 ['b', 'c'],78 ],79 },80])('array', ({ value, targetLength, expectedShrinks }) => {81 const shrinker = dev.Shrink.array(targetLength);82 const shrinks = Array.from(shrinker(value));83 expect(shrinks).toEqual(expectedShrinks);84});85test.each([86 {87 value: ['c', 'b', 'a'],88 targetLength: 0,89 expectedShrinks: [90 ['a', 'b', 'c'],91 [],92 ['a'],93 ['a', 'b'],94 ['b'],95 ['c'],96 ['a', 'c'],97 ['b', 'c'],98 [],99 ['c'],100 ['c', 'b'],101 ['b'],102 ['a'],103 ['c', 'a'],104 ['b', 'a'],105 ],106 },107])('array (with ordering)', ({ value, targetLength, expectedShrinks }) => {108 const shrinker = dev.Shrink.array<string>(targetLength, (x) => x.charCodeAt(0));109 const shrinks = Array.from(shrinker(value));110 expect(shrinks).toEqual(expectedShrinks);111});112test.each([113 {114 value: [],115 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),116 expectedShrinks: [],117 },118 {119 value: [1],120 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),121 expectedShrinks: [[0]],122 },123 {124 value: [1, 2],125 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),126 expectedShrinks: [127 [0, 2],128 [1, 0],129 [1, 1],130 ],131 },132 {133 value: [1, 1, 0],134 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),135 expectedShrinks: [136 [0, 1, 0],137 [1, 0, 0],138 ],139 },140])('elements', ({ value, elementShrinker, expectedShrinks }) => {141 const shrinker = dev.Shrink.elements(elementShrinker);142 const shrinks = Array.from(shrinker(value.map(nativeCalculator.loadIntegerUnchecked))).map((xs) =>143 xs.map(nativeCalculator.loadIntegerUnchecked),144 );145 expect(shrinks).toEqual(expectedShrinks);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { expectedShrinks } = require('fast-check/lib/check/arbitrary/definition/ExpectedShrinks');3const { Random } = require('fast-check/lib/random/generator/Random');4const { Stream } = require('fast-check/lib/stream/Stream');5const { cloneMethod } = require('fast-check/lib/check/symbols');6const { random } = new Random(0);7const { value_ } = expectedShrinks(fc.integer(), random);8console.log(value_);9const { value_ } = expectedShrinks(fc.float(), random);10console.log(value_);11const { value_ } = expectedShrinks(fc.string(), random);12console.log(value_);13const { value_ } = expectedShrinks(fc.boolean(), random);14console.log(value_);15const { value_ } = expectedShrinks(fc.constantFrom('a', 'b', 'c'), random);16console.log(value_);17const { value_ } = expectedShrinks(fc.constantFrom(1, 2, 3), random);18console.log(value_);19const { value_ } = expectedShrinks(fc.constantFrom(true, false), random);20console.log(value_);21const { value_ } = expectedShrinks(fc.constantFrom(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), random);22console.log(value_);23const { value_ } = expectedShrinks(fc.constantFrom('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'), random);24console.log(value_);25const { value_ } = expectedShrinks(fc.constantFrom(true, false, false, true, false, true, true, false, true, false), random);26console.log(value_);27const { value_ } = expectedShrinks(fc.oneof(fc.constantFrom(1, 2, 3), fc.constantFrom('a', 'b', 'c'), fc.constantFrom(true, false)), random);28console.log(value_);29const { value_ } = expectedShrinks(fc.oneof(fc.constantFrom(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), fc.constantFrom('a', 'b', 'c', 'd', 'e', 'f', 'g

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const assert = require('assert');3const isOdd = (n) => n % 2 === 1;4fc.assert(5 fc.property(fc.integer(), (n) => {6 assert(isOdd(n));7 }),8);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const arb1 = fc.integer(0, 100);3const arb2 = fc.integer(0, 100);4const arb3 = fc.tuple(arb1, arb2);5const arb4 = fc.tuple(arb3, arb3);6const arb5 = fc.tuple(arb4, arb4);7const arb6 = fc.tuple(arb5, arb5);8const arb7 = fc.tuple(arb6, arb6);9const arb8 = fc.tuple(arb7, arb7);10const arb9 = fc.tuple(arb8, arb8);11const arb10 = fc.tuple(arb9, arb9);12const arb11 = fc.tuple(arb10, arb10);13const arb12 = fc.tuple(arb11, arb11);14const arb13 = fc.tuple(arb12, arb12);15const arb14 = fc.tuple(arb13, arb13);16const arb15 = fc.tuple(arb14, arb14);17const arb16 = fc.tuple(arb15, arb15);18const arb17 = fc.tuple(arb16, arb16);19const arb18 = fc.tuple(arb17, arb17);20const arb19 = fc.tuple(arb18, arb18);21const arb20 = fc.tuple(arb19, arb19);22const arb21 = fc.tuple(arb20, arb20);23const arb22 = fc.tuple(arb21, arb21);24const arb23 = fc.tuple(arb22, arb22);25const arb24 = fc.tuple(arb23, arb23);26const arb25 = fc.tuple(arb24, arb24);27const arb26 = fc.tuple(arb25, arb25);28const arb27 = fc.tuple(arb26, arb26);29const arb28 = fc.tuple(arb27, arb27);30const arb29 = fc.tuple(arb28, arb28);31const arb30 = fc.tuple(arb29, arb29);32const arb31 = fc.tuple(arb30, arb30);33const arb32 = fc.tuple(arb31, arb31);34const arb33 = fc.tuple(arb32, arb32);35const arb34 = fc.tuple(arb33, arb33);36const arb35 = fc.tuple(arb34, arb34);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const { expectedShrinks } = require("fast-check/lib/check/arbitrary/definition/ExpectedShrinks");3const arb = fc.integer(0, 10);4const shrinks = expectedShrinks(arb);5console.log(shrinks(0));6console.log(shrinks(1));7console.log(shrinks(2));8console.log(shrinks(3));9console.log(shrinks(4));10console.log(shrinks(5));11console.log(shrinks(6));12console.log(shrinks(7));13console.log(shrinks(8));14console.log(shrinks(9));15console.log(sh

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fc } from "fast-check";2const arb = fc.string();3const result = fc.check(4 fc.property(arb, (s) => {5 return s.length < 10;6 })7);8console.log(result.failed ? result.counterexample![0] : "No counterexample");9console.log("shrinks", result.failed ? result.counterexample![1] : "No shrinks");10console.log(result.failed ? result.counterexample![2] : "No shrinks");11console.log(result.failed ? result.counterexample![3] : "No shrinks");12console.log(result.failed ? result.counterexample![4] : "No shrinks");13console.log(result.failed ? result.counterexample![5] : "No shrinks");14console.log(result.failed ? result.counterexample![6] : "No shrinks");15console.log(result.failed ? result.counterexample![7] : "No shrinks");16console.log(result.failed ? result.counterexample![8] : "No shrinks");17console.log(result.failed ? result.counterexample![9] : "No shrinks");18console.log(result.failed ? result.counterexample![10] : "No shrinks");19console.log(result.failed ? result.counterexample![11] : "No shrinks");20console.log(result.failed ? result.counterexample![12] : "No shrinks");21console.log(result.failed ? result.counterexample![13] : "No shrinks");22console.log(result.failed ? result.counterexample![14] : "No shrinks");23console.log(result.failed ? result.counterexample![15] : "No shrinks");24console.log(result.failed ? result.counterexample![16] : "No shrinks");25console.log(result.failed ? result.counterexample![17] : "No shrinks");26console.log(result.failed ? result.counterexample![18] : "No shrinks");27console.log(result.failed ? result.counterexample![19] : "No shrinks");28console.log(result.failed ? result.counterexample![20] : "No shrinks");29console.log(result.failed ? result.counterexample![21] : "No shrinks");30console.log(result.failed ? result.counterexample![22] : "No shrinks");31console.log(result.failed ? result.counterexample![23] : "No shrinks");32console.log(result.failed ? result.counterexample![24] : "No shrinks");33console.log(result.failed ? result.counterexample![25] : "No shrinks");34console.log(result.failed ? result.counterexample![

Full Screen

Using AI Code Generation

copy

Full Screen

1const { asyncProperty, integer } = require("fast-check");2const { expect } = require("chai");3const { asyncProperty } = require("fast-check");4const isEven = (n) => n % 2 === 0;5describe("isEven", () => {6 it("should only generate even numbers", async () => {7 await asyncProperty(8 integer(),9 async (n) => {10 const result = isEven(n);11 expect(result).to.be.true;12 },13 {14 }15 );16 });17});18const { asyncProperty, integer } = require("fast-check");19const { expect } = require("chai");20const { asyncProperty } = require("fast-check");21const isEven = (n) => n % 2 === 0;22describe("isEven", () => {23 it("should only generate even numbers", async () => {24 await asyncProperty(25 integer(),26 async (n) => {27 const result = isEven(n);28 expect(result).to.be.true;29 },30 {31 }32 );33 });34});35const { asyncProperty, integer } = require("fast-check");36const { expect } = require("chai");37const { asyncProperty } = require("fast-check");38const isEven = (n) => n % 2 === 0;39describe("isEven", () => {40 it("should only generate even numbers", async () => {41 await asyncProperty(42 integer(),43 async (n) => {44 const result = isEven(n);45 expect(result).to.be.true;46 },47 {48 }49 );50 });51});52const { asyncProperty, integer } = require("fast-check");53const { expect } = require("chai

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const property = fc.property(fc.integer(), fc.integer(), (a, b) => {3 return a + b === b + a;4});5const seed = 42;6const numRuns = 100;7const runner = fc.check(property, { seed, numRuns });8console.log(runner.expectedShrinks());9const fc = require('fast-check');10const property = fc.property(fc.integer(), fc.integer(), (a, b) => {11 return a + b === b + a;12});13const seed = 42;14const numRuns = 100;15const numFailures = 10;16const runner = fc.check(property, { seed, numRuns, numFailures });17console.log(runner.expectedShrinks());18const fc = require('fast-check');19const property = fc.property(fc.integer(), fc.integer(), (a, b) => {20 return a + b === b + a;21});22const seed = 42;23const numRuns = 100;24const numFailures = 10;25const runner = fc.check(property, { seed, numRuns, numFailures });26console.log(runner.expectedShrinks());

Full Screen

Using AI Code Generation

copy

Full Screen

1const { property, fc } = require('fast-check');2const shrinkArray = require('./shrinkArray');3property(4 fc.array(fc.integer()),5 (arr) => {6 const result = shrinkArray(arr);7 return result.every((subarr) => subarr.length <= arr.length);8 }9).expectedShrinks(1000).check();10const shrinkArray = (arr) => {11 const result = [];12 for (let i = 0; i < arr.length; i++) {13 const subarr = arr.slice();14 subarr.splice(i, 1);15 result.push(subarr);16 }17 return result;18};19module.exports = shrinkArray;20const { property, fc } = require('fast-check');21const shrinkArray = require('./shrinkArray');22property(23 fc.array(fc.integer()),24 (arr) => {25 const result = shrinkArray(arr);26 return result.every((subarr) => subarr.length <= arr.length);27 }

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