Best JavaScript code snippet using fast-check-monorepo
FloatArbitrary.spec.ts
Source:FloatArbitrary.spec.ts
1import * as fc from '../../../src/fast-check';2import { seed } from '../seed';3describe(`FloatArbitrary (seed: ${seed})`, () => {4 describe('float', () => {5 const limitedNumRuns = 1000;6 const numRuns = 25000;7 const sampleFloat = fc.sample(fc.float(), { seed, numRuns });8 const sampleFloatNoBias = fc.sample(fc.float().noBias(), { seed, numRuns });9 function shouldGenerate(expectedValue: number) {10 it('Should be able to generate ' + fc.stringify(expectedValue), () => {11 const hasValue = sampleFloat.findIndex((v) => Object.is(v, expectedValue)) !== -1;12 expect(hasValue).toBe(true);13 });14 it('Should not be able to generate ' + fc.stringify(expectedValue) + ' if not biased (very unlikely)', () => {15 const hasValue = sampleFloatNoBias.findIndex((v) => Object.is(v, expectedValue)) !== -1;16 expect(hasValue).toBe(false);17 });18 }19 const extremeValues = [20 Number.POSITIVE_INFINITY,21 Number.NEGATIVE_INFINITY,22 Number.NaN,23 0,24 -0,25 2 ** -126 * 2 ** -23, // Number.MIN_VALUE for 32-bit floats26 -(2 ** -126 * 2 ** -23), // -Number.MIN_VALUE for 32-bit floats27 2 ** 127 * (1 + (2 ** 23 - 1) / 2 ** 23), // Number.MAX_VALUE for 32-bit floats28 -(2 ** 127 * (1 + (2 ** 23 - 1) / 2 ** 23)), // -Number.MAX_VALUE for 32-bit floats29 ];30 for (const extremeValue of extremeValues) {31 // Should be able to generate an exact extreme value in {numRuns} runs32 // The set of possible values for floats is of 4_278_190_083 distinct values (incl. nan, -/+inf)33 shouldGenerate(extremeValue);34 }35 it(`Should be able to generate one of the extreme values in a limited amount of runs (${limitedNumRuns})`, () => {36 const hasValue =37 sampleFloat.slice(0, limitedNumRuns).findIndex((v) => {38 // Check if we can find one of the extreme values in our limited sample39 return extremeValues.findIndex((expectedValue) => Object.is(v, expectedValue)) !== -1;40 }) !== -1;41 expect(hasValue).toBe(true);42 });43 // Remark:44 // MIN_VALUE_32 = (2**-126) * (2**-23)45 // In range: [MIN_VALUE_32 ; 2 ** -125[ there are 2**24 distinct values46 // Remark:47 // MAX_VALUE_32 = (2**127) * (2 - 2**-23)48 // In range: [2**127 ; MAX_VALUE_32] there are 2**23 distinct values49 //50 // If we join those 4 ranges (including negative versions), they only represent 1.176 % of all the possible values.51 // Indeed there are 4_278_190_080 distinct values for double if we exclude -infinity, +infinty and NaN.52 // So most of the generated values should be in the union of the ranges ]-2**127 ; -2**-125] and [2**-125 ; 2**127[.53 const filterIntermediateValues = (sample: number[]) => {54 return sample.filter((v) => {55 const absV = Math.abs(v);56 return absV >= 2 ** -125 && absV < 2 ** 127;57 });58 };59 it('Should be able to generate intermediate values most of the time even if biased', () => {60 const countIntermediate = filterIntermediateValues(sampleFloat).length;61 expect(countIntermediate).toBeGreaterThan(0.5 * sampleFloat.length);62 });63 it('Should be able to generate intermediate values most of the time if not biased', () => {64 const countIntermediate = filterIntermediateValues(sampleFloatNoBias).length;65 expect(countIntermediate).toBeGreaterThan(0.5 * sampleFloatNoBias.length);66 });67 });...
klangraum_client.js
Source:klangraum_client.js
1export function klangraumConnect(url, onmessageFunc) {2// let socket = new WebSocket("wss://static.184.12.47.78.clients.your-server.de:8800");3// let socket = new WebSocket("ws://localhost:8800");4 5 let socket = new WebSocket(url);6 const mp3encoder = new lamejs.Mp3Encoder(1, 44100, 128);7 const CHUNK_LENGTH = 1152;8 9 socket.onmessage = onmessageFunc;10 11 socket.onopen = function (event) { 12 13 navigator.mediaDevices.getUserMedia({14 audio: {15 sampleRate: 44100,16 channelCount: 1,17 echoCancellation: false,18 noiseSuppression: false,19 autoGainControl: false20 },21 video : false22 })23 .then(function(stream) {24 25 const context = new AudioContext({ sampleRate: 44100 });26 const source = context.createMediaStreamSource(stream);27 const processor = context.createScriptProcessor(16384, 1, 1);28 29 source.connect(processor);30 processor.connect(context.destination);31 32 let toDecode = new Int16Array(CHUNK_LENGTH);33 let toDecodeI = 0;34 processor.onaudioprocess = function(e) {35 let audioData = e.inputBuffer.getChannelData(0);36 for (let i = 0; i < audioData.length; i++) {37 38 if (toDecodeI >= CHUNK_LENGTH) {39 let mp3Chunk = mp3encoder.encodeBuffer(toDecode);40 socket.send(mp3Chunk);41 // console.log('sending chunk with length ', mp3Chunk.length);42 toDecode = new Int16Array(CHUNK_LENGTH);43 toDecodeI = 0;44 }45 46 let sampleFloat = audioData[i];47 let sample = sampleFloat > 0 ? sampleFloat*0x7FFF : sampleFloat*0x8000;48 49 toDecode[toDecodeI] = sample;50 toDecodeI += 1;51 }52 }; 53 54 })55 .catch(function(err) {56 57 });58 };59 return socket;...
float.ts
Source:float.ts
...6export interface FloatConstraints {7 min: number8 max: number9}10export function sampleFloat({ min, max }: FloatConstraints, { rng }: ArbitraryContext): number {11 return rng.sample() * (max - min) + min12}13export function shrinkFloat({ min, max }: FloatConstraints, x: number): Tree<number> {14 const destination = min <= 0 && max >= 0 ? 0 : min < 0 ? max : min15 return expandTree((v) => towardsf(destination, v), tree(x, [tree(destination)]))16}17export function float(constraints: RelaxedPartial<FloatConstraints> = {}): Integrated<FloatConstraints, number> {18 const { min = -Math.pow(2, 31), max = Math.pow(2, 31) } = constraints19 return makeIntegrated({20 sample: sampleFloat,21 shrink: shrinkFloat,22 constraints: {23 min,24 max,...
Using AI Code Generation
1const { sampleFloat } = require('fast-check-monorepo');2console.log(sampleFloat());3console.log(sampleFloat());4const { sampleFloat } = require('fast-check-monorepo');5console.log(sampleFloat());6console.log(sampleFloat());7const { sampleFloat } = require('fast-check-monorepo');8console.log(sampleFloat());9console.log(sampleFloat());10const { sampleFloat } = require('fast-check-monorepo');11console.log(sampleFloat());12console.log(sampleFloat());13const { sampleFloat } = require('fast-check-monorepo');14console.log(sampleFloat());15console.log(sampleFloat());16const { sampleFloat } = require('fast-check-monorepo');17console.log(sampleFloat());18console.log(sampleFloat());19const { sampleFloat } = require('fast-check-monorepo');20console.log(sampleFloat());21console.log(sampleFloat());22const { sampleFloat } = require('fast-check-monorepo');23console.log(sampleFloat());24console.log(sampleFloat());25const { sampleFloat } = require('fast-check-monorepo');26console.log(sampleFloat());27console.log(sampleFloat());28const { sampleFloat } = require('fast-check-monorepo');29console.log(sampleFloat());30console.log(sampleFloat());31const { sampleFloat } = require('fast-check-monorepo');32console.log(sampleFloat());33console.log(sampleFloat());34const { sample
Using AI Code Generation
1const { sampleFloat } = require('fast-check-monorepo');2console.log(sampleFloat(1, 2));3const { sampleFloat } = require('fast-check-monorepo');4console.log(sampleFloat(1, 2));5"workspaces": {6 }
Using AI Code Generation
1const { sampleFloat } = require('fast-check');2const float = sampleFloat(0, 100);3console.log(float);4import { sampleFloat } from 'fast-check-monorepo';5const { sampleFloat } = require('fast-check-monorepo');6const float = sampleFloat(0, 100);7console.log(float);
Using AI Code Generation
1const fc = require('fast-check');2const { sampleFloat } = require('fast-check/lib/arbitrary/float');3const { sample } = require('fast-check/lib/check/sampler/Sampler');4const { Random } = require('fast-check/lib/random/generator/Random');5const { Stream } = require('fast-check/lib/stream/Stream');6const random = new Random(0);7const floatArb = sampleFloat();8const floatSampler = sample(floatArb, 1);9const stream = floatSampler(random);10const result = stream.getHead();11console.log(result);12const fc = require('fast-check');13const { sampleFloat } = require('fast-check/lib/arbitrary/float');14const { sample } = require('fast-check/lib/check/sampler/Sampler');15const { Random } = require('fast-check/lib/random/generator/Random');16const { Stream } = require('fast-check/lib/stream/Stream');17const random = new Random(0);18const floatArb = sampleFloat();19const floatSampler = sample(floatArb, 1);20const stream = floatSampler(random);21const result = stream.getHead();22console.log(result);23const fc = require('fast-check');24const { sampleFloat } = require('fast-check/lib/arbitrary/float');25const { sample } = require('fast-check/lib/check/sampler/Sampler');26const { Random } = require('fast-check/lib/random/generator/Random');27const { Stream } = require('fast-check/lib/stream/Stream');28const random = new Random(0);29const floatArb = sampleFloat();30const floatSampler = sample(floatArb, 1);31const stream = floatSampler(random);32const result = stream.getHead();33console.log(result);34const fc = require('fast-check');35const { sampleFloat } = require('fast-check/lib/arbitrary/float');36const { sample } = require('fast-check/lib/check/sampler/Sampler');37const { Random } = require('fast-check/lib/random/generator/Random');38const { Stream } = require('fast-check/lib/stream/Stream');39const random = new Random(0);40const floatArb = sampleFloat();41const floatSampler = sample(floatArb,
Using AI Code Generation
1const { sampleFloat } = require('fast-check');2const sample = sampleFloat(0, 1);3console.log(sample);4const { sampleFloat } = require('fast-check');5const sample = sampleFloat(0, 1);6console.log(sample);7const { sampleFloat } = require('fast-check');8const sample = sampleFloat(0, 1);9console.log(sample);10const { sampleFloat } = require('fast-check');11const sample = sampleFloat(0, 1);12console.log(sample);13const { sampleFloat } = require('fast-check');14const sample = sampleFloat(0, 1);15console.log(sample);16const { sampleFloat } = require('fast-check');17const sample = sampleFloat(0, 1);18console.log(sample);19const { sampleFloat } = require('fast-check');20const sample = sampleFloat(0, 1);21console.log(sample);22const { sampleFloat } = require('fast-check');23const sample = sampleFloat(0, 1);24console.log(sample);25const { sampleFloat } = require('fast-check');26const sample = sampleFloat(0, 1);27console.log(sample);28const { sampleFloat } = require('fast-check');29const sample = sampleFloat(0, 1);30console.log(sample);31const { sampleFloat } =
Using AI Code Generation
1const { sampleFloat } = require('fast-check-monorepo');2sampleFloat(0, 1, 0.1).then((value) => {3 console.log(value);4});5const { sampleFloat } = require('fast-check-monorepo');6sampleFloat(0, 1, 0.1).then((value) => {7 console.log(value);8});9const { sampleFloat } = require('fast-check-monorepo');10sampleFloat(0, 1, 0.1).then((value) => {11 console.log(value);12});13const { sampleFloat } = require('fast-check-monorepo');14sampleFloat(0, 1, 0.1).then((value) => {15 console.log(value);16});17const { sampleFloat } = require('fast-check-monorepo');18sampleFloat(0, 1, 0.1).then((value) => {19 console.log(value);20});21const { sampleFloat } = require('fast-check-monorepo');22sampleFloat(0, 1, 0.1).then((value) => {23 console.log(value);24});25const { sampleFloat } = require('fast-check-monorepo');26sampleFloat(0, 1, 0.1).then((value) => {27 console.log(value);28});
Using AI Code Generation
1const { sampleFloat } = require('fast-check');2const sampleFloat = sampleFloat(0, 1);3console.log(sampleFloat);4 throw err;5 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)6 at Function.Module._load (internal/modules/cjs/loader.js:507:25)7 at Module.require (internal/modules/cjs/loader.js:637:17)8 at require (internal/modules/cjs/helpers.js:22:18)9 at Object.<anonymous> (C:\Users\anand\Documents\fast-check-monorepo\test3.js:1:16)10 at Module._compile (internal/modules/cjs/loader.js:689:30)11 at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)12 at Module.load (internal/modules/cjs/loader.js:599:32)13 at tryModuleLoad (internal/modules/cjs/loader.js:538:12)14 at Function.Module._load (internal/modules/cjs/loader.js:530:3)15Your name to display (optional):16Your name to display (optional):17Your name to display (optional):
Using AI Code Generation
1const { sampleFloat } = require('fast-check');2sampleFloat();3Then import fast-check in your code:4import * as fc from 'fast-check';5const fc = require('fast-check');6define(['fast-check'], function(fc) { /* ... */ });7const fc = window.fastCheck;8var fc = require('fast-check').default;9fc.assert(10 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a)11);
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!!