Best JavaScript code snippet using fast-check-monorepo
ArrayInt64.spec.ts
Source:ArrayInt64.spec.ts
1import * as fc from 'fast-check';2import {3 add64,4 ArrayInt64,5 halve64,6 isEqual64,7 isStrictlySmaller64,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 });...
Using AI Code Generation
1const { a64Cloned } = require('fast-check-monorepo');2const { a64 } = require('fast-check');3const a64ClonedResult = a64Cloned();4const a64Result = a64();5console.log(a64ClonedResult);6console.log(a64Result);
Using AI Code Generation
1const {a64Cloned} = require('fast-check-monorepo');2test('a64Cloned', () => {3 fc.assert(4 fc.property(fc.array(fc.integer()), (arr) => {5 const cloned = a64Cloned(arr);6 expect(cloned).toEqual(arr);7 expect(cloned).not.toBe(arr);8 })9 );10});
Using AI Code Generation
1import { a64Cloned } from 'fast-check-monorepo';2const result = a64Cloned();3import { a64Cloned } from 'fast-check-monorepo';4const result = a64Cloned();5import { a64Cloned } from 'fast-check-monorepo';6const result = a64Cloned();7import { a64Cloned } from 'fast-check-monorepo';8const result = a64Cloned();9import { a64Cloned } from 'fast-check-monorepo';10const result = a64Cloned();11import { a64Cloned } from 'fast-check-monorepo';12const result = a64Cloned();13import { a64Cloned } from 'fast-check-monorepo';14const result = a64Cloned();15import { a64Cloned } from 'fast-check-monorepo';16const result = a64Cloned();17import { a64Cloned } from 'fast-check-monorepo';18const result = a64Cloned();
Using AI Code Generation
1const fc = require("fast-check");2const { a64Cloned } = require("fast-check-cloned");3const { a64 } = require("fast-check");4a64Cloned().forEach((v) => {5 console.log(v);6});7a64().forEach((v) => {8 console.log(v);9});10const fc = require("fast-check");11const { a64Cloned } = require("fast-check");12const { a64 } = require("fast-check");13a64Cloned().forEach((v) => {14 console.log(v);15});16a64().forEach((v) => {17 console.log(v);18});
Using AI Code Generation
1const a64Cloned = require('fast-check').a64Cloned;2console.log(a64Cloned(1,2));3const a64Cloned = require('fast-check').a64Cloned;4console.log(a64Cloned(1,2));5const a64Cloned = require('fast-check').a64Cloned;6console.log(a64Cloned(1,2));7const a64Cloned = require('fast-check').a64Cloned;8console.log(a64Cloned(1,2));9const a64Cloned = require('fast-check').a64Cloned;10console.log(a64Cloned(1,2));11const a64Cloned = require('fast-check').a64Cloned;12console.log(a64Cloned(1,2));13const a64Cloned = require('fast-check').a64Cloned;14console.log(a64Cloned(1,2));15const a64Cloned = require('fast-check').a64Cloned;16console.log(a64Cloned(1,2));17const a64Cloned = require('fast-check').a64Cloned;18console.log(a64Cloned(1,2));19const a64Cloned = require('fast-check').a64Cloned;20console.log(a64Cloned(1,2));21const a64Cloned = require('fast-check').a64Cloned;22console.log(a64Cloned(1,2));23const a64Cloned = require('fast-check').a64Cloned;24console.log(a64Cloned(1,
Using AI Code Generation
1const fc = require('fast-check');2const a64Cloned = require('fast-check-arbitrary-64bits');3const { a64 } = a64Cloned;4const a64Cloned = require('fast-check-arbitrary-64bits');5const { a64 } = a64Cloned;6fc.assert(7 fc.property(a64(), a64(), (a, b) => {8 return a + b >= a && a + b >= b;9 })10);11const fc = require('fast-check');12const a64Cloned = require('fast-check-arbitrary-64bits');13const { a64 } = a64Cloned;14const a64Cloned = require('fast-check-arbitrary-64bits');15const { a64 } = a64Cloned;16fc.assert(17 fc.property(a64(), a64(), (a, b) => {18 return a + b >= a && a + b >= b;19 })20);21const fc = require('fast-check');22const a64Cloned = require('fast-check-arbitrary-64bits');23const { a64 } = a64Cloned;24const a64Cloned = require('fast-check-arbitrary-64bits');25const { a64 } = a64Cloned;26fc.assert(27 fc.property(a64(), a64(), (a, b) => {28 return a + b >= a && a + b >= b;29 })30);31const fc = require('fast-check');32const a64Cloned = require('fast-check-arbitrary-64bits');33const { a64 } = a64Cloned;34const a64Cloned = require('fast-check-arbitrary-64bits');35const { a64 } = a64Cloned;36fc.assert(37 fc.property(a64(), a64(), (a, b) => {38 return a + b >= a && a + b >= b;39 })40);41const fc = require('fast-check');42const a64Cloned = require('fast-check
Using AI Code Generation
1const fc = require('fast-check');2const a64 = require('a64Cloned');3const { a64Cloned } = a64;4const { a64Cloned } = fc;5const { a64Cloned } = fc;6console.log(a64Cloned);7console.log(fc.a64Cloned);8console.log(a64Cloned);9console.log(fc.a64Cloned);10const fc = require('fast-check');11const a64 = require('a64Cloned');12const { a64Cloned } = a64;13const { a64Cloned } = fc;14console.log(a64Cloned);15console.log(fc.a64Cloned);16console.log(a64Cloned);17console.log(fc.a64Cloned);
Using AI Code Generation
1const fc = require('../fast-check-monorepo/lib');2const { a64Cloned } = fc;3const a = a64Cloned(1000);4const b = a64Cloned(1000);5const c = a64Cloned(1000);6fc.assert(7 fc.property(a, b, c, (a, b, c) => {8 return a + b === c;9 })10);11 throw err;12 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)13 at Function.Module._load (internal/modules/cjs/loader.js:562:25)14 at Module.require (internal/modules/cjs/loader.js:692:17)15 at require (internal/modules/cjs/helpers.js:25:18)16 at Object.<anonymous> (C:\Users\...\test.js:1:15)17 at Module._compile (internal/modules/cjs/loader.js:778:30)18 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)19 at Module.load (internal/modules/cjs/loader.js:653:32)20 at tryModuleLoad (internal/modules/cjs/loader.js:593:12)21 at Function.Module._load (internal/modules/cjs/loader.js:585:3)22 throw err;23 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)24 at Function.Module._load (internal/modules/cjs/loader.js:562:25)25 at Module.require (internal/modules/cjs/loader.js:692:17)26 at require (internal/modules/cjs/helpers.js
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!