How to use negative64 method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

math.ts

Source:math.ts Github

copy

Full Screen

...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 * @internal...

Full Screen

Full Screen

ArrayInt64Arbitrary.ts

Source:ArrayInt64Arbitrary.ts Github

copy

Full Screen

1import { Random } from '../../random/generator/Random';2import { stream, Stream } from '../../stream/Stream';3import { Arbitrary } from '../../check/arbitrary/definition/Arbitrary';4import { Value } from '../../check/arbitrary/definition/Value';5import {6 add64,7 ArrayInt64,8 halve64,9 isEqual64,10 isStrictlyNegative64,11 isStrictlyPositive64,12 isStrictlySmaller64,13 isZero64,14 logLike64,15 substract64,16 Unit64,17 Zero64,18} from './helpers/ArrayInt64';19/** @internal */20class ArrayInt64Arbitrary extends Arbitrary<ArrayInt64> {21 private biasedRanges: { min: ArrayInt64; max: ArrayInt64 }[] | null = null;22 constructor(readonly min: ArrayInt64, readonly max: ArrayInt64) {23 super();24 }25 generate(mrng: Random, biasFactor: number | undefined): Value<ArrayInt64> {26 const range = this.computeGenerateRange(mrng, biasFactor);27 const uncheckedValue = mrng.nextArrayInt(range.min, range.max);28 if (uncheckedValue.data.length === 1) {29 // either 1 or 2, never 0 or >230 uncheckedValue.data.unshift(0); // prepend a zero31 }32 return new Value(uncheckedValue as ArrayInt64, undefined);33 }34 private computeGenerateRange(mrng: Random, biasFactor: number | undefined): { min: ArrayInt64; max: ArrayInt64 } {35 if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) {36 return { min: this.min, max: this.max };37 }38 const ranges = this.retrieveBiasedRanges();39 if (ranges.length === 1) {40 return ranges[0];41 }42 const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); // 1st range has the highest priority43 return id < 0 ? ranges[0] : ranges[id + 1];44 }45 canShrinkWithoutContext(value: unknown): value is ArrayInt64 {46 const unsafeValue = value as ArrayInt64;47 return (48 typeof value === 'object' &&49 value !== null &&50 (unsafeValue.sign === -1 || unsafeValue.sign === 1) &&51 Array.isArray(unsafeValue.data) &&52 unsafeValue.data.length === 2 &&53 ((isStrictlySmaller64(this.min, unsafeValue) && isStrictlySmaller64(unsafeValue, this.max)) ||54 isEqual64(this.min, unsafeValue) ||55 isEqual64(this.max, unsafeValue))56 );57 }58 private shrinkArrayInt64(value: ArrayInt64, target: ArrayInt64, tryTargetAsap?: boolean): Stream<Value<ArrayInt64>> {59 const realGap = substract64(value, target);60 function* shrinkGen(): IterableIterator<Value<ArrayInt64>> {61 let previous: ArrayInt64 | undefined = tryTargetAsap ? undefined : target;62 const gap = tryTargetAsap ? realGap : halve64(realGap);63 for (let toremove = gap; !isZero64(toremove); toremove = halve64(toremove)) {64 const next = substract64(value, toremove);65 yield new Value(next, previous); // previous indicates the last passing value66 previous = next;67 }68 }69 return stream(shrinkGen());70 }71 shrink(current: ArrayInt64, context?: unknown): Stream<Value<ArrayInt64>> {72 if (!ArrayInt64Arbitrary.isValidContext(current, context)) {73 // No context:74 // Take default target and shrink towards it75 // Try the target on first try76 const target = this.defaultTarget();77 return this.shrinkArrayInt64(current, target, true);78 }79 if (this.isLastChanceTry(current, context)) {80 // Last chance try...81 // context is set to undefined, so that shrink will restart82 // without any assumptions in case our try find yet another bug83 return Stream.of(new Value(context, undefined));84 }85 // Normal shrink process86 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 -> >=0144 const arbCloseToMin = { min: this.min, max: add64(this.min, logGap) }; // close to min145 const arbCloseToMax = { min: substract64(this.max, logGap), max: this.max }; // close to max146 this.biasedRanges = minStrictlySmallerZero147 ? [arbCloseToMax, arbCloseToMin] // max is closer to zero148 : [arbCloseToMin, arbCloseToMax]; // min is closer to zero149 }150 return this.biasedRanges;151 }152}153/** @internal */154export function arrayInt64(min: ArrayInt64, max: ArrayInt64): Arbitrary<ArrayInt64> {155 const arb = new ArrayInt64Arbitrary(min, max);156 return arb;...

Full Screen

Full Screen

ArrayInt64.ts

Source:ArrayInt64.ts Github

copy

Full Screen

...85/**86 * Negative version of an ArrayInt6487 * @internal88 */89export function negative64(arrayIntA: ArrayInt64): ArrayInt64 {90 return {91 sign: -arrayIntA.sign as -1 | 1,92 data: [arrayIntA.data[0], arrayIntA.data[1]],93 };94}95/**96 * Add two ArrayInt6497 * @returns When result is zero always with sign=198 * @internal99 */100export function add64(arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64 {101 if (isZero64(arrayIntB)) {102 if (isZero64(arrayIntA)) {103 return clone64(Zero64);104 }105 return clone64(arrayIntA);106 }107 return substract64(arrayIntA, negative64(arrayIntB));108}109/**110 * Halve an ArrayInt64111 * @internal112 */113export function halve64(a: ArrayInt64): ArrayInt64 {114 return {115 sign: a.sign,116 data: [Math.floor(a.data[0] / 2), (a.data[0] % 2 === 1 ? 0x80000000 : 0) + Math.floor(a.data[1] / 2)],117 };118}119/**120 * Apply log2 to an ArrayInt64 (preserve sign)121 * @internal...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const { negative64 } = require("fast-check/lib/arbitrary/integer64Arbitrary");3const { integer64 } = require("fast-check/lib/arbitrary/integer64Arbitrary");4fc.assert(5 fc.property(6 integer64(),7 (a) => {8 const b = negative64(a);9 console.log(a, b);10 return true;11 },12 { verbose: true }13);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const { negative64 } = require("fast-check/lib/arbitrary/negative64");3const arb = negative64();4const arb2 = fc.nat().map((n) => n * -1);5fc.assert(6 fc.property(arb, (a) => {7 console.log(a);8 })9);10fc.assert(11 fc.property(arb2, (a) => {12 console.log(a);13 })14);15const fc = require("fast-check");16const { negative64 } = require("fast-check/lib/arbitrary/negative64");17const arb = negative64();18const arb2 = fc.nat().map((n) => n * -1);19fc.assert(20 fc.property(arb, (a) => {21 console.log(a);22 })23);24fc.assert(25 fc.property(arb2, (a) => {26 console.log(a);27 })28);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { negative64 } = require('fast-check/lib/arbitrary/negative64');3const { convertFromNext } = require('fast-check/lib/check/arbitrary/definition/Converters');4const { convertToNext } = require('fast-check/lib/check/arbitrary/definition/Converters');5const negative64Arb = convertFromNext(convertToNext(negative64()));6fc.assert(fc.property(negative64Arb, (n) => n < 0));7const fc = require('fast-check');8const { negative64 } = require('fast-check/lib/arbitrary/negative64');9const { convertFromNext } = require('fast-check/lib/check/arbitrary/definition/Converters');10const { convertToNext } = require('fast-check/lib/check/arbitrary/definition/Converters');11const negative64Arb = convertFromNext(convertToNext(negative64()));12fc.assert(fc.property(negative64Arb, (n) => n < 0));13const fc = require('fast-check');14const { negative64 } = require('fast-check/lib/arbitrary/negative64');15const { convertFromNext } = require('fast-check/lib/check/arbitrary/definition/Converters');16const { convertToNext } = require('fast-check/lib/check/arbitrary/definition/Converters');17const negative64Arb = convertFromNext(convertToNext(negative64()));18fc.assert(fc.property(negative64Arb, (n) => n < 0));19const fc = require('fast-check');20const { negative64 } = require('fast-check/lib/arbitrary/negative64');21const { convertFromNext } = require('fast-check/lib/check/arbitrary/definition/Converters');22const { convertToNext } = require('fast-check/lib/check/arbitrary/definition/Converters');23const negative64Arb = convertFromNext(convertToNext(negative64()));24fc.assert(fc.property(negative

Full Screen

Using AI Code Generation

copy

Full Screen

1let fastCheck = require('fast-check');2let negative64 = fastCheck.negative64;3let positive64 = fastCheck.positive64;4let integer64 = fastCheck.integer64;5let fc = require('fast-check');6let bigInt = require('big-integer');7let n = bigInt("18446744073709551616");8let p = bigInt("9223372036854775808");9let m = bigInt("-9223372036854775808");10let n64 = negative64();11let p64 = positive64();12let i64 = integer64();13console.log("n64: " + n64);14console.log("p64: " + p64);15console.log("i64: " + i64);16console.log("n64: " + n64.toString());17console.log("p64: " + p64.toString());18console.log("i64: " + i64.toString());19console.log("n64: " + n64.toString(16));20console.log("p64: " + p64.toString(16));21console.log("i64: " + i64.toString(16));22let n64b = n64.toJSNumber();23let p64b = p64.toJSNumber();24let i64b = i64.toJSNumber();25console.log("n64b: " + n64b);26console.log("p64b: " + p64b);27console.log("i64b: " + i64b);28console.log("n64b: " + n64b.toString(16));29console.log("p64b: " + p64b.toString(16));30console.log("i64b: " + i64b.toString(16));31console.log("n64b: " + n64b.toString(2));32console.log("p64b: " + p64b.toString(2));33console.log("i64b: " + i64b.toString(2));34console.log("n64b: " + n64b.toString(10));35console.log("p64b: " + p64b.toString(10));36console.log("i64b: " + i64b.toString(10));37console.log("n64b: " + n64b.toString(8));38console.log("p64b: " + p64b.toString(8));39console.log("i64b: " + i64b.toString(8));40console.log("n

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