How to use bigIntIndexPos method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

DoubleHelpers.spec.ts

Source:DoubleHelpers.spec.ts Github

copy

Full Screen

1import * as fc from 'fast-check';2import { float64raw, isStrictlySmaller } from '../../__test-helpers__/FloatingPointHelpers';3import {4 decomposeDouble,5 doubleToIndex,6 indexToDouble,7} from '../../../../../src/arbitrary/_internals/helpers/DoubleHelpers';8type Index = ReturnType<typeof doubleToIndex>;9const toIndex = (raw: bigint | string): Index => {10 const b = typeof raw === 'string' ? BigInt(raw) : raw;11 const pb = b < BigInt(0) ? -b : b;12 return { sign: b < BigInt(0) ? -1 : 1, data: [Number(pb >> BigInt(32)), Number(pb & BigInt(0xffffffff))] };13};14const toBigInt = (index: Index): bigint => {15 return BigInt(index.sign) * ((BigInt(index.data[0]) << BigInt(32)) + BigInt(index.data[1]));16};17describe('decomposeDouble', () => {18 it('should properly decompose basic values', () => {19 expect(decomposeDouble(0)).toEqual({ exponent: -1022, significand: 0 });20 expect(decomposeDouble(1)).toEqual({ exponent: 0, significand: 1 });21 expect(decomposeDouble(128)).toEqual({ exponent: 7, significand: 1 });22 expect(decomposeDouble(201)).toEqual({ exponent: 7, significand: 1.5703125 });23 });24 it('should properly decompose negative values', () => {25 expect(decomposeDouble(-0)).toEqual({ exponent: -1022, significand: -0 });26 expect(decomposeDouble(-1)).toEqual({ exponent: 0, significand: -1 });27 });28 it('should properly decompose extreme values', () => {29 expect(decomposeDouble(Number.MAX_VALUE)).toEqual({ exponent: 1023, significand: 2 - Number.EPSILON });30 expect(decomposeDouble(Number.MIN_VALUE)).toEqual({ exponent: -1022, significand: Number.EPSILON });31 expect(decomposeDouble(Number.EPSILON)).toEqual({ exponent: -52, significand: 1 });32 expect(decomposeDouble(1 + Number.EPSILON)).toEqual({ exponent: 0, significand: 1 + Number.EPSILON });33 });34 it('should decompose a 64-bit float into its equivalent (significand, exponent)', () => {35 fc.assert(36 fc.property(float64raw(), (f64) => {37 // Arrange38 fc.pre(!Number.isNaN(f64));39 // Act40 const { exponent, significand } = decomposeDouble(f64);41 // Assert42 expect(significand * 2 ** exponent).toBe(f64);43 })44 );45 });46});47describe('doubleToIndex', () => {48 it('should always produce well-formed indexes', () => {49 fc.assert(50 fc.property(float64raw(), (d) => {51 // Arrange52 fc.pre(!Number.isNaN(d));53 // Act54 const index = doubleToIndex(d);55 // Assert56 expect(index.data[0]).toBeGreaterThanOrEqual(0);57 expect(index.data[0]).toBeLessThanOrEqual(0xffffffff);58 expect(Number.isInteger(index.data[0])).toBe(true);59 expect(index.data[1]).toBeGreaterThanOrEqual(0);60 expect(index.data[1]).toBeLessThanOrEqual(0xffffffff);61 expect(Number.isInteger(index.data[1])).toBe(true);62 })63 );64 });65 if (typeof BigInt === 'undefined') {66 it('no test', () => {67 expect(true).toBe(true);68 });69 return;70 } // Following tests require BigInt to be launched71 it('should properly compute indexes', () => {72 expect(doubleToIndex(0)).toEqual(toIndex('0'));73 expect(doubleToIndex(Number.MIN_VALUE)).toEqual(toIndex('1'));74 expect(doubleToIndex(2 * Number.MIN_VALUE)).toEqual(toIndex('2'));75 expect(doubleToIndex(3 * Number.MIN_VALUE)).toEqual(toIndex('3'));76 // Last double with minimal exponent, ie -102277 // index(last with min exponent) = 2**53 - 178 expect(doubleToIndex(2 ** -1022 * (2 - Number.EPSILON))).toEqual(toIndex('9007199254740991'));79 // First double without minimal exponent, ie -102280 // index(first without min exponent) = index(last with min exponent) + 181 expect(doubleToIndex(2 ** -1021)).toEqual(toIndex('9007199254740992'));82 // Number.EPSILON === 1. * 2**-52 --> m = 1, e = -5283 // index(Number.EPSILON) = 2**53 + (-52 - (-1022) -1) * 2**5284 expect(doubleToIndex(Number.EPSILON)).toEqual(toIndex('4372995238176751616'));85 // index(1 - Number.EPSILON / 2) = index(1) - 186 expect(doubleToIndex(1 - Number.EPSILON / 2)).toEqual(toIndex('4607182418800017407'));87 // 1 === 1. * 2**0 --> m = 1, e = 088 // index(1) = 2**53 + (0 - (-1022) -1) * 2**5289 expect(doubleToIndex(1)).toEqual(toIndex('4607182418800017408'));90 // index(1 + Number.EPSILON) = index(1) + 191 expect(doubleToIndex(1 + Number.EPSILON)).toEqual(toIndex('4607182418800017409'));92 // index(2 - Number.EPSILON) = index(2) - 1 = index(1 + (2 ** 52 - 1) * Number.EPSILON)93 expect(doubleToIndex(2 - Number.EPSILON)).toEqual(toIndex('4611686018427387903'));94 // 1 === 1. * 2**1 --> m = 1, e = 195 // index(2) = index(1) + 2**5296 expect(doubleToIndex(2)).toEqual(toIndex('4611686018427387904'));97 // Number.MAX_VALUE === (1 + (2**52-1)/2**52) * 2**1023 --> m = 1 + (2**52-1)/2**52, e = 102398 // index(Number.MAX_VALUE) = index(next(Number.MAX_VALUE)) -1 = 2**53 + (1024 - (-1022) -1) * 2**52 -199 expect(doubleToIndex(Number.MAX_VALUE)).toEqual(toIndex('9218868437227405311'));100 });101 it('should properly compute negative indexes', () => {102 expect(doubleToIndex(-0)).toEqual(toIndex('-1'));103 expect(doubleToIndex(-Number.MIN_VALUE)).toEqual(toIndex('-2'));104 expect(doubleToIndex(-Number.MAX_VALUE)).toEqual(toIndex('-9218868437227405312'));105 });106 it('should properly compute indexes for infinity', () => {107 expect(doubleToIndex(Number.NEGATIVE_INFINITY)).toEqual(108 toIndex(toBigInt(doubleToIndex(-Number.MAX_VALUE)) - BigInt(1))109 );110 expect(doubleToIndex(Number.POSITIVE_INFINITY)).toEqual(111 toIndex(toBigInt(doubleToIndex(Number.MAX_VALUE)) + BigInt(1))112 );113 });114 it('should be able to infer index for negative double from the positive one', () => {115 fc.assert(116 fc.property(float64raw(), (d) => {117 // Arrange118 fc.pre(!Number.isNaN(d));119 const posD = d > 0 || 1 / d > 0 ? d : -d;120 // Act121 const bigIntIndexPos = toBigInt(doubleToIndex(posD));122 const bigIntIndexNeg = toBigInt(doubleToIndex(-posD));123 // Assert124 expect(bigIntIndexNeg).toEqual(-bigIntIndexPos - BigInt(1));125 })126 );127 });128 it('should return index +1 for the successor of a given double', () => {129 fc.assert(130 fc.property(131 fc.integer({ min: -1022, max: +1023 }),132 fc.integer({ min: 0, max: 2 ** 53 - 1 }),133 (exponent, rescaledSignificand) => {134 // Arrange135 fc.pre(exponent === -1022 || rescaledSignificand >= 2 ** 52); // valid136 fc.pre(exponent !== 1023 || rescaledSignificand !== 2 ** 53 - 1); // not max137 const current = rescaledSignificand * Number.EPSILON * 2 ** exponent;138 const next = (rescaledSignificand + 1) * Number.EPSILON * 2 ** exponent;139 // Act140 const bigIntIndexCurrent = toBigInt(doubleToIndex(current));141 const bigIntIndexNext = toBigInt(doubleToIndex(next));142 // Assert143 expect(bigIntIndexNext).toEqual(bigIntIndexCurrent + BigInt(1));144 }145 )146 );147 });148 it('should preserve ordering between two doubles', () => {149 fc.assert(150 fc.property(float64raw(), float64raw(), (fa64, fb64) => {151 // Arrange152 fc.pre(!Number.isNaN(fa64) && !Number.isNaN(fb64));153 // Act / Assert154 if (isStrictlySmaller(fa64, fb64)) {155 expect(toBigInt(doubleToIndex(fa64))).toBeLessThan(toBigInt(doubleToIndex(fb64)));156 } else {157 expect(toBigInt(doubleToIndex(fa64))).toBeGreaterThanOrEqual(toBigInt(doubleToIndex(fb64)));158 }159 })160 );161 });162});163describe('indexToDouble', () => {164 it('Should reverse doubleToIndex', () =>165 fc.assert(166 fc.property(float64raw(), (f64) => {167 fc.pre(!Number.isNaN(f64));168 expect(indexToDouble(doubleToIndex(f64))).toBe(f64);169 })170 ));171 if (typeof BigInt === 'undefined') {172 it('no test', () => {173 expect(true).toBe(true);174 });175 return;176 } // Following tests require BigInt to be launched177 it('should properly find doubles corresponding to well-known values', () => {178 expect(indexToDouble(toIndex('-9218868437227405313'))).toBe(Number.NEGATIVE_INFINITY);179 expect(indexToDouble(toIndex('-9218868437227405312'))).toBe(-Number.MAX_VALUE);180 expect(indexToDouble(toIndex('-1'))).toBe(-0);181 expect(indexToDouble(toIndex('0'))).toBe(0);182 expect(indexToDouble(toIndex('4372995238176751616'))).toBe(Number.EPSILON);183 expect(indexToDouble(toIndex('9218868437227405311'))).toBe(Number.MAX_VALUE);184 expect(indexToDouble(toIndex('9218868437227405312'))).toBe(Number.POSITIVE_INFINITY);185 });186 it('should be reversed by doubleToIndex', () => {187 fc.assert(188 fc.property(189 fc.bigInt({ min: BigInt('-9218868437227405313'), max: BigInt('9218868437227405312') }),190 (bigIntIndex) => {191 // The test below checks that indexToDouble(doubleToIndex) is identity192 // It does not confirm that doubleToIndex(indexToDouble)) is identity193 // Arrange194 const index = toIndex(bigIntIndex);195 // Act / Assert196 expect(doubleToIndex(indexToDouble(index))).toEqual(index);197 }198 )199 );200 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { bigIntIndexPos } from 'fast-check';2console.log(bigIntIndexPos(1n, 1n));3console.log(bigIntIndexPos(1n, 2n));4console.log(bigIntIndexPos(1n, 3n));5console.log(bigIntIndexPos(1n, 4n));6console.log(bigIntIndexPos(1n, 5n));7console.log(bigIntIndexPos(1n, 6n));8console.log(bigIntIndexPos(1n, 7n));9console.log(bigIntIndexPos(1n, 8n));10console.log(bigIntIndexPos(1n, 9n));11console.log(bigIntIndexPos(1n, 10n));12console.log(bigIntIndexPos(2n, 1n));13console.log(bigIntIndexPos(2n, 2n));14console.log(bigIntIndexPos(2n, 3n));15console.log(bigIntIndexPos(2n, 4n));16console.log(bigIntIndexPos(2n, 5n));17console.log(bigIntIndexPos(2n, 6n));18console.log(bigIntIndexPos(2n, 7n));19console.log(bigIntIndexPos(2n, 8n));20console.log(bigIntIndexPos(2n, 9n));21console.log(bigIntIndexPos(2n, 10n));22console.log(bigIntIndexPos(3n, 1n));23console.log(bigIntIndexPos(3n, 2n));24console.log(bigIntIndexPos(3n, 3n));25console.log(bigIntIndexPos(3n, 4n));26console.log(bigIntIndexPos(3n, 5n));27console.log(bigIntIndexPos(3n, 6n));28console.log(bigIntIndexPos(3n, 7n));29console.log(bigIntIndexPos(3n, 8n));30console.log(bigIntIndexPos(3n, 9n));31console.log(bigIntIndexPos(3n, 10n));32console.log(bigIntIndexPos(4n, 1n));33console.log(bigIntIndexPos(4n, 2n));34console.log(bigIntIndexPos(4n, 3n));35console.log(bigIntIndexPos(4

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const bigIntIndexPos = require('bigIntIndexPos');3const bigInt = fc.bigInt();4const bigIntIndexPos = bigIntIndexPos(bigInt);5fc.assert(6 fc.property(bigIntIndexPos, (index) => {7 })8const bigIntIndexPos = require('bigIntIndexPos');9bigIntIndexPos(bigInt)10const fc = require('fast-check');11const bigIntIndexPos = require('bigIntIndexPos');12const bigInt = fc.bigInt();13const bigIntIndexPos = bigIntIndexPos(bigInt);14fc.assert(15 fc.property(bigIntIndexPos, (index) => {16 })17const fc = require('fast-check');18const bigIntIndexPos = require('bigIntIndexPos');19const bigInt = fc.bigInt();20const bigIntIndexPos = bigIntIndexPos(bigInt);21fc.assert(22 fc.property(bigIntIndexPos, (index) => {23 expect(index).toBeGreaterThanOrEqual(0n);24 expect(index).toBeLessThanOrEqual(bigInt - 1n);25 })26Copyright (c) 2021, Samir El-Hajjaj

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const bigIntIndexPos = require('fast-check-monorepo/lib/bigIntIndexPos.js');3const bigIntIndexPosArb = fc.bigIntIndexPos();4const bigIntIndexPosArb2 = fc.bigIntIndexPos({min: -10n, max: 10n});5fc.assert(6 fc.property(bigIntIndexPosArb, (pos) => {7 return pos >= 0n;8 })9);10fc.assert(11 fc.property(bigIntIndexPosArb2, (pos) => {12 return pos >= -10n && pos <= 10n;13 })14);15const bigIntIndexPosArb = fc.bigIntIndexPos();16const bigIntIndexPosArb2 = fc.bigIntIndexPos({min: -10n, max: 10n});17fc.assert(18 fc.property(fc.array(bigIntIndexPosArb), (arr) => {19 return arr.every((pos) => pos >= 0n);20 })21);22fc.assert(23 fc.property(fc.array(bigIntIndexPosArb2), (arr) => {24 return arr.every((pos) => pos >= -10n && pos <= 10n);25 })26);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { bigIntIndexPos } = require('fast-check');2const { bigInt } = require('fast-check');3const { sample } = require('fast-check');4const { integer } = require('fast-check');5const { assert } = require('chai');6const { bigIntN } = require('fast-check');7const { bigIntNIndexPos } = require('fast-check');8const { bigUintN } = require('fast-check');9const { bigUintNIndexPos } = require('fast-check');10const { bigUint } = require('fast-check');11const { bigUintIndexPos } = require('fast-check');12const { bigIntMax } = require('fast-check');13const { bigIntMaxIndexPos } = require('fast-check');14const { bigUintMax } = require('fast-check');15const { bigUintMaxIndexPos } = require('fast-check');16const { bigIntMin } = require('fast-check');17const { bigIntMinIndexPos } = require('fast-check');18const { bigUintMin } = require('fast-check');19const { bigUintMinIndexPos } = require('fast-check');20const { bigInt64 } = require('fast-check');21const { bigInt64IndexPos } = require('fast-check');22const { bigUint64 } = require('fast-check');23const { bigUint64IndexPos } = require('fast-check');24const { bigInt32 } = require('fast-check');25const { bigInt32IndexPos } = require('fast-check');26const { bigUint32 } = require('fast-check');27const { bigUint32IndexPos } = require('fast-check');28const { bigInt16 } = require('fast-check');29const { bigInt16IndexPos } = require('fast-check');30const { bigUint16 } = require('fast-check');31const { bigUint16IndexPos } = require('fast-check');32const { bigInt8 } = require('fast-check');33const { bigInt8IndexPos } = require('fast-check');34const { bigUint8 } = require('fast-check');35const { bigUint8IndexPos } = require('fast-check');36const { bigIntMinN } = require('fast-check');37const { bigIntMinNIndexPos } = require('fast-check');38const { bigUintMinN } = require('fast-check');39const { bigUintMinNIndexPos }

Full Screen

Using AI Code Generation

copy

Full Screen

1const fastCheck = require('fast-check');2const bigIntIndexPos = require('bigIntIndexPos');3bigIntIndexPos(fastCheck);4module.exports = bigIntIndexPos;5const fastCheck = require('fast-check');6const bigIntIndexPos = require('bigIntIndexPos');7bigIntIndexPos(fastCheck);8module.exports = bigIntIndexPos;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { bigIntIndexPos } = require('fast-check-monorepo')2const { array, bigInt, constantFrom, property } = require('fast-check')3describe('bigIntIndexPos', () => {4 it('should return the position of the index of the provided value', () => {5 property(6 array(bigInt()),7 bigInt(),8 (array, value) => {9 const index = array.indexOf(value)10 return index === -1 ? true : bigIntIndexPos(array, value) === index11 }12 ).check()13 })14})15const { bigIntIndexPos } = require('fast-check-monorepo')16const { array, bigInt, constantFrom, property } = require('fast-check')17describe('bigIntIndexPos', () => {18 it('should return the position of the index of the provided value', () => {19 property(20 array(bigInt()),21 bigInt(),22 (array, value) => {23 const index = array.indexOf(value)24 return index === -1 ? true : bigIntIndexPos(array, value) === index25 }26 ).check()27 })28})29const { bigIntIndexPos } = require('fast-check-monorepo')30const { array, bigInt, constantFrom, property } = require('fast-check')31describe('bigIntIndexPos', () => {32 it('should return the position of the index of the provided value', () => {33 property(34 array(bigInt()),35 bigInt(),36 (array, value) => {37 const index = array.indexOf(value)38 return index === -1 ? true : bigIntIndexPos(array, value) === index39 }40 ).check()41 })42})43const { bigIntIndexPos } = require('fast-check-monorepo')44const { array, bigInt, constantFrom, property } = require('fast-check')

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const bigIntIndexPos = require('fast-check-monorepo').bigIntIndexPos;3const array = [1n, 2n, 3n, 4n, 5n, 6n, 7n, 8n, 9n, 10n];4const toFind = 5n;5const index = bigIntIndexPos(array, toFind);6console.log(index);7const arrayArb = fc.array(fc.bigInt(), 1, 20)8 .map(arr => arr.sort((a, b) => a - b));9const toFindArb = fc.bigInt();10fc.assert(11 fc.property(arrayArb, toFindArb, (arr, toFind) => {12 const index = bigIntIndexPos(arr, toFind);13 if (index === -1) {14 return !arr.includes(toFind);15 }16 return arr[index] === toFind;17 })18);19const bigIntIndexPos = require('fast-check-monorepo').bigIntIndexPos;20test('bigIntIndexPos', () => {21 const array = [1n, 2n, 3n, 4n, 5n, 6n, 7n, 8n, 9n, 10n];22 const toFind = 5n;23 const index = bigIntIndexPos(array, toFind);24 expect(index).toBe(4);25});

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