How to use toArrayInt64 method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

ArrayInt64Arbitrary.spec.ts

Source:ArrayInt64Arbitrary.spec.ts Github

copy

Full Screen

...31 fc.boolean(),32 (a, b, c, negMin, negMax) => {33 // Arrange34 const [min, mid, max] = [a, b, c].sort((a, b) => Number(a - b));35 const min64 = toArrayInt64(min, negMin);36 const mid64 = toArrayInt64(mid, false);37 const max64 = toArrayInt64(max, negMax);38 const { instance: mrng, nextArrayInt, nextInt } = fakeRandom();39 nextArrayInt.mockReturnValueOnce(mid64);40 // Act41 const arb = arrayInt64(min64, max64);42 const out = arb.generate(mrng, undefined);43 // Assert44 expect(out.value).toBe(mid64);45 expect(nextArrayInt).toHaveBeenCalledTimes(1);46 expect(nextArrayInt).toHaveBeenCalledWith(min64, max64);47 expect(nextInt).not.toHaveBeenCalled();48 }49 )50 );51 });52 it('should always consider the full range when bias should not apply', () => {53 fc.assert(54 fc.property(55 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),56 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),57 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),58 fc.boolean(),59 fc.boolean(),60 fc.integer({ min: 2 }),61 (a, b, c, negMin, negMax, biasFactor) => {62 // Arrange63 const [min, mid, max] = [a, b, c].sort((a, b) => Number(a - b));64 const min64 = toArrayInt64(min, negMin);65 const mid64 = toArrayInt64(mid, false);66 const max64 = toArrayInt64(max, negMax);67 const { instance: mrng, nextArrayInt, nextInt } = fakeRandom();68 nextArrayInt.mockReturnValueOnce(mid64);69 nextInt.mockImplementationOnce((low, _high) => low + 1); // >low is no bias case70 // Act71 const arb = arrayInt64(min64, max64);72 const out = arb.generate(mrng, biasFactor);73 // Assert74 expect(out.value).toBe(mid64);75 expect(nextArrayInt).toHaveBeenCalledTimes(1);76 expect(nextArrayInt).toHaveBeenCalledWith(min64, max64);77 expect(nextInt).toHaveBeenCalledTimes(1);78 expect(nextInt).toHaveBeenCalledWith(1, biasFactor);79 }80 )81 );82 });83 it('should consider sub-ranges when bias applies', () => {84 fc.assert(85 fc.property(86 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),87 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),88 fc.boolean(),89 fc.boolean(),90 fc.integer({ min: 2 }),91 fc.nat(),92 (a, b, negMin, negMax, biasFactor, r) => {93 // Arrange94 const [min, max] = a < b ? [a, b] : [b, a];95 fc.pre(max - min >= BigInt(100)); // large enough range (arbitrary value)96 const min64 = toArrayInt64(min, negMin);97 const max64 = toArrayInt64(max, negMax);98 const { instance: mrng, nextArrayInt, nextInt } = fakeRandom();99 nextArrayInt.mockImplementationOnce((low, _high) => low);100 nextInt101 .mockImplementationOnce((low, _high) => low) // low is bias case for first call102 .mockImplementationOnce((low, high) => low + (r % (high - low + 1))); // random inside the provided range (bias selection step)103 // Act104 const arb = arrayInt64(min64, max64);105 arb.generate(mrng, biasFactor);106 // Assert107 expect(nextInt).toHaveBeenCalledTimes(2);108 expect(nextArrayInt).toHaveBeenCalledTimes(1);109 expect(nextArrayInt).not.toHaveBeenCalledWith(min64, max64);110 const receivedMin = toBigInt(nextArrayInt.mock.calls[0][0] as ArrayInt64);111 const receivedMax = toBigInt(nextArrayInt.mock.calls[0][1] as ArrayInt64);112 expect(receivedMin).toBeGreaterThanOrEqual(min);113 expect(receivedMin).toBeLessThanOrEqual(max);114 expect(receivedMax).toBeGreaterThanOrEqual(min);115 expect(receivedMax).toBeLessThanOrEqual(max);116 }117 )118 );119 });120 });121 describe('canShrinkWithoutContext', () => {122 it('should recognize any value it could have generated', () => {123 fc.assert(124 fc.property(125 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),126 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),127 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),128 fc.boolean(),129 fc.boolean(),130 fc.boolean(),131 (a, b, c, negMin, negMid, negMax) => {132 // Arrange133 const [min, mid, max] = [a, b, c].sort((a, b) => Number(a - b));134 // Act135 const arb = arrayInt64(toArrayInt64(min, negMin), toArrayInt64(max, negMax));136 const out = arb.canShrinkWithoutContext(toArrayInt64(mid, negMid));137 // Assert138 expect(out).toBe(true);139 }140 )141 );142 });143 it('should reject values outside of its range', () => {144 fc.assert(145 fc.property(146 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),147 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),148 fc.bigInt(MinArrayIntValue, MaxArrayIntValue),149 fc.boolean(),150 fc.boolean(),151 fc.boolean(),152 fc.constantFrom(...(['lower', 'higher'] as const)),153 (a, b, c, negMin, negSelected, negMax, type) => {154 // Arrange155 const sorted = [a, b, c].sort((a, b) => Number(a - b));156 const [min, max, selected] =157 type === 'lower' ? [sorted[1], sorted[2], sorted[0]] : [sorted[0], sorted[1], sorted[2]];158 fc.pre(selected < min || selected > max);159 // Act160 const arb = arrayInt64(toArrayInt64(min, negMin), toArrayInt64(max, negMax));161 const out = arb.canShrinkWithoutContext(toArrayInt64(selected, negSelected));162 // Assert163 expect(out).toBe(false);164 }165 )166 );167 });168 });169 describe('shrink', () => {170 it('should shrink strictly positive value for positive range including zero', () => {171 // Arrange172 const arb = arrayInt64({ sign: 1, data: [0, 0] }, { sign: 1, data: [0, 10] });173 const source = new Value({ sign: 1, data: [0, 8] }, undefined); // no context174 // Act175 const tree = buildShrinkTree(arb, source);176 const renderedTree = renderTree(tree).join('\n');177 // Assert178 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);179 // When there is no more option, the shrinker retry one time with the value180 // current-1 to check if something that changed outside (another value not itself)181 // may have changed the situation182 expect(renderedTree).toMatchInlineSnapshot(`183 "{"sign":1,"data":[0,8]}184 ├> {"sign":1,"data":[0,0]}185 ├> {"sign":1,"data":[0,4]}186 | ├> {"sign":1,"data":[0,2]}187 | | └> {"sign":1,"data":[0,1]}188 | | └> {"sign":1,"data":[0,0]}189 | └> {"sign":1,"data":[0,3]}190 | └> {"sign":1,"data":[0,2]}191 | ├> {"sign":1,"data":[0,0]}192 | └> {"sign":1,"data":[0,1]}193 | └> {"sign":1,"data":[0,0]}194 ├> {"sign":1,"data":[0,6]}195 | └> {"sign":1,"data":[0,5]}196 | └> {"sign":1,"data":[0,4]}197 | ├> {"sign":1,"data":[0,0]}198 | ├> {"sign":1,"data":[0,2]}199 | | └> {"sign":1,"data":[0,1]}200 | | └> {"sign":1,"data":[0,0]}201 | └> {"sign":1,"data":[0,3]}202 | └> {"sign":1,"data":[0,2]}203 | ├> {"sign":1,"data":[0,0]}204 | └> {"sign":1,"data":[0,1]}205 | └> {"sign":1,"data":[0,0]}206 └> {"sign":1,"data":[0,7]}207 └> {"sign":1,"data":[0,6]}208 ├> {"sign":1,"data":[0,0]}209 ├> {"sign":1,"data":[0,3]}210 | └> {"sign":1,"data":[0,2]}211 | └> {"sign":1,"data":[0,1]}212 | └> {"sign":1,"data":[0,0]}213 └> {"sign":1,"data":[0,5]}214 └> {"sign":1,"data":[0,4]}215 └> {"sign":1,"data":[0,3]}216 ├> {"sign":1,"data":[0,0]}217 └> {"sign":1,"data":[0,2]}218 └> {"sign":1,"data":[0,1]}219 └> {"sign":1,"data":[0,0]}"220 `);221 });222 it('should shrink strictly positive value for range not including zero', () => {223 // Arrange224 const arb = arrayInt64({ sign: 1, data: [1, 10] }, { sign: 1, data: [1, 20] });225 const source = new Value({ sign: 1, data: [1, 18] }, undefined); // no context226 // Act227 const tree = buildShrinkTree(arb, source);228 const renderedTree = renderTree(tree).join('\n');229 // Assert230 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);231 // As the range [[1,10], [1,20]] and the value [1,18]232 // are just offset by +[1,10] compared to the first case,233 // the rendered tree will be offset by [1,10] too234 expect(renderedTree).toMatchInlineSnapshot(`235 "{"sign":1,"data":[1,18]}236 ├> {"sign":1,"data":[1,10]}237 ├> {"sign":1,"data":[1,14]}238 | ├> {"sign":1,"data":[1,12]}239 | | └> {"sign":1,"data":[1,11]}240 | | └> {"sign":1,"data":[1,10]}241 | └> {"sign":1,"data":[1,13]}242 | └> {"sign":1,"data":[1,12]}243 | ├> {"sign":1,"data":[1,10]}244 | └> {"sign":1,"data":[1,11]}245 | └> {"sign":1,"data":[1,10]}246 ├> {"sign":1,"data":[1,16]}247 | └> {"sign":1,"data":[1,15]}248 | └> {"sign":1,"data":[1,14]}249 | ├> {"sign":1,"data":[1,10]}250 | ├> {"sign":1,"data":[1,12]}251 | | └> {"sign":1,"data":[1,11]}252 | | └> {"sign":1,"data":[1,10]}253 | └> {"sign":1,"data":[1,13]}254 | └> {"sign":1,"data":[1,12]}255 | ├> {"sign":1,"data":[1,10]}256 | └> {"sign":1,"data":[1,11]}257 | └> {"sign":1,"data":[1,10]}258 └> {"sign":1,"data":[1,17]}259 └> {"sign":1,"data":[1,16]}260 ├> {"sign":1,"data":[1,10]}261 ├> {"sign":1,"data":[1,13]}262 | └> {"sign":1,"data":[1,12]}263 | └> {"sign":1,"data":[1,11]}264 | └> {"sign":1,"data":[1,10]}265 └> {"sign":1,"data":[1,15]}266 └> {"sign":1,"data":[1,14]}267 └> {"sign":1,"data":[1,13]}268 ├> {"sign":1,"data":[1,10]}269 └> {"sign":1,"data":[1,12]}270 └> {"sign":1,"data":[1,11]}271 └> {"sign":1,"data":[1,10]}"272 `);273 });274 it('should shrink strictly negative value for negative range including zero', () => {275 // Arrange276 const arb = arrayInt64({ sign: -1, data: [0, 10] }, { sign: 1, data: [0, 0] });277 const source = new Value({ sign: -1, data: [0, 8] }, undefined); // no context278 // Act279 const tree = buildShrinkTree(arb, source);280 const renderedTree = renderTree(tree).join('\n');281 // Assert282 expect(arb.canShrinkWithoutContext(source.value)).toBe(true);283 // As the range [-10, 0] and the value -8284 // are the opposite of first case, the rendered tree will be the same except285 // it contains opposite values286 expect(renderedTree).toMatchInlineSnapshot(`287 "{"sign":-1,"data":[0,8]}288 ├> {"sign":1,"data":[0,0]}289 ├> {"sign":-1,"data":[0,4]}290 | ├> {"sign":-1,"data":[0,2]}291 | | └> {"sign":-1,"data":[0,1]}292 | | └> {"sign":1,"data":[0,0]}293 | └> {"sign":-1,"data":[0,3]}294 | └> {"sign":-1,"data":[0,2]}295 | ├> {"sign":1,"data":[0,0]}296 | └> {"sign":-1,"data":[0,1]}297 | └> {"sign":1,"data":[0,0]}298 ├> {"sign":-1,"data":[0,6]}299 | └> {"sign":-1,"data":[0,5]}300 | └> {"sign":-1,"data":[0,4]}301 | ├> {"sign":1,"data":[0,0]}302 | ├> {"sign":-1,"data":[0,2]}303 | | └> {"sign":-1,"data":[0,1]}304 | | └> {"sign":1,"data":[0,0]}305 | └> {"sign":-1,"data":[0,3]}306 | └> {"sign":-1,"data":[0,2]}307 | ├> {"sign":1,"data":[0,0]}308 | └> {"sign":-1,"data":[0,1]}309 | └> {"sign":1,"data":[0,0]}310 └> {"sign":-1,"data":[0,7]}311 └> {"sign":-1,"data":[0,6]}312 ├> {"sign":1,"data":[0,0]}313 ├> {"sign":-1,"data":[0,3]}314 | └> {"sign":-1,"data":[0,2]}315 | └> {"sign":-1,"data":[0,1]}316 | └> {"sign":1,"data":[0,0]}317 └> {"sign":-1,"data":[0,5]}318 └> {"sign":-1,"data":[0,4]}319 └> {"sign":-1,"data":[0,3]}320 ├> {"sign":1,"data":[0,0]}321 └> {"sign":-1,"data":[0,2]}322 └> {"sign":-1,"data":[0,1]}323 └> {"sign":1,"data":[0,0]}"324 `);325 });326 });327});328describe('arrayInt64 (integration)', () => {329 if (typeof BigInt === 'undefined') {330 it('no test', () => {331 expect(true).toBe(true);332 });333 return;334 }335 type Extra = { min: bigint; max: bigint };336 const MaxArrayIntValue = BigInt(2) ** BigInt(64) - BigInt(1);337 const extraParameters: fc.Arbitrary<Extra> = fc338 .tuple(339 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),340 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue })341 )342 .map((vs) => ({343 min: vs[0] <= vs[1] ? vs[0] : vs[1],344 max: vs[0] <= vs[1] ? vs[1] : vs[0],345 }));346 const isCorrect = (v: ArrayInt64, extra: Extra) => {347 if (!isValidArrayInt(v)) {348 return false;349 }350 const vbg = toBigInt(v);351 if (vbg === BigInt(0) && v.sign === -1) {352 return false; // zero is always supposed to be marked with sign 1353 }354 return extra.min <= vbg && vbg <= extra.max;355 };356 const isStrictlySmaller = (v1: ArrayInt64, v2: ArrayInt64) => {357 const vbg1 = toBigInt(v1);358 const vbg2 = toBigInt(v2);359 const absVbg1 = vbg1 < BigInt(0) ? -vbg1 : vbg1;360 const absVbg2 = vbg2 < BigInt(0) ? -vbg2 : vbg2;361 return absVbg1 < absVbg2;362 };363 const arrayInt64Builder = (extra: Extra) =>364 arrayInt64(toArrayInt64(extra.min, false), toArrayInt64(extra.max, false));365 it('should produce the same values given the same seed', () => {366 assertProduceSameValueGivenSameSeed(arrayInt64Builder, { extraParameters });367 });368 it('should only produce correct values', () => {369 assertProduceCorrectValues(arrayInt64Builder, isCorrect, { extraParameters });370 });371 it('should produce values seen as shrinkable without any context', () => {372 assertProduceValuesShrinkableWithoutContext(arrayInt64Builder, { extraParameters });373 });374 it('should be able to shrink to the same values without initial context', () => {375 assertShrinkProducesSameValueWithoutInitialContext(arrayInt64Builder, { extraParameters });376 });377 it('should preserve strictly smaller ordering in shrink', () => {378 assertShrinkProducesStrictlySmallerValue(arrayInt64Builder, isStrictlySmaller, { extraParameters });379 });380});381// Helpers382function toArrayInt64(b: bigint, withNegativeZero: boolean): ArrayInt64 {383 const posB = b < BigInt(0) ? -b : b;384 return {385 sign: b < BigInt(0) || (withNegativeZero && b === BigInt(0)) ? -1 : 1,386 data: [Number(posB >> BigInt(32)), Number(posB & ((BigInt(1) << BigInt(32)) - BigInt(1)))],387 };388}389function toBigInt(a: ArrayInt64): bigint {390 return BigInt(a.sign) * ((BigInt(a.data[0]) << BigInt(32)) + BigInt(a.data[1]));391}392function isValidArrayInt(a: ArrayInt64): boolean {393 return (394 (a.sign === 1 || a.sign === -1) &&395 a.data[0] >= 0 &&396 a.data[0] <= 0xffffffff &&...

Full Screen

Full Screen

ArrayInt64.spec.ts

Source:ArrayInt64.spec.ts Github

copy

Full Screen

...8 logLike64,9 negative64,10 substract64,11} from '../../../../../src/arbitrary/_internals/helpers/ArrayInt64';12function toArrayInt64(b: bigint, withNegativeZero: boolean): ArrayInt64 {13 const posB = b < BigInt(0) ? -b : b;14 return {15 sign: b < BigInt(0) || (withNegativeZero && b === BigInt(0)) ? -1 : 1,16 data: [Number(posB >> BigInt(32)), Number(posB & ((BigInt(1) << BigInt(32)) - BigInt(1)))],17 };18}19function toBigInt(a: ArrayInt64): bigint {20 return BigInt(a.sign) * ((BigInt(a.data[0]) << BigInt(32)) + BigInt(a.data[1]));21}22function expectValidArrayInt(a: ArrayInt64): void {23 expect([-1, 1]).toContain(a.sign);24 expect(a.data[0]).toBeGreaterThanOrEqual(0);25 expect(a.data[0]).toBeLessThanOrEqual(0xffffffff);26 expect(a.data[1]).toBeGreaterThanOrEqual(0);27 expect(a.data[1]).toBeLessThanOrEqual(0xffffffff);28}29function expectValidZeroIfAny(a: ArrayInt64): void {30 if (a.data[0] === 0 && a.data[1] === 0) {31 expect(a.sign).toBe(1);32 }33}34describe('ArrayInt64', () => {35 if (typeof BigInt === 'undefined') {36 it('no test', () => {37 expect(true).toBe(true);38 });39 return;40 }41 const MaxArrayIntValue = (BigInt(1) << BigInt(64)) - BigInt(1);42 describe('isEqual64', () => {43 it('should consider identical values as equal', () => {44 fc.assert(45 fc.property(fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }), (a) => {46 // Arrange47 const a64 = toArrayInt64(a, false);48 const a64Cloned = toArrayInt64(a, false);49 // Act50 const out = isEqual64(a64, a64Cloned);51 // Assert52 expect(out).toBe(true);53 })54 );55 });56 it('should consider two different values as not equal', () => {57 fc.assert(58 fc.property(59 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),60 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),61 fc.boolean(),62 fc.boolean(),63 (a, b, na, nb) => {64 // Arrange65 fc.pre(a !== b);66 const a64 = toArrayInt64(a, na);67 const b64 = toArrayInt64(b, nb);68 // Act69 const out = isEqual64(a64, b64);70 // Assert71 expect(out).toBe(false);72 }73 )74 );75 });76 it('should consider zero and -zero to be equal', () => {77 expect(isEqual64({ sign: -1, data: [0, 0] }, { sign: -1, data: [0, 0] })).toBe(true);78 expect(isEqual64({ sign: 1, data: [0, 0] }, { sign: -1, data: [0, 0] })).toBe(true);79 expect(isEqual64({ sign: -1, data: [0, 0] }, { sign: 1, data: [0, 0] })).toBe(true);80 expect(isEqual64({ sign: 1, data: [0, 0] }, { sign: 1, data: [0, 0] })).toBe(true);81 });82 });83 describe('isStrictlySmaller64', () => {84 it('should properly compare two ArrayInt64 (including negative zeros)', () => {85 fc.assert(86 fc.property(87 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),88 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),89 fc.boolean(),90 fc.boolean(),91 (a, b, na, nb) => {92 // Arrange93 const a64 = toArrayInt64(a, na);94 const b64 = toArrayInt64(b, nb);95 // Act96 const out = isStrictlySmaller64(a64, b64);97 // Assert98 expect(out).toBe(a < b);99 }100 )101 );102 });103 it('should consider zero and -zero as equal values (never strictly smaller that the other)', () => {104 expect(isStrictlySmaller64({ sign: -1, data: [0, 0] }, { sign: -1, data: [0, 0] })).toBe(false);105 expect(isStrictlySmaller64({ sign: 1, data: [0, 0] }, { sign: -1, data: [0, 0] })).toBe(false);106 expect(isStrictlySmaller64({ sign: -1, data: [0, 0] }, { sign: 1, data: [0, 0] })).toBe(false);107 expect(isStrictlySmaller64({ sign: 1, data: [0, 0] }, { sign: 1, data: [0, 0] })).toBe(false);108 });109 });110 describe('substract64', () => {111 it('should properly substract two ArrayInt64 (including negative zeros)', () => {112 fc.assert(113 fc.property(114 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),115 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),116 fc.boolean(),117 fc.boolean(),118 (a, b, na, nb) => {119 // Arrange120 const expectedResult = a - b;121 fc.pre(expectedResult >= -MaxArrayIntValue);122 fc.pre(expectedResult <= MaxArrayIntValue);123 const a64 = toArrayInt64(a, na);124 const b64 = toArrayInt64(b, nb);125 // Act126 const result64 = substract64(a64, b64);127 // Assert128 expectValidArrayInt(result64);129 expectValidZeroIfAny(result64);130 expect(toBigInt(result64)).toBe(expectedResult);131 }132 )133 );134 });135 it('should equal to first term if second one is zero', () => {136 fc.assert(137 fc.property(138 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),139 fc.boolean(),140 fc.boolean(),141 (a, na, nb) => {142 // Arrange143 const a64 = toArrayInt64(a, na);144 const b64 = toArrayInt64(BigInt(0), nb);145 // Act146 const result64 = substract64(a64, b64);147 // Assert148 expectValidArrayInt(result64);149 expectValidZeroIfAny(result64);150 expect(result64).toEqual(toArrayInt64(a, false)); // toArrayInt64(a, false): sign must be + for 0151 }152 )153 );154 });155 it('should equal to minus second term if first one is zero', () => {156 fc.assert(157 fc.property(158 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),159 fc.boolean(),160 fc.boolean(),161 (a, na, nb) => {162 // Arrange163 const z64 = toArrayInt64(BigInt(0), nb);164 const a64 = toArrayInt64(a, na);165 // Act166 const result64 = substract64(z64, a64);167 // Assert168 expectValidArrayInt(result64);169 expectValidZeroIfAny(result64);170 expect(result64).toEqual(toArrayInt64(-a, false)); // toArrayInt64(-a, false): sign must be + for 0171 }172 )173 );174 });175 it('should equal to zero when substracting zeros', () => {176 const negZero: ArrayInt64 = { sign: -1, data: [0, 0] };177 const posZero: ArrayInt64 = { sign: 1, data: [0, 0] };178 expect(substract64(negZero, negZero)).toEqual(posZero);179 expect(substract64(negZero, posZero)).toEqual(posZero);180 expect(substract64(posZero, negZero)).toEqual(posZero);181 expect(substract64(posZero, posZero)).toEqual(posZero);182 });183 });184 describe('negative64', () => {185 it('should properly negate an ArrayInt64 (including negative zeros)', () => {186 fc.assert(187 fc.property(fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }), fc.boolean(), (a, na) => {188 // Arrange189 const expectedResult = -a;190 const a64 = toArrayInt64(a, na);191 // Act192 const result64 = negative64(a64);193 // Assert194 expectValidArrayInt(result64);195 expect(toBigInt(result64)).toBe(expectedResult);196 })197 );198 });199 });200 describe('add64', () => {201 it('should properly add two ArrayInt64 (including negative zeros)', () => {202 fc.assert(203 fc.property(204 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),205 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),206 fc.boolean(),207 fc.boolean(),208 (a, b, na, nb) => {209 // Arrange210 const expectedResult = a + b;211 fc.pre(expectedResult >= -MaxArrayIntValue);212 fc.pre(expectedResult <= MaxArrayIntValue);213 const a64 = toArrayInt64(a, na);214 const b64 = toArrayInt64(b, nb);215 // Act216 const result64 = add64(a64, b64);217 // Assert218 expectValidArrayInt(result64);219 expectValidZeroIfAny(result64);220 expect(toBigInt(result64)).toBe(expectedResult);221 }222 )223 );224 });225 it('should equal to first term if second one is zero', () => {226 fc.assert(227 fc.property(228 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),229 fc.boolean(),230 fc.boolean(),231 (a, na, nb) => {232 // Arrange233 const a64 = toArrayInt64(a, na);234 const z64 = toArrayInt64(BigInt(0), nb);235 // Act236 const result64 = add64(a64, z64);237 // Assert238 expectValidArrayInt(result64);239 expectValidZeroIfAny(result64);240 expect(result64).toEqual(toArrayInt64(a, false)); // toArrayInt64(a, false): sign must be + for 0241 }242 )243 );244 });245 it('should equal to second term if first one is zero', () => {246 fc.assert(247 fc.property(248 fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }),249 fc.boolean(),250 fc.boolean(),251 (a, na, nb) => {252 // Arrange253 const z64 = toArrayInt64(BigInt(0), nb);254 const a64 = toArrayInt64(a, na);255 // Act256 const result64 = add64(z64, a64);257 // Assert258 expectValidArrayInt(result64);259 expectValidZeroIfAny(result64);260 expect(result64).toEqual(toArrayInt64(a, false)); // toArrayInt64(a, false): sign must be + for 0261 }262 )263 );264 });265 it('should equal to zero when adding zeros together', () => {266 const negZero: ArrayInt64 = { sign: -1, data: [0, 0] };267 const posZero: ArrayInt64 = { sign: 1, data: [0, 0] };268 expect(add64(negZero, negZero)).toEqual(posZero);269 expect(add64(negZero, posZero)).toEqual(posZero);270 expect(add64(posZero, negZero)).toEqual(posZero);271 expect(add64(posZero, posZero)).toEqual(posZero);272 });273 });274 describe('halve64', () => {275 it('should properly halve an ArrayInt64 (including negative zeros)', () => {276 fc.assert(277 fc.property(fc.bigInt({ min: -MaxArrayIntValue, max: MaxArrayIntValue }), fc.boolean(), (a, na) => {278 // Arrange279 const expectedResult = a / BigInt(2);280 const a64 = toArrayInt64(a, na);281 // Act282 const result64 = halve64(a64);283 // Assert284 expectValidArrayInt(result64);285 expect(toBigInt(result64)).toBe(expectedResult);286 })287 );288 });289 });290 describe('logLike64', () => {291 it('should properly log2 an ArrayInt64', () => {292 fc.assert(293 fc.property(fc.bigInt({ min: BigInt(1), max: MaxArrayIntValue }), (a) => {294 // Arrange295 const expectedResult = Math.floor(Math.log(Number(a)) / Math.log(2));296 const a64 = toArrayInt64(a, false); // no negative zero: a > 0297 // Act298 const result64 = logLike64(a64);299 // Assert300 expectValidArrayInt(result64);301 expect(toBigInt(result64)).toBe(BigInt(expectedResult));302 })303 );304 });305 it('should properly log2 a negative ArrayInt64', () => {306 fc.assert(307 fc.property(fc.bigInt({ min: BigInt(1), max: MaxArrayIntValue }), (a) => {308 // Arrange309 const expectedResult = -Math.floor(Math.log(Number(a)) / Math.log(2));310 const a64 = toArrayInt64(-a, false); // no negative zero: a > 0311 // Act312 const result64 = logLike64(a64);313 // Assert314 expectValidArrayInt(result64);315 expect(toBigInt(result64)).toBe(BigInt(expectedResult));316 })317 );318 });319 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const {toArrayInt64} = require('fast-check-monorepo');3console.log(toArrayInt64([1,2,3,4,5,6,7,8,9,10]));4const fc = require('fast-check');5const {toArrayInt64} = require('fast-check-monorepo');6console.log(toArrayInt64([1,2,3,4,5,6,7,8,9,10]));7const fc = require('fast-check');8const {toArrayInt64} = require('fast-check-monorepo');9console.log(toArrayInt64([1,2,3,4,5,6,7,8,9,10]));10const fc = require('fast-check');11const {toArrayInt64} = require('fast-check-monorepo');12console.log(toArrayInt64([1,2,3,4,5,6,7,8,9,10]));13const fc = require('fast-check');14const {toArrayInt64} = require('fast-check-monorepo');15console.log(toArrayInt64([1,2,3,4,5,6,7,8,9,10]));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fc } = require('fast-check');2const { toArrayInt64 } = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.integer(), (i) => {5 const arr = toArrayInt64(i);6 const j = arr[0] + arr[1] * 2 ** 32;7 return i === j;8 }),9);

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1const { check, property, gen } = require('fast-check');2const { toArrayInt64 } = require('fast-check-monorepo');3const isSorted = (arr) => {4 for (let i = 1; i < arr.length; i++) {5 if (arr[i - 1] > arr[i]) {6 return false;7 }8 }9 return true;10};11check(property(gen.int64(), (n) => isSorted(toArrayInt64(n))), {12});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toArrayInt64 } = require('fast-check-monorepo')2const { Int64 } = require('fast-check')3const { Int32 } = require('fast-check')4const { array } = require('fast-check')5const { tuple } = require('fast-check')6const { property } = require('fast-check')7const { assert } = require('chai')8describe('toArrayInt64', () => {9 it('should convert Int64 to array of 2 Int32', () => {10 property(11 tuple(array(Int32()), array(Int32())),12 ([a, b]) => {13 const ia = Int64.fromArray([a, b])14 const [c, d] = toArrayInt64(ia)15 assert.equal(a, c)16 assert.equal(b, d)17 }18 })19})20const { toArrayInt64 } = require('fast-check-monorepo')21const { Int64 } = require('fast-check')22const { Int32 } = require('fast-check')23const { array } = require('fast-check')24const { tuple } = require('fast-check')25const { property } = require('fast-check')26const { assert } = require('chai')27describe('toArrayInt64', () => {28 it('should convert Int64 to array of 2 Int32', () => {29 property(30 tuple(array(Int32()), array(Int32())),31 ([a, b]) => {32 const ia = Int64.fromArray([a, b])33 const [c, d] = toArrayInt64(ia)34 assert.equal(a, c)35 assert.equal(b, d)36 }37 })38})39const { toArrayInt64 } = require('fast-check-monorepo')40const { Int64 } = require('fast-check')41const { Int32 } = require('fast-check')42const { array } = require('fast

Full Screen

Using AI Code Generation

copy

Full Screen

1var fc = require('fast-check');2var arr = fc.array(fc.integer());3var arrInt64 = arr.map(x => fc.convertToNext(x).toArrayInt64());4var arrInt64Size = arrInt64.map(x => x.length);5fc.assert(fc.property(arrInt64Size, x => x >= 0));6var fc = require('fast-check');7var arr = fc.array(fc.integer());8var arrInt64 = arr.map(x => fc.convertToNext(x).toArrayInt64());9var arrInt64Size = arrInt64.map(x => x.length);10fc.assert(fc.property(arrInt64Size, x => x >= 0));11var fc = require('fast-check');12var arr = fc.array(fc.integer());13var arrInt64 = arr.map(x => fc.convertToNext(x).toArrayInt64());14var arrInt64Size = arrInt64.map(x => x.length);15fc.assert(fc.property(arrInt64Size, x => x >= 0));16var fc = require('fast-check');17var arr = fc.array(fc.integer());18var arrInt64 = arr.map(x => fc.convertToNext(x).toArrayInt64());19var arrInt64Size = arrInt64.map(x => x.length);20fc.assert(fc.property(arrInt64Size, x => x >= 0));21var fc = require('fast-check');22var arr = fc.array(fc.integer());23var arrInt64 = arr.map(x => fc.convertToNext(x).toArrayInt64());24var arrInt64Size = arrInt64.map(x => x.length);25fc.assert(fc.property(arrInt64Size, x => x >= 0));26var fc = require('fast-check');27var arr = fc.array(fc.integer());28var arrInt64 = arr.map(x => fc.convertToNext(x).toArrayInt

Full Screen

Using AI Code Generation

copy

Full Screen

1const {array, integer} = require('fast-check');2const arrayArb = array(integer(0, 1000));3const int64Array = arrayArb.toArrayInt64();4console.log(int64Array);5const {array, integer} = require('fast-check');6const arrayArb = array(integer(0, 1000));7const int64Array = arrayArb.toArrayInt64();8console.log(int64Array);9const {array, integer} = require('fast-check');10const arrayArb = array(integer(0, 1000));11const int64Array = arrayArb.toArrayInt64();12console.log(int64Array);13const {array, integer} = require('fast-check');14const arrayArb = array(integer(0, 1000));15const int64Array = arrayArb.toArrayInt64();16console.log(int64Array);17const {array, integer} = require('fast-check');18const arrayArb = array(integer(0, 1000));19const int64Array = arrayArb.toArrayInt64();20console.log(int64Array);21const {array, integer} = require('fast-check');22const arrayArb = array(integer(0, 1000));23const int64Array = arrayArb.toArrayInt64();24console.log(int64Array);25const {array, integer} = require('fast-check');

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