Best JavaScript code snippet using fast-check-monorepo
DoubleHelpers.spec.ts
Source:DoubleHelpers.spec.ts
...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);...
DoubleHelpers.ts
Source:DoubleHelpers.ts
...21 * @param d - 64-bit floating point number to be decomposed into (significand, exponent)22 *23 * @internal24 */25export function decomposeDouble(d: number): { exponent: number; significand: number } {26 // 1 => significand 0b1 - exponent 1 (will be preferred)27 // => significand 0b0.1 - exponent 228 const maxSignificand = 2 - safeEpsilon;29 for (let exponent = -1022; exponent !== 1024; ++exponent) {30 const powExponent = 2 ** exponent;31 const maxForExponent = maxSignificand * powExponent;32 if (Math.abs(d) <= maxForExponent) {33 return { exponent, significand: d / powExponent };34 }35 }36 return { exponent: safeNaN, significand: safeNaN };37}38/** @internal */39function positiveNumberToInt64(n: number): ArrayInt64['data'] {40 return [~~(n / 0x100000000), n >>> 0];41}42/** @internal */43function indexInDoubleFromDecomp(exponent: number, significand: number): ArrayInt64['data'] {44 // WARNING: significand >= 045 // By construct of significand in decomposeDouble,46 // significand is always max-ed.47 // The double close to zero are the only one having a significand <1, they also have an exponent of -1022.48 // They are in range: [2**(-1022) * 2**(-52), 2**(-1022) * (2 - 2 ** 52)]49 // In other words there are 2**53 elements in that range if we include zero.50 // All other ranges (other exponents) have a length of 2**52 elements.51 if (exponent === -1022) {52 // We want the significand to be an integer value (like an index)53 const rescaledSignificand = significand * 2 ** 52; // significand * 2**5254 return positiveNumberToInt64(rescaledSignificand);55 }56 // Offset due to exp = -1022 + Offset of previous exp (excl. -1022) + Offset in current exp57 // 2**53 + (exponent - (-1022) -1) * 2**52 + (significand - 1) * 2**5258 // (exponent + 1023) * 2**52 + (significand - 1) * 2**5259 const rescaledSignificand = (significand - 1) * 2 ** 52; // (significand-1) * 2**5260 const exponentOnlyHigh = (exponent + 1023) * 2 ** 20; // (exponent + 1023) * 2**52 => [high: (exponent + 1023) * 2**20, low: 0]61 const index = positiveNumberToInt64(rescaledSignificand);62 index[0] += exponentOnlyHigh;63 return index;64}65/**66 * Compute the index of d relative to other available 64-bit floating point numbers67 * Rq: Produces negative indexes for negative doubles68 *69 * @param d - 64-bit floating point number, anything except NaN70 *71 * @internal72 */73export function doubleToIndex(d: number): ArrayInt64 {74 if (d === safePositiveInfinity) {75 return clone64(INDEX_POSITIVE_INFINITY);76 }77 if (d === safeNegativeInfinity) {78 return clone64(INDEX_NEGATIVE_INFINITY);79 }80 const decomp = decomposeDouble(d);81 const exponent = decomp.exponent;82 const significand = decomp.significand;83 if (d > 0 || (d === 0 && 1 / d === safePositiveInfinity)) {84 return { sign: 1, data: indexInDoubleFromDecomp(exponent, significand) };85 } else {86 const indexOpposite = indexInDoubleFromDecomp(exponent, -significand);87 if (indexOpposite[1] === 0xffffffff) {88 indexOpposite[0] += 1;89 indexOpposite[1] = 0;90 } else {91 indexOpposite[1] += 1;92 }93 return { sign: -1, data: indexOpposite }; // -indexInDoubleFromDecomp(exponent, -significand) - 194 }...
integrationTests.js
Source:integrationTests.js
1export default function integrationTests(Hangul) {2 const a = Symbol('oneArgument');3 const typeDecorator = datum => ((typeof datum === 'object' || typeof datum === 'string')4 ? JSON.stringify(datum)5 : datum);6 const tests = {7 assemble: [8 ['ã±ã
ã
ã
ã
ã
ã
£', 'ê³ ìì´'],9 [a, ['ã±', 'ã
', 'ã
', 'ã
', 'ã
', 'ã
', 'ã
£'], 'ê³ ìì´'],10 [a, ['ã
ã
£ã±ã
ã
ã·ã
ã
ã
ã±ã·ã
ã
ã
ã
ã
ã´ã
£ã·ã
'], 'ì´ê²ë ìëí©ëë¤'],11 ['Hello ã
ã
ã´ã´ã
ã
World ã
ã
ã
ã
ã
', 'Hello ìë
World ì¸ì'],12 ],13 composeComplex: [14 [['ã·', 'ã·'], 'ã¸'],15 [['ã
ã
', 'ã
'], 'ã
ã
ã
'],16 [['', 'ã
'], 'ã
'],17 [['ã¹', 'ã±', ''], 'ãº'],18 [['ã¹', 'ã±', true], 'ãºtrue'],19 [['ã¹', 'ã±', 1], 'ãº1'],20 // composition with different options21 [22 ['ã
ã
', 'ã
', '', { hardFail: true }],23 Error('is not a Character!'),24 ],25 [26 ['', 'ã
', '', { hardFail: true }],27 Error('The first input to Hangul.composeComplex'),28 ],29 [30 ['ã·', 'ã·', 'ã
', { hardFail: true }],31 Error('but cannot combine'),32 ],33 [34 ['ã
', 'ã
', 'ã·', {35 complex3: true,36 complexArchaic: true,37 }],38 'ã
µ',39 ],40 // [['ã
', 'ã
', '', { complexJung: false }], 'ã
ã
'],41 // [['ã±', 'ã±', '', { composeComplexDouble: false }], 'ã±ã±'],42 ],43 composeSyllable: [44 [['ã
', 'ã
£', 'ã
'], 'ì§'],45 [['ã
', 'ã
', 'ã
£'], '모ã
£'],46 [['ã
', 'ã
', 'ã
£', { hardFail: true }], Error('')],47 [['ã
', 'a'], 'ã
a'],48 [['ã
', 'a', '', { hardFail: true }], Error('is not a valid jung Character!')],49 [['ã
ã
', 'ã·'], 'ã
ã
ã·'],50 [['ã
', 'ã
'], 'ë¹ '],51 ],52 decomposeComplex: [53 ['ã¸', 'ã¸'],54 [['ã¸', { grouped: true }], 'ã¸'],55 [['ã¸', { decomposeDouble: true }], 'ã·ã·'],56 [['ã¸', { grouped: true, decomposeDouble: true }], 'ã·ã·'],57 [['', { grouped: true }], ''],58 ],59 decomposeSyllable: [60 ['ë¹ ', 'ã
ã
'],61 ['ì', 'ã
ã
ã
'],62 ['ã
', 'ã
'],63 [['ã
', { hardFail: true }], Error('is not a syllable!')],64 ],65 disassemble: [66 ['ê³ ìì´', 'ã±ã
ã
ã
ã
ã
ã
£'],67 [['ë¹ ë¥¸', { grouped: true }], [['ã
', 'ã
'], ['ã¹', 'ã
¡', 'ã´']]],68 [['ìë¤', { grouped: true }], [['ã
', 'ã
', ['ã
', 'ã
']], ['ã·', 'ã
']]],69 ['', ''],70 [['', { grouped: true }], []],71 ],72 disassembleCharacter: [73 ['ì', 'ã
ã
ã
ã
'],74 [['ì', { grouped: true }], ['ã
', 'ã
', ['ã
', 'ã
']]],75 ],76 stronger: [77 ['ã±', 'ã²'],78 ['ã
', 'ã
'],79 ['ã
', 'ã²'],80 ['ã
', 'ã
'],81 ],82 hangulToKeys: [83 ['ê³ ìì´', 'rhdiddl'],84 [['ë¹ ë¥¸', { grouped: true }], [['Q', 'k'], ['f', 'm', 's']]],85 [['ìë¤', { grouped: true }], [['d', 'j', ['q', 't']], ['e', 'k']]],86 ['', ''],87 [['', { grouped: true }], []],88 ],89 keysToHangul: [90 ['qwerty', 'ã
ã
ã·ã³ã
'],91 [a, ['qwer', 'ty'], 'ã
ã
ã·ã±ì¼'],92 ],93 };94 Object.keys(tests).forEach((functionName) => {95 const pairs = tests[functionName];96 describe(`Hangul.${functionName}`, () => {97 const fn = Hangul[functionName];98 if (!fn) {99 throw Hangul;100 }101 pairs.forEach((en) => {102 let args;103 let res;104 if (en[0] === a) {105 args = [en[1]];106 [, , res] = en;107 } else if (Array.isArray(en[0])) {108 [args, res] = en;109 } else {110 args = [en[0]];111 [, res] = en;112 }113 const stargs = args.map(typeDecorator).join(', ');114 if (res instanceof Error) {115 const { message } = res;116 test(`${stargs} throws "${message}"`, () => {117 expect(() => fn(...args)).toThrow(message);118 });119 } else if (res instanceof Object) {120 test(`${(stargs)} => ${typeDecorator(res)}`, () => {121 expect(fn(...args)).toEqual(res);122 });123 } else if (Array.isArray(en)) {124 test(`${(stargs)} => ${typeDecorator(res)}`, () => {125 expect(fn(...args)).toBe(res);126 });127 }128 });129 });130 });131 // I'm not gonna test the hangul block things because I'm lazy...
Using AI Code Generation
1const { decomposeDouble } = require('fast-check');2const [sign, exponent, significand] = decomposeDouble(0.1);3console.log(sign, exponent, significand);4const { decomposeDouble } = require('fast-check');5const [sign, exponent, significand] = decomposeDouble(0.1);6console.log(sign, exponent, significand);7const { decomposeDouble } = require('fast-check');8const [sign, exponent, significand] = decomposeDouble(0.1);9console.log(sign, exponent, significand);10const { decomposeDouble } = require('fast-check');11const [sign, exponent, significand] = decomposeDouble(0.1);12console.log(sign, exponent, significand);13const { decomposeDouble } = require('fast-check');14const [sign, exponent, significand] = decomposeDouble(0.1);15console.log(sign, exponent, significand);16const { decomposeDouble } = require('fast-check');17const [sign, exponent, significand] = decomposeDouble(0.1);18console.log(sign, exponent, significand);19const { decomposeDouble } = require('fast-check');20const [sign, exponent, significand] = decomposeDouble(0.1);21console.log(sign, exponent, significand);22const { decomposeDouble } = require('fast-check');23const [sign, exponent, significand] = decomposeDouble(0.1);24console.log(sign, exponent, significand);25const { decomposeDouble } = require('fast
Using AI Code Generation
1const fc = require('fast-check');2const {decomposeDouble} = require('fast-check/lib/types/DoubleArbitrary');3const {double} = require('fast-check/lib/types/DoubleArbitrary');4const {doubleNext} = require('fast-check/lib/types/DoubleArbitrary');5const {doubleNextWithin} = require('fast-check/lib/types/DoubleArbitrary');6const {doubleNextArbitrary} = require('fast-check/lib/types/DoubleArbitrary');7const {doubleNextArbitraryWithin} = require('fast-check/lib/types/DoubleArbitrary');8const {doubleNextArbitraryWithinArbitrary} = require('fast-check/lib/types/DoubleArbitrary');9const {doubleNextArbitraryWithinArbitraryNext} = require('fast-check/lib/types/DoubleArbitrary');10const {doubleNextArbitraryWithinArbitraryNextWithin} = require('fast-check/lib/types/DoubleArbitrary');11const {doubleNextArbitraryWithinArbitraryNextWithinArbitrary} = require('fast-check/lib/types/DoubleArbitrary');12const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNext} = require('fast-check/lib/types/DoubleArbitrary');13const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithin} = require('fast-check/lib/types/DoubleArbitrary');14const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitrary} = require('fast-check/lib/types/DoubleArbitrary');15const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitraryNext} = require('fast-check/lib/types/DoubleArbitrary');16const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithin} = require('fast-check/lib/types/DoubleArbitrary');17const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithinArbitrary} = require('fast-check/lib/types/DoubleArbitrary');18const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithinArbitraryNext} = require('fast-check/lib/types/DoubleArbitrary');19const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithin} = require('fast-check/lib/types/DoubleArbitrary');20const {doubleNextArbitraryWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithinArbitraryNextWithinArbitrary} = require('fast-check/lib/types/
Using AI Code Generation
1const fc = require("fast-check");2const { decomposeDouble } = require("fast-check/lib/types/DoubleArbitrary.js");3console.log(decomposeDouble(2.5));4console.log(decomposeDouble(-2.5));5console.log(decomposeDouble(0.0));6console.log(decomposeDouble(-0.0));7console.log(decomposeDouble(1.0));8console.log(decomposeDouble(-1.0));9console.log(decomposeDouble(Infinity));10console.log(decomposeDouble(-Infinity));11console.log(decomposeDouble(NaN));
Using AI Code Generation
1const { decomposeDouble } = require("fast-check");2const test3 = () => {3 const decomposed = decomposeDouble(123.456);4 console.log(decomposed);5};6test3();7const { decomposeDouble } = require("./dist/lib/check/arbitrary/DoubleArbitrary");8const test4 = () => {9 const decomposed = decomposeDouble(123.456);10 console.log(decomposed);11};12test4();13const { decomposeDouble } = require("./dist/lib/check/arbitrary/DoubleArbitrary");14const test5 = () => {15 const decomposed = decomposeDouble(123.456);16 console.log(decomposed);17};18test5();
Using AI Code Generation
1const fc = require('fast-check');2const { decomposeDouble, recomposeDouble } = require('double-fp');3const double = 1.2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;4const { mantissa, exponent } = decomposeDouble(double);5console.log(`mantissa: ${mantissa}, exponent: ${exponent}`);6const recomposedDouble = recomposeDouble(mantissa, exponent);7console.log(`recomposed double: ${recomposedDouble}`);
Using AI Code Generation
1const fc = require ('fast-check');2const {decomposeDouble} = require ('./double-decomposer');3fc.assert(fc.property(fc.double(), (d) => {4 const {sign, exponent, significand} = decomposeDouble(d);5 const result = sign * Math.pow(2, exponent) * (1 + significand);6 return result === d;7}));8const fc = require ('fast-check');9const {decomposeDouble} = require ('./double-decomposer');10fc.assert(fc.property(fc.double(), (d) => {11 const {sign, exponent, significand} = decomposeDouble(d);12 const result = sign * Math.pow(2, exponent) * (1 + significand);13 return result === d;14}));15const fc = require ('fast-check');16const {decomposeDouble} = require ('./double-decomposer');17fc.assert(fc.property(fc.double(), (d) => {18 const {sign, exponent, significand} = decomposeDouble(d);19 const result = sign * Math.pow(2, exponent) * (1 + significand);20 return result === d;21}));22const fc = require ('fast-check');23const {decomposeDouble} = require ('./double-decomposer');24fc.assert(fc.property(fc.double(), (d) => {25 const {sign, exponent, significand} = decomposeDouble(d);26 const result = sign * Math.pow(2, exponent) * (1 + significand);27 return result === d;28}));29const fc = require ('fast-check');30const {decomposeDouble} = require ('./double-decomposer');31fc.assert(fc.property(fc.double(), (d) => {32 const {sign, exponent, significand} = decomposeDouble(d);33 const result = sign * Math.pow(2, exponent) * (1 +
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!!