How to use spyArrayInt64 method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

double.spec.ts

Source:double.spec.ts Github

copy

Full Screen

...37 it('should accept any valid range of floating point numbers (including infinity)', () => {38 fc.assert(39 fc.property(doubleConstraints(), (ct) => {40 // Arrange41 spyArrayInt64();42 // Act43 const arb = double(ct);44 // Assert45 expect(arb).toBeDefined();46 })47 );48 });49 it('should accept any constraits defining min (not-NaN) equal to max', () => {50 fc.assert(51 fc.property(52 float64raw(),53 fc.record({ noDefaultInfinity: fc.boolean(), noNaN: fc.boolean() }, { withDeletedKeys: true }),54 (f, otherCt) => {55 // Arrange56 fc.pre(!Number.isNaN(f));57 spyArrayInt64();58 // Act59 const arb = double({ ...otherCt, min: f, max: f });60 // Assert61 expect(arb).toBeDefined();62 }63 )64 );65 });66 it('should reject NaN if specified for min', () => {67 // Arrange68 const arrayInt64 = spyArrayInt64();69 // Act / Assert70 expect(() => double({ min: Number.NaN })).toThrowError();71 expect(arrayInt64).not.toHaveBeenCalled();72 });73 it('should reject NaN if specified for max', () => {74 // Arrange75 const arrayInt64 = spyArrayInt64();76 // Act / Assert77 expect(() => double({ max: Number.NaN })).toThrowError();78 expect(arrayInt64).not.toHaveBeenCalled();79 });80 it('should reject if specified min is strictly greater than max', () => {81 fc.assert(82 fc.property(float64raw(), float64raw(), (da, db) => {83 // Arrange84 fc.pre(!Number.isNaN(da));85 fc.pre(!Number.isNaN(db));86 fc.pre(!Object.is(da, db)); // Object.is can distinguish -0 from 0, while !== cannot87 const arrayInt64 = spyArrayInt64();88 const min = isStrictlySmaller(da, db) ? db : da;89 const max = isStrictlySmaller(da, db) ? da : db;90 // Act / Assert91 expect(() => double({ min, max })).toThrowError();92 expect(arrayInt64).not.toHaveBeenCalled();93 })94 );95 });96 it('should reject impossible noDefaultInfinity-based ranges', () => {97 // Arrange98 const arrayInt64 = spyArrayInt64();99 // Act / Assert100 expect(() => double({ min: Number.POSITIVE_INFINITY, noDefaultInfinity: true })).toThrowError();101 expect(() => double({ max: Number.NEGATIVE_INFINITY, noDefaultInfinity: true })).toThrowError();102 expect(arrayInt64).not.toHaveBeenCalled();103 });104 if (typeof BigInt !== 'undefined') {105 it('should properly convert integer value for index between min and max into its associated float value', () => {106 fc.assert(107 fc.property(108 fc.option(doubleConstraints(), { nil: undefined }),109 fc.bigUintN(64),110 fc.option(fc.integer({ min: 2 }), { nil: undefined }),111 (ct, mod, biasFactor) => {112 // Arrange113 const { instance: mrng } = fakeRandom();114 const { min, max } = minMaxForConstraints(ct || {});115 const minIndex = doubleToIndex(min);116 const maxIndex = doubleToIndex(max);117 const arbitraryGeneratedIndex = toIndex(118 (mod % (toBigInt(maxIndex) - toBigInt(minIndex) + BigInt(1))) + toBigInt(minIndex)119 );120 spyArrayInt64WithValue(() => arbitraryGeneratedIndex);121 // Act122 const arb = double(ct);123 const { value_: f } = arb.generate(mrng, biasFactor);124 // Assert125 expect(f).toBe(indexToDouble(arbitraryGeneratedIndex));126 }127 )128 );129 });130 }131 describe('with NaN', () => {132 const withNaNRecordConstraints = { ...defaultDoubleRecordConstraints, noNaN: fc.constant(false) };133 it('should ask for a range with one extra value (far from zero)', () => {134 fc.assert(135 fc.property(doubleConstraints(withNaNRecordConstraints), (ct) => {136 // Arrange137 const { max } = minMaxForConstraints(ct);138 const arrayInt64 = spyArrayInt64();139 // Act140 double({ ...ct, noNaN: true });141 double(ct);142 // Assert143 expect(arrayInt64).toHaveBeenCalledTimes(2);144 const constraintsNoNaN = arrayInt64.mock.calls[0];145 const constraintsWithNaN = arrayInt64.mock.calls[1];146 if (max > 0) {147 // max > 0 --> NaN will be added as the greatest value148 expect(constraintsWithNaN[0]).toEqual(constraintsNoNaN[0]);149 expect(constraintsWithNaN[1]).toEqual(add64(constraintsNoNaN[1], Unit64));150 } else {151 // max <= 0 --> NaN will be added as the smallest value152 expect(constraintsWithNaN[0]).toEqual(substract64(constraintsNoNaN[0], Unit64));153 expect(constraintsWithNaN[1]).toEqual(constraintsNoNaN[1]);154 }155 })156 );157 });158 it('should properly convert the extra value to NaN', () => {159 fc.assert(160 fc.property(161 doubleConstraints(withNaNRecordConstraints),162 fc.option(fc.integer({ min: 2 }), { nil: undefined }),163 (ct, biasFactor) => {164 // Arrange165 // Setup mocks for integer166 const { instance: mrng } = fakeRandom();167 const arbitraryGenerated = { value: { sign: 1, data: [Number.NaN, Number.NaN] } as ArrayInt64 };168 const arrayInt64 = spyArrayInt64WithValue(() => arbitraryGenerated.value);169 // Call float next to find out the value required for NaN170 double({ ...ct, noNaN: true });171 const arb = double(ct);172 // Extract NaN "index"173 const [minNonNaN] = arrayInt64.mock.calls[0];174 const [minNaN, maxNaN] = arrayInt64.mock.calls[1];175 const indexForNaN = !isEqual64(minNonNaN, minNaN) ? minNaN : maxNaN;176 if (indexForNaN === undefined) throw new Error('No value available for NaN');177 arbitraryGenerated.value = indexForNaN;178 // Act179 const { value_: f } = arb.generate(mrng, biasFactor);180 // Assert181 expect(f).toBe(Number.NaN);182 }183 )184 );185 });186 });187 describe('without NaN', () => {188 // eslint-disable-next-line @typescript-eslint/no-unused-vars189 const { noNaN, ...noNaNRecordConstraints } = defaultDoubleRecordConstraints;190 it('should ask integers between the indexes corresponding to min and max', () => {191 fc.assert(192 fc.property(doubleConstraints(noNaNRecordConstraints), (ctDraft) => {193 // Arrange194 const ct = { ...ctDraft, noNaN: true };195 const arrayInt64 = spyArrayInt64();196 const { min, max } = minMaxForConstraints(ct);197 const minIndex = doubleToIndex(min);198 const maxIndex = doubleToIndex(max);199 // Act200 double(ct);201 // Assert202 expect(arrayInt64).toHaveBeenCalledTimes(1);203 expect(arrayInt64).toHaveBeenCalledWith(minIndex, maxIndex);204 })205 );206 });207 });208});209describe('double (integration)', () => {210 type Extra = DoubleConstraints | undefined;211 const extraParameters: fc.Arbitrary<Extra> = fc.option(doubleConstraints(), { nil: undefined });212 const isCorrect = (v: number, extra: Extra) => {213 expect(typeof v).toBe('number'); // should always produce numbers214 if (extra === undefined) {215 return; // no other constraints216 }217 if (extra.noNaN) {218 expect(v).not.toBe(Number.NaN); // should not produce NaN if explicitely asked not too219 }220 if (extra.min !== undefined && !Number.isNaN(v)) {221 expect(v).toBeGreaterThanOrEqual(extra.min); // should always be greater than min when specified222 }223 if (extra.max !== undefined && !Number.isNaN(v)) {224 expect(v).toBeLessThanOrEqual(extra.max); // should always be smaller than max when specified225 }226 if (extra.noDefaultInfinity) {227 if (extra.min === undefined) {228 expect(v).not.toBe(Number.NEGATIVE_INFINITY); // should not produce -infinity when noInfinity and min unset229 }230 if (extra.max === undefined) {231 expect(v).not.toBe(Number.POSITIVE_INFINITY); // should not produce +infinity when noInfinity and max unset232 }233 }234 };235 const isStrictlySmaller = (fa: number, fb: number) =>236 Math.abs(fa) < Math.abs(fb) || // Case 1: abs(a) < abs(b)237 (Object.is(fa, +0) && Object.is(fb, -0)) || // Case 2: +0 < -0 --> we shrink from -0 to +0238 (!Number.isNaN(fa) && Number.isNaN(fb)); // Case 3: notNaN < NaN, NaN is one of the extreme values239 const doubleBuilder = (extra: Extra) => double(extra);240 it('should produce the same values given the same seed', () => {241 assertProduceSameValueGivenSameSeed(doubleBuilder, { extraParameters });242 });243 it('should only produce correct values', () => {244 assertProduceCorrectValues(doubleBuilder, isCorrect, { extraParameters });245 });246 it('should produce values seen as shrinkable without any context', () => {247 assertProduceValuesShrinkableWithoutContext(doubleBuilder, { extraParameters });248 });249 it('should be able to shrink to the same values without initial context', () => {250 assertShrinkProducesSameValueWithoutInitialContext(doubleBuilder, { extraParameters });251 });252 it('should preserve strictly smaller ordering in shrink', () => {253 assertShrinkProducesStrictlySmallerValue(doubleBuilder, isStrictlySmaller, { extraParameters });254 });255});256// Helpers257type Index = ReturnType<typeof doubleToIndex>;258function toIndex(raw: bigint | string): Index {259 const b = typeof raw === 'string' ? BigInt(raw) : raw;260 const pb = b < BigInt(0) ? -b : b;261 return { sign: b < BigInt(0) ? -1 : 1, data: [Number(pb >> BigInt(32)), Number(pb & BigInt(0xffffffff))] };262}263function toBigInt(index: Index): bigint {264 return BigInt(index.sign) * ((BigInt(index.data[0]) << BigInt(32)) + BigInt(index.data[1]));265}266function minMaxForConstraints(ct: DoubleConstraints) {267 const noDefaultInfinity = ct.noDefaultInfinity;268 const {269 min = noDefaultInfinity ? -Number.MAX_VALUE : Number.NEGATIVE_INFINITY,270 max = noDefaultInfinity ? Number.MAX_VALUE : Number.POSITIVE_INFINITY,271 } = ct;272 return { min, max };273}274function spyArrayInt64() {275 const { instance, map } = fakeArbitrary<ArrayInt64>();276 const { instance: mappedInstance } = fakeArbitrary();277 const arrayInt64 = jest.spyOn(ArrayInt64ArbitraryMock, 'arrayInt64');278 arrayInt64.mockReturnValue(instance);279 map.mockReturnValue(mappedInstance);280 return arrayInt64;281}282function spyArrayInt64WithValue(value: () => ArrayInt64) {283 const { instance } = fakeArbitraryStaticValue<ArrayInt64>(value);284 const integer = jest.spyOn(ArrayInt64ArbitraryMock, 'arrayInt64');285 integer.mockReturnValue(instance);286 return integer;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spyArrayInt64 } = require("fast-check-monorepo");2spyArrayInt64();3const { spyArrayInt64 } = require("fast-check");4spyArrayInt64();5const { spyArrayInt64 } = require("fast-check/lib/check/arbitrary/ArrayArbitrary");6spyArrayInt64();7const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");8spyArrayInt64();9const { spyArrayInt64 } = require("fast-check/check/arbitrary/ArrayArbitrary");10spyArrayInt64();11const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");12spyArrayInt64();13const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");14spyArrayInt64();15const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");16spyArrayInt64();17const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");18spyArrayInt64();19const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");20spyArrayInt64();21const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");22spyArrayInt64();23const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");24spyArrayInt64();25const { spyArrayInt64 } = require("fast-check/src/check/arbitrary/ArrayArbitrary");26spyArrayInt64();27const { spyArrayInt

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spyArrayInt64 } = require('fast-check-monorepo');2const { spyArrayInt64 } = require('fast-check');3const { spyArrayInt64 } = require('@fast-check-monorepo/fast-check');4const { spyArrayInt64 } = require('@fast-check/fast-check');5const { spyArrayInt64 } = require('@fast-check-monorepo/fast-check/lib/esm/check/arbitrary/SpyArbitrary');6const { spyArrayInt64 } = require('@fast-check/fast-check/lib/esm/check/arbitrary/SpyArbitrary');7const { spyArrayInt64 } = require('@fast-check-monorepo/fast-check/lib/esm/check/arbitrary/SpyArbitrary.js');8const { spyArrayInt64 } = require('@fast-check/fast-check/lib/esm/check/arbitrary/SpyArbitrary.js');9const { spyArrayInt64 } = require('@fast-check-monorepo/fast-check/lib/esm/check/arbitrary/SpyArbitrary');10const { spyArrayInt64 } = require('@fast-check/fast-check/lib/esm/check/arbitrary/SpyArbitrary');11const { spyArrayInt64 } = require('@fast-check-monorepo/fast-check/lib/esm/check/arbitrary/SpyArbitrary.js');12const { spyArrayInt64 } = require('@fast-check/fast-check/lib/esm/check/arbitrary/SpyArbitrary.js');13const { spyArrayInt64 } = require('@fast-check-monorepo/fast-check/lib/esm/check/arbitrary/SpyArbitrary');14const { spyArrayInt

Full Screen

Using AI Code Generation

copy

Full Screen

1const fastCheck = require('fast-check');2const spyArrayInt64 = require('fast-check-monorepo').spyArrayInt64;3fastCheck.assert(4 fastCheck.property(5 fastCheck.array(fastCheck.int64(), 1, 10),6);7npm ERR! 404 You should bug the author to publish it (or use the name yourself!)8const fastCheck = require('fast-check');9const spyArrayInt64 = require('fast-check-monorepo').spyArrayInt64;10test('test', () => {11 expect(12 fastCheck.assert(13 fastCheck.property(14 fastCheck.array(fastCheck.int64(), 1, 10),15 ).toBeTruthy();16});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { spyArrayInt64 } = require('fast-check-monorepo');3fc.assert(4 fc.property(spyArrayInt64(), (arr) => {5 return arr.length === 2;6 })7);8{ _t: 'ArrayInt64', _v: [ 0, 0 ] }9{ _t: 'ArrayInt64', _v: [ 0, 0 ] }10{ _t: 'ArrayInt64', _v: [ 0, 0 ] }

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const spyArrayInt64 = require('fast-check-monorepo').spyArrayInt64;3describe('spyArrayInt64', () => {4 it('should return an array of 64 bits integers', () => {5 fc.assert(6 fc.property(spyArrayInt64(), (array) => {7 expect(array).toBeInstanceOf(Array);8 expect(array.length).toBeGreaterThan(0);9 expect(array.every((v) => Number.isInteger(v))).toBe(true);10 expect(array.every((v) => v >= 0)).toBe(true);11 expect(array.every((v) => v <= 0xffffffff)).toBe(true);12 })13 );14 });15});16{17 "scripts": {18 },19 "devDependencies": {20 }21}22module.exports = {23 {24 },25};26 - name: Use Node.js ${{ matrix.node-version }}27 node-version: ${{ matrix.node-version }}

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const spyArrayInt64 = require("fast-check/lib/check/arbitrary/ArrayArbitrary.js");3const spyArrayInt64Spy = jest.spyOn(spyArrayInt64, "spyArrayInt64");4console.log(spyArrayInt64Spy);5const fc = require("fast-check");6const spyArrayInt64 = require("fast-check/lib/check/arbitrary/ArrayArbitrary.js");7const spyArrayInt64Spy = jest.spyOn(spyArrayInt64, "spyArrayInt64");8console.log(spyArrayInt64Spy);9const fc = require("fast-check");10const spyArrayInt64 = require("fast-check/lib/check/arbitrary/ArrayArbitrary.js");11const spyArrayInt64Spy = jest.spyOn(spyArrayInt64, "spyArrayInt64");12console.log(spyArrayInt64Spy);13const fc = require("fast-check");14const spyArrayInt64 = require("fast-check/lib/check/arbitrary/ArrayArbitrary.js");15const spyArrayInt64Spy = jest.spyOn(spyArrayInt64, "spyArrayInt64");16console.log(spyArrayInt64Spy);17const fc = require("fast-check");18const spyArrayInt64 = require("fast-check/lib/check/arbitrary/ArrayArbitrary.js");19const spyArrayInt64Spy = jest.spyOn(spyArrayInt64, "spyArrayInt64");20console.log(spyArrayInt64Spy);21const fc = require("fast-check");22const spyArrayInt64 = require("fast-check/lib/check/ar

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