How to use float64raw method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

double.spec.ts

Source:double.spec.ts Github

copy

Full Screen

...48 });49 it('should accept any constraits defining min (not-NaN) equal to max', () => {50 fc.assert(51 fc.property(52 float64raw(),53 fc.record({ noDefaultInfinity: fc.boolean(), noNaN: fc.boolean() }, { withDeletedKeys: true }),54 (f, otherCt) => {55 // Arrange56 fc.pre(!Number.isNaN(f));57 spyArrayInt64();58 // Act59 const arb = double({ ...otherCt, min: f, max: f });60 // Assert61 expect(arb).toBeDefined();62 }63 )64 );65 });66 it('should reject NaN if specified for min', () => {67 // Arrange68 const arrayInt64 = spyArrayInt64();69 // Act / Assert70 expect(() => double({ min: Number.NaN })).toThrowError();71 expect(arrayInt64).not.toHaveBeenCalled();72 });73 it('should reject NaN if specified for max', () => {74 // Arrange75 const arrayInt64 = spyArrayInt64();76 // Act / Assert77 expect(() => double({ max: Number.NaN })).toThrowError();78 expect(arrayInt64).not.toHaveBeenCalled();79 });80 it('should reject if specified min is strictly greater than max', () => {81 fc.assert(82 fc.property(float64raw(), float64raw(), (da, db) => {83 // Arrange84 fc.pre(!Number.isNaN(da));85 fc.pre(!Number.isNaN(db));86 fc.pre(!Object.is(da, db)); // Object.is can distinguish -0 from 0, while !== cannot87 const arrayInt64 = spyArrayInt64();88 const min = isStrictlySmaller(da, db) ? db : da;89 const max = isStrictlySmaller(da, db) ? da : db;90 // Act / Assert91 expect(() => double({ min, max })).toThrowError();92 expect(arrayInt64).not.toHaveBeenCalled();93 })94 );95 });96 it('should reject impossible noDefaultInfinity-based ranges', () => {...

Full Screen

Full Screen

DoubleHelpers.spec.ts

Source:DoubleHelpers.spec.ts Github

copy

Full Screen

...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);...

Full Screen

Full Screen

FloatingPointHelpers.ts

Source:FloatingPointHelpers.ts Github

copy

Full Screen

...3import { FloatConstraints } from '../../../../src/arbitrary/float';4export function float32raw(): fc.Arbitrary<number> {5 return fc.integer().map((n32) => new Float32Array(new Int32Array([n32]).buffer)[0]);6}7export function float64raw(): fc.Arbitrary<number> {8 return fc9 .tuple(fc.integer(), fc.integer())10 .map(([na32, nb32]) => new Float64Array(new Int32Array([na32, nb32]).buffer)[0]);11}12export const defaultFloatRecordConstraints = {13 min: float32raw(),14 max: float32raw(),15 noDefaultInfinity: fc.boolean(),16 noNaN: fc.boolean(),17};18export const defaultDoubleRecordConstraints = {19 min: float64raw(),20 max: float64raw(),21 noDefaultInfinity: fc.boolean(),22 noNaN: fc.boolean(),23};24type ConstraintsInternalOut = FloatConstraints & DoubleConstraints;25type ConstraintsInternal = {26 [K in keyof ConstraintsInternalOut]?: fc.Arbitrary<ConstraintsInternalOut[K]>;27};28function constraintsInternal(recordConstraints: ConstraintsInternal): fc.Arbitrary<ConstraintsInternalOut> {29 return fc30 .record(recordConstraints, { withDeletedKeys: true })31 .filter((ct) => (ct.min === undefined || !Number.isNaN(ct.min)) && (ct.max === undefined || !Number.isNaN(ct.max)))32 .filter((ct) => {33 if (!ct.noDefaultInfinity) return true;34 if (ct.min === Number.POSITIVE_INFINITY && ct.max === undefined) return false;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const assert = require('assert');3const { float64raw } = require('fast-check/lib/arbitrary/float64raw.js');4const { float64rawNext } = require('fast-check/lib/arbitrary/float64raw.js');5describe('float64raw', () => {6 it('should be able to generate a float64raw', () => {7 fc.assert(8 fc.property(float64raw(), (v) => {9 assert(typeof v === 'number');10 assert(v >= Number.MIN_VALUE);11 assert(v <= Number.MAX_VALUE);12 assert(!isNaN(v));13 assert(isFinite(v));14 })15 );16 });17 it('should be able to generate a float64rawNext', () => {18 fc.assert(19 fc.property(float64rawNext(), (v) => {20 assert(typeof v === 'number');21 assert(v >= Number.MIN_VALUE);22 assert(v <= Number.MAX_VALUE);23 assert(!isNaN(v));24 assert(isFinite(v));25 })26 );27 });28});29const fc = require('fast-check');30const assert = require('assert');31const { float64raw } = require('fast-check/lib/arbitrary/float64raw.js');32const { float64rawNext } = require('fast-check/lib/arbitrary/float64raw.js');33describe('float64raw', () => {34 it('should be able to generate a float64raw', () => {35 fc.assert(36 fc.property(float64raw(), (v) => {37 assert(typeof v === 'number');38 assert(v >= Number.MIN_VALUE);39 assert(v <= Number.MAX_VALUE);40 assert(!isNaN(v));41 assert(isFinite(v));42 })43 );44 });45 it('should be able to generate a float64rawNext', () => {46 fc.assert(47 fc.property(float64rawNext(), (v) => {48 assert(typeof v === 'number');49 assert(v >= Number.MIN_VALUE);50 assert(v <= Number.MAX_VALUE);51 assert(!isNaN(v));52 assert(isFinite(v));53 })54 );55 });56});57const fc = require('fast-check');58const assert = require('assert');59const { float64raw } =

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { float64raw } = require('fast-check-monorepo');3fc.assert(4 fc.property(float64raw(MIN, MAX), (x) => {5 if (x < MIN || x > MAX) {6 throw new Error(`Value ${x} is outside of range ${MIN} to ${MAX}`);7 }8 })9);10const fc = require('fast-check');11const { float64raw } = require('fast-check-monorepo');12fc.assert(13 fc.property(float64raw(MIN, MAX), (x) => {14 if (x < MIN || x > MAX) {15 throw new Error(`Value ${x} is outside of range ${MIN} to ${MAX}`);16 }17 })18);19[MIT](./LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const randomNumbers = fc.float64raw();3const randomNumbers2 = fc.float64raw(0, 10);4const randomNumbers3 = fc.float64raw(-1, 1);5const randomNumbers4 = fc.float64raw(1, 2);6const randomNumbers5 = fc.float64raw(-1, 0);7const randomNumbers6 = fc.float64raw(0, 0);8const randomNumbers7 = fc.float64raw(-1, -1);9const randomNumbers8 = fc.float64raw(1, 1);10const randomNumbers9 = fc.float64raw(1, 1);11const randomNumbers10 = fc.float64raw(1, 1);12const randomNumbers11 = fc.float64raw(1, 1);13const randomNumbers12 = fc.float64raw(1, 1);14const randomNumbers13 = fc.float64raw(1, 1);15const randomNumbers14 = fc.float64raw(1, 1);16const randomNumbers15 = fc.float64raw(1, 1);17const randomNumbers16 = fc.float64raw(1, 1);18const randomNumbers17 = fc.float64raw(1, 1);19const randomNumbers18 = fc.float64raw(1, 1);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const random = fc.float64raw();3const randomString = fc.stringOf(random, 100);4fc.assert(5 fc.property(randomString, (s) => {6 console.log(s);7 return true;8 })9);10const fc = require("fast-check");11const random = fc.float64raw();12const randomString = fc.stringOf(random, 100);13fc.assert(14 fc.property(randomString, (s) => {15 console.log(s);16 return true;17 })18);19const fc = require("fast-check");20const random = fc.float64raw();21const randomString = fc.stringOf(random, 100);22fc.assert(23 fc.property(randomString, (s) => {24 console.log(s);25 return true;26 })27);28const fc = require("fast-check");29const random = fc.float64raw();30const randomString = fc.stringOf(random, 100);31fc.assert(32 fc.property(randomString, (s) => {33 console.log(s);34 return true;35 })36);37const fc = require("fast-check");38const random = fc.float64raw();39const randomString = fc.stringOf(random, 100);40fc.assert(41 fc.property(randomString, (s) => {42 console.log(s);43 return true;44 })45);46const fc = 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