How to use isStrictlyNegative64 method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

math.ts

Source:math.ts Github

copy

Full Screen

...106export function isZero64(a: ArrayInt64): boolean {107 return a.data[0] === 0 && a.data[1] === 0108}109/** @internal */110export function isStrictlyNegative64(a: ArrayInt64): boolean {111 return a.sign === -1 && !isZero64(a)112}113/** @internal */114export function isStrictlyPositive64(a: ArrayInt64): boolean {115 return a.sign === 1 && !isZero64(a)116}117/** @internal */118export function isEqual64(a: ArrayInt64, b: ArrayInt64): boolean {119 if (a.data[0] === b.data[0] && a.data[1] === b.data[1]) {120 return a.sign === b.sign || (a.data[0] === 0 && a.data[1] === 0) // either the same or both zero121 }122 return false123}124/** @internal */125function isStrictlySmaller64Internal(a: ArrayInt64['data'], b: ArrayInt64['data']): boolean {126 return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])127}128/** @internal */129export function isStrictlySmaller64(a: ArrayInt64, b: ArrayInt64): boolean {130 if (a.sign === b.sign) {131 return a.sign === 1132 ? isStrictlySmaller64Internal(a.data, b.data) // a.sign = +1, b.sign = +1133 : isStrictlySmaller64Internal(b.data, a.data) // a.sign = -1, b.sign = -1134 }135 // a.sign = +1, b.sign = -1 is always false136 return a.sign === -1 && (!isZero64(a) || !isZero64(b)) // a.sign = -1, b.sign = +1137}138/** @internal */139export function clone64(a: ArrayInt64): ArrayInt64 {140 return { sign: a.sign, data: [a.data[0], a.data[1]] }141}142/** @internal */143function substract64DataInternal(a: ArrayInt64['data'], b: ArrayInt64['data']): ArrayInt64['data'] {144 let reminderLow = 0145 let low = a[1] - b[1]146 if (low < 0) {147 reminderLow = 1148 low = low >>> 0149 }150 return [a[0] - b[0] - reminderLow, low]151}152/**153 * Expects a >= b154 * @internal155 */156function substract64Internal(a: ArrayInt64, b: ArrayInt64): ArrayInt64 {157 if (a.sign === 1 && b.sign === -1) {158 // Operation is a simple sum of a + abs(b)159 const low = a.data[1] + b.data[1]160 const high = a.data[0] + b.data[0] + (low > 0xffffffff ? 1 : 0)161 return { sign: 1, data: [high >>> 0, low >>> 0] }162 }163 // a.sign === -1 with b.sign === 1 is impossible given: a - b >= 0, except for a = 0 and b = 0164 // Operation is a substraction165 return {166 sign: 1,167 data: a.sign === 1 ? substract64DataInternal(a.data, b.data) : substract64DataInternal(b.data, a.data)168 }169}170/**171 * Substract two ArrayInt64172 * @returns When result is zero always with sign=1173 * @internal174 */175export function substract64(arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64 {176 if (isStrictlySmaller64(arrayIntA, arrayIntB)) {177 const out = substract64Internal(arrayIntB, arrayIntA)178 out.sign = -1179 return out180 }181 return substract64Internal(arrayIntA, arrayIntB)182}183/**184 * Negative version of an ArrayInt64185 * @internal186 */187export function negative64(arrayIntA: ArrayInt64): ArrayInt64 {188 return {189 sign: -arrayIntA.sign as -1 | 1,190 data: [arrayIntA.data[0], arrayIntA.data[1]]191 }192}193/**194 * Add two ArrayInt64195 * @returns When result is zero always with sign=1196 * @internal197 */198export function add64(arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64 {199 if (isZero64(arrayIntB)) {200 if (isZero64(arrayIntA)) {201 return clone64(Zero64)202 }203 return clone64(arrayIntA)204 }205 return substract64(arrayIntA, negative64(arrayIntB))206}207/**208 * Halve an ArrayInt64209 * @internal210 */211export function halve64(a: ArrayInt64): ArrayInt64 {212 return {213 sign: a.sign,214 data: [Math.floor(a.data[0] / 2), (a.data[0] % 2 === 1 ? 0x80000000 : 0) + Math.floor(a.data[1] / 2)]215 }216}217/**218 * Apply log2 to an ArrayInt64 (preserve sign)219 * @internal220 */221export function logLike64(a: ArrayInt64): ArrayInt64 {222 // Math.floor(Math.log(hi * 2**32 + low) / Math.log(2)) <= Math.floor(Math.log(2**64) / Math.log(2)) = 64223 return {224 sign: a.sign,225 data: [0, Math.floor(Math.log(a.data[0] * 0x100000000 + a.data[1]) / Math.log(2))]226 }227}228/** @internal */229const INDEX_POSITIVE_INFINITY: ArrayInt64 = { sign: 1, data: [2146435072, 0] } // doubleToIndex(Number.MAX_VALUE) + 1;230/** @internal */231const INDEX_NEGATIVE_INFINITY: ArrayInt64 = { sign: -1, data: [2146435072, 1] } // doubleToIndex(-Number.MAX_VALUE) - 1232/**233 * Decompose a 64-bit floating point number into a significand and exponent234 * such that:235 * - significand over 53 bits including sign (also referred as fraction)236 * - exponent over 11 bits including sign237 * - whenever there are multiple possibilities we take the one having the highest significand (in abs)238 * - Number.MAX_VALUE = 2**1023 * (1 + (2**52-1)/2**52)239 * = 2**1023 * (2 - Number.EPSILON)240 * - Number.MIN_VALUE = 2**(-1022) * 2**(-52)241 * - Number.EPSILON = 2**(-52)242 *243 * @param d - 64-bit floating point number to be decomposed into (significand, exponent)244 *245 * @internal246 */247export function decomposeDouble(d: number): { exponent: number, significand: number } {248 // 1 => significand 0b1 - exponent 1 (will be preferred)249 // => significand 0b0.1 - exponent 2250 const maxSignificand = 2 - Number.EPSILON251 for (let exponent = -1022; exponent !== 1024; ++exponent) {252 const powExponent = 2 ** exponent253 const maxForExponent = maxSignificand * powExponent254 if (Math.abs(d) <= maxForExponent) {255 return { exponent, significand: d / powExponent }256 }257 }258 return { exponent: Number.NaN, significand: Number.NaN }259}260/** @internal */261function positiveNumberToInt64(n: number): ArrayInt64['data'] {262 return [~~(n / 0x100000000), n >>> 0]263}264/** @internal */265function indexInDoubleFromDecomp(exponent: number, significand: number): ArrayInt64['data'] {266 // WARNING: significand >= 0267 // By construct of significand in decomposeDouble,268 // significand is always max-ed.269 // The double close to zero are the only one having a significand <1, they also have an exponent of -1022.270 // They are in range: [2**(-1022) * 2**(-52), 2**(-1022) * (2 - 2 ** 52)]271 // In other words there are 2**53 elements in that range if we include zero.272 // All other ranges (other exponents) have a length of 2**52 elements.273 if (exponent === -1022) {274 // We want the significand to be an integer value (like an index)275 const rescaledSignificand = significand * 2 ** 52 // significand * 2**52276 return positiveNumberToInt64(rescaledSignificand)277 }278 // Offset due to exp = -1022 + Offset of previous exp (excl. -1022) + Offset in current exp279 // 2**53 + (exponent - (-1022) -1) * 2**52 + (significand - 1) * 2**52280 // (exponent + 1023) * 2**52 + (significand - 1) * 2**52281 const rescaledSignificand = (significand - 1) * 2 ** 52 // (significand-1) * 2**52282 const exponentOnlyHigh = (exponent + 1023) * 2 ** 20 // (exponent + 1023) * 2**52 => [high: (exponent + 1023) * 2**20, low: 0]283 const index = positiveNumberToInt64(rescaledSignificand)284 index[0] += exponentOnlyHigh285 return index286}287/**288 * Compute the index of d relative to other available 64-bit floating point numbers289 * Rq: Produces negative indexes for negative doubles290 *291 * @param d - 64-bit floating point number, anything except NaN292 *293 * @internal294 */295export function doubleToIndex(d: number): ArrayInt64 {296 if (d === Number.POSITIVE_INFINITY) {297 return clone64(INDEX_POSITIVE_INFINITY)298 }299 if (d === Number.NEGATIVE_INFINITY) {300 return clone64(INDEX_NEGATIVE_INFINITY)301 }302 const decomp = decomposeDouble(d)303 const exponent = decomp.exponent304 const significand = decomp.significand305 if (d > 0 || (d === 0 && 1 / d === Number.POSITIVE_INFINITY)) {306 return { sign: 1, data: indexInDoubleFromDecomp(exponent, significand) }307 } else {308 const indexOpposite = indexInDoubleFromDecomp(exponent, -significand)309 if (indexOpposite[1] === 0xffffffff) {310 indexOpposite[0] += 1311 indexOpposite[1] = 0312 } else {313 indexOpposite[1] += 1314 }315 return { sign: -1, data: indexOpposite } // -indexInDoubleFromDecomp(exponent, -significand) - 1316 }317}318/**319 * Compute the 64-bit floating point number corresponding to the provided indexes320 *321 * @param n - index of the double322 *323 * @internal324 */325export function indexToDouble(index: ArrayInt64): number {326 if (index.sign === -1) {327 const indexOpposite: ArrayInt64 = { sign: 1, data: [index.data[0], index.data[1]] }328 if (indexOpposite.data[1] === 0) {329 indexOpposite.data[0] -= 1330 indexOpposite.data[1] = 0xffffffff331 } else {332 indexOpposite.data[1] -= 1333 }334 return -indexToDouble(indexOpposite) // -indexToDouble(-index - 1);335 }336 if (isEqual64(index, INDEX_POSITIVE_INFINITY)) {337 return Number.POSITIVE_INFINITY338 }339 if (index.data[0] < 0x200000) {340 // if: index < 2 ** 53 <--> index[0] < 2 ** (53-32) = 0x20_0000341 // The first 2**53 elements correspond to values having342 // exponent = -1022 and significand = index * Number.EPSILON343 // double value = index * 2 ** -1022 * Number.EPSILON344 // = index * 2 ** -1022 * 2 ** -52345 // = index * 2 ** -1074346 return (index.data[0] * 0x100000000 + index.data[1]) * 2 ** -1074347 }348 const postIndexHigh = index.data[0] - 0x200000 // postIndex = index - 2 ** 53349 // exponent = -1021 + Math.floor(postIndex / 2**52)350 // = -1021 + Math.floor(postIndexHigh / 2**(52-32))351 // = -1021 + Math.floor(postIndexHigh / 2**20)352 // = -1021 + (postIndexHigh >> 20)353 const exponent = -1021 + (postIndexHigh >> 20)354 // significand = 1 + (postIndex % 2**52) / 2**52355 // = 1 + ((postIndexHigh * 2**32 + postIndexLow) % 2**52) / 2**52356 // = 1 + ((postIndexHigh % 2**20) * 2**32 + postIndexLow) / 2**52357 // = 1 + ((postIndexHigh & 0xfffff) * 2**32 + postIndexLow) / 2**52358 // = 1 + ((postIndexHigh & 0xfffff) * 2**32 + postIndexLow) * Number.EPSILON359 const significand = 1 + ((postIndexHigh & 0xfffff) * 2 ** 32 + index.data[1]) * Number.EPSILON360 return significand * 2 ** exponent361}362/**363 * Same as {@link doubleToIndex} except it throws in case of invalid double364 *365 * @internal366 */367export function safeDoubleToIndex(d: number, label: string): I.IO<unknown, never, ArrayInt64> {368 if (Number.isNaN(d)) {369 // Number.NaN does not have any associated index in the current implementation370 return I.die(new Error('fc.doubleNext constraints.' + label + ' must be a 32-bit float'))371 }372 return I.succeed(doubleToIndex(d))373}374let EPSILON = Math.pow(2, -52)375let MAX_VALUE = (2 - EPSILON) * Math.pow(2, 1023)376let MIN_VALUE = Math.pow(2, -1022)377export function nextUp(x: number) {378 if (x !== x) {379 return x380 }381 if (x === -1 / 0) {382 return -MAX_VALUE383 }384 if (x === +1 / 0) {385 return +1 / 0386 }387 if (x === +MAX_VALUE) {388 return +1 / 0389 }390 let y = x * (x < 0 ? 1 - EPSILON / 2 : 1 + EPSILON)391 if (y === x) {392 y = MIN_VALUE * EPSILON > 0 ? x + MIN_VALUE * EPSILON : x + MIN_VALUE393 }394 if (y === +1 / 0) {395 y = +MAX_VALUE396 }397 let b = x + (y - x) / 2398 if (x < b && b < y) {399 y = b400 }401 let c = (y + x) / 2402 if (x < c && c < y) {403 y = c404 }405 return y === 0 ? -0 : y406}407export function nextAfter(x: number, y: number) {408 return y < x ? -nextUp(-x) : y > x ? nextUp(x) : x !== x ? x : y409}410export function computeBiasedRanges(411 min: ArrayInt64,412 max: ArrayInt64,413 biasedRanges?: { min: ArrayInt64, max: ArrayInt64 }[]414): { min: ArrayInt64, max: ArrayInt64 }[] {415 if (biasedRanges != null) {416 return biasedRanges417 }418 if (isEqual64(min, max)) {419 return [{ min, max }]420 }421 const minStrictlySmallerThanZero = isStrictlyNegative64(min)422 const maxStrictlyGreaterThanZero = isStrictlyPositive64(max)423 if (minStrictlySmallerThanZero && maxStrictlyGreaterThanZero) {424 const logMin = logLike64(min)425 const logMax = logLike64(max)426 return [427 { min: logMin, max: logMax },428 { min: substract64(max, logMax), max },429 { min, max: substract64(min, logMin) }430 ]431 } else {432 const logGap = logLike64(substract64(max, min))433 const closeToMin = { min, max: add64(min, logGap) }434 const closeToMax = { min: substract64(max, logGap), max }435 return minStrictlySmallerThanZero ? [closeToMax, closeToMin] : [closeToMin, closeToMax]...

Full Screen

Full Screen

ArrayInt64Arbitrary.ts

Source:ArrayInt64Arbitrary.ts Github

copy

Full Screen

...86 return this.shrinkArrayInt64(current, context, false);87 }88 private defaultTarget(): ArrayInt64 {89 // min <= 0 && max >= 0 => shrink towards zero90 if (!isStrictlyPositive64(this.min) && !isStrictlyNegative64(this.max)) {91 return Zero64;92 }93 // min < 0 => shrink towards max (closer to zero)94 // otherwise => shrink towards min (closer to zero)95 return isStrictlyNegative64(this.min) ? this.max : this.min;96 }97 private isLastChanceTry(current: ArrayInt64, context: ArrayInt64): boolean {98 // Last chance corresponds to scenario where shrink should be empty99 // But we try a last thing just in case it can work100 if (isZero64(current)) {101 return false;102 }103 if (current.sign === 1) {104 return isEqual64(current, add64(context, Unit64)) && isStrictlyPositive64(substract64(current, this.min));105 } else {106 return isEqual64(current, substract64(context, Unit64)) && isStrictlyNegative64(substract64(current, this.max));107 }108 }109 private static isValidContext(_current: ArrayInt64, context?: unknown): context is ArrayInt64 {110 // Context contains a value between zero and current that is known to be111 // the closer to zero passing value*.112 // *More precisely: our shrinker will not try something closer to zero113 if (context === undefined) {114 return false;115 }116 if (typeof context !== 'object' || context === null || !('sign' in context) || !('data' in context)) {117 throw new Error(`Invalid context type passed to ArrayInt64Arbitrary (#1)`);118 }119 return true;120 }121 private retrieveBiasedRanges(): { min: ArrayInt64; max: ArrayInt64 }[] {122 if (this.biasedRanges != null) {123 return this.biasedRanges;124 }125 if (isEqual64(this.min, this.max)) {126 this.biasedRanges = [{ min: this.min, max: this.max }];127 return this.biasedRanges;128 }129 const minStrictlySmallerZero = isStrictlyNegative64(this.min);130 const maxStrictlyGreaterZero = isStrictlyPositive64(this.max);131 if (minStrictlySmallerZero && maxStrictlyGreaterZero) {132 // min < 0 && max > 0133 const logMin = logLike64(this.min); // min !== 0 -> <=0134 const logMax = logLike64(this.max); // max !== 0 -> >=0135 this.biasedRanges = [136 { min: logMin, max: logMax }, // close to zero,137 { min: substract64(this.max, logMax), max: this.max }, // close to max138 { min: this.min, max: substract64(this.min, logMin) }, // close to min139 ];140 } else {141 // Either min < 0 && max <= 0142 // Or min >= 0, so max >= 0143 const logGap = logLike64(substract64(this.max, this.min)); // max-min !== 0 -> >=0...

Full Screen

Full Screen

ArrayInt64.ts

Source:ArrayInt64.ts Github

copy

Full Screen

...8export function isZero64(a: ArrayInt64): boolean {9 return a.data[0] === 0 && a.data[1] === 0;10}11/** @internal */12export function isStrictlyNegative64(a: ArrayInt64): boolean {13 return a.sign === -1 && !isZero64(a);14}15/** @internal */16export function isStrictlyPositive64(a: ArrayInt64): boolean {17 return a.sign === 1 && !isZero64(a);18}19/** @internal */20export function isEqual64(a: ArrayInt64, b: ArrayInt64): boolean {21 if (a.data[0] === b.data[0] && a.data[1] === b.data[1]) {22 return a.sign === b.sign || (a.data[0] === 0 && a.data[1] === 0); // either the same or both zero23 }24 return false;25}26/** @internal */...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isStrictlyNegative64 } = require('fast-check');2Recommended Posts: Node.js | fs.appendFileSync() Method3Node.js | fs.appendFile() Method4Node.js | fs.lstatSync() Method5Node.js | fs.lstat() Method6Node.js | fs.accessSync() Method7Node.js | fs.access() Method8Node.js | fs.existsSync() Method9Node.js | fs.exists() Method10Node.js | fs.mkdirSync() Method11Node.js | fs.mkdir() Method12Node.js | fs.openSync() Method13Node.js | fs.open() Method14Node.js | fs.readdirSync() Method15Node.js | fs.readdir() Method16Node.js | fs.readFileSync() Method17Node.js | fs.readFile() Method18Node.js | fs.renameSync() Method19Node.js | fs.rename() Method20Node.js | fs.rmdirSync() Method21Node.js | fs.rmdir() Method22Node.js | fs.statSync() Method23Node.js | fs.stat() Method24Node.js | fs.unlinkSync() Method25Node.js | fs.unlink() Method26Node.js | fs.writeSync() Method27Node.js | fs.write() Method28Node.js | fs.writeFile() Method29Node.js | fs.writeFileSync() Method30Node.js | fs.watchFile() Method31Node.js | fs.watch() Method32Node.js | fs.createReadStream() Method

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const isStrictlyNegative64 = require('fast-check-monorepo/packages/arbitrary/_internals/helpers/Numbers');3fc.assert(4 fc.property(fc.integer(), (i) => {5 if (i < 0) {6 isStrictlyNegative64(i);7 }8 })9);10const fc = require('fast-check');11const isStrictlyNegative64 = require('fast-check-monorepo/packages/arbitrary/_internals/helpers/Numbers');12fc.assert(13 fc.property(fc.integer(), (i) => {14 if (i < 0) {15 isStrictlyNegative64(i);16 }17 })18);19const fc = require('fast-check');20const isStrictlyNegative64 = require('fast-check-monorepo/packages/arbitrary/_internals/helpers/Numbers');21fc.assert(22 fc.property(fc.integer(), (i) => {23 if (i < 0) {24 isStrictlyNegative64(i);25 }26 })27);28const fc = require('fast-check');29const isStrictlyNegative64 = require('fast-check-monorepo/packages/arbitrary/_internals/helpers/Numbers');30fc.assert(31 fc.property(fc.integer(), (i) => {32 if (i < 0) {33 isStrictlyNegative64(i);34 }35 })36);37const fc = require('fast-check');38const isStrictlyNegative64 = require('fast-check-monorepo/packages/arbitrary/_internals/helpers/Numbers');39fc.assert(40 fc.property(fc.integer(), (i) => {41 if (i < 0) {42 isStrictlyNegative64(i);43 }44 })45);

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { isStrictlyNegative64 } = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.integer(), (n) => {5 expect(isStrictlyNegative64(n)).toBe(n < 0);6 })7);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const isStrictlyNegative64 = (n) => {3 if (typeof n !== 'number') {4 throw new Error('Not a number');5 }6 if (n >= 0) {7 throw new Error('Not a strictly negative number');8 }9 if (n !== Math.floor(n)) {10 throw new Error('Not an integer');11 }12 if (n < -0x8000000000000000) {13 throw new Error('Number is too small');14 }15 return true;16};17fc.assert(18 fc.property(fc.integer64(), isStrictlyNegative64),19 { verbose: true }20);21const fc = require('fast-check');22const isStrictlyNegative64 = (n) => {23 if (typeof n !== 'number') {24 throw new Error('Not a number');25 }26 if (n >= 0) {27 throw new Error('Not a strictly negative number');28 }29 if (n !== Math.floor(n)) {30 throw new Error('Not an integer');31 }32 if (n < -0x8000000000000000) {33 throw new Error('Number is too small');34 }35 return true;36};37fc.assert(38 fc.property(fc.integer64(), isStrictlyNegative64),39 { verbose: true }40);41const fc = require('fast-check');42const isStrictlyNegative64 = (n) => {43 if (typeof n !== 'number') {44 throw new Error('Not a number');45 }46 if (n >= 0) {47 throw new Error('Not a strictly negative number');48 }49 if (n !== Math.floor(n)) {50 throw new Error('Not an integer');51 }52 if (n < -0x8000000000000000) {53 throw new Error('Number is too small');54 }55 return true;56};57fc.assert(58 fc.property(fc.integer64(), isStrictlyNegative64),59 { verbose: true }60);

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