Best JavaScript code snippet using fast-check-monorepo
SoundMgr.ts
Source:SoundMgr.ts
1class SoundMgr {2 private static _instance: SoundMgr;3 public static getInstance(): SoundMgr {4 if (SoundMgr._instance == null) {5 SoundMgr._instance = new SoundMgr();6 }7 return SoundMgr._instance;8 }910 private _bg: egret.Sound;11 private click_waArr: HTMLAudioElement[] = [];12 private gameover: egret.Sound;13 private gamestart0: egret.Sound;14 private gamestart1: egret.Sound;15 private paopaocrush: egret.Sound;16 private paopaocrushArr: HTMLAudioElement[] = [];17 private paopaoon: egret.Sound;18 private paopaoonArr: HTMLAudioElement[] = [];19 private paopaofantan: egret.Sound;20 private shoot: egret.Sound;21 private shootArr: HTMLAudioElement[] = [];22 private propLaser: egret.Sound;23 private propRainbow: egret.Sound;24 private _good: egret.Sound;25 private _perfect: egret.Sound;26 private _nice: egret.Sound;27 private _countdown: egret.Sound;28 private _win: egret.Sound;29 private _draw: egret.Sound;30 private _lose: egret.Sound;31 private _readyGo: egret.Sound;32 private _drop: egret.Sound;33 private _touch: egret.Sound;3435 /**36 * å¼å¯æå
³éé³ä¹åé³æ37 */38 public _isOpen: boolean;39 public set isOpen(b: boolean) {40 this._isOpen = b;41 LocalStorageController.getInstance().setSoundOpen(b);42 }43 public get isOpen(): boolean {44 return LocalStorageController.getInstance().getSoundOpen();45 }4647 public constructor() {48 this.initSounds();49 }5051 private async initSounds() {52 let prefix: string = "";53 RES.getResByUrl(prefix + "bg_mp3", (val) => {54 this._bg = val;55 if (this.isOpen) {56 this._bgSoundChannel = this._bg.play(0, -1);57 }58 }, this, "sound");5960 RES.getResByUrl(prefix + "gameover_mp3", (val) => {61 this.gameover = val;62 }, this, "sound");6364 RES.getResByUrl(prefix + "gamestart0_mp3", (val) => {65 this.gamestart0 = val;66 }, this, "sound");6768 RES.getResByUrl(prefix + "gamestart1_mp3", (val) => {69 this.gamestart1 = val;70 }, this, "sound");7172 // RES.getResByUrl(prefix + "paopaoon_mp3", (val) => {73 // this.paopaoon = val;74 // }, this, "sound");7576 RES.getResByUrl(prefix + "paopaofantan_mp3", (val) => {77 this.paopaofantan = val;78 }, this, "sound");7980 // RES.getResByUrl(prefix + "shoot_mp3", (val) => {81 // this.shoot = val;82 // }, this, "sound");83 RES.getResByUrl(prefix + "rainbow_mp3", (val) => {84 this.propRainbow = val;85 }, this, "sound");86 RES.getResByUrl(prefix + "lightning_mp3", (val) => {87 this.propLaser = val;88 }, this, "sound");8990 RES.getResByUrl(prefix + "good_mp3", (val) => {91 this._good = val;92 }, this, "sound");93 RES.getResByUrl(prefix + "perfect_mp3", (val) => {94 this._perfect = val;95 }, this, "sound");96 RES.getResByUrl(prefix + "nice_mp3", (val) => {97 this._nice = val;98 }, this, "sound");99 RES.getResByUrl(prefix + "countDown_mp3", (val) => {100 this._countdown = val;101 }, this, "sound");102103 RES.getResByUrl(prefix + "win_mp3", (val) => {104 this._win = val;105 }, this, "sound");106 RES.getResByUrl(prefix + "lose_mp3", (val) => {107 this._lose = val;108 }, this, "sound");109 RES.getResByUrl(prefix + "draw_mp3", (val) => {110 this._draw = val;111 }, this, "sound");112113 RES.getResByUrl(prefix + "readyGo_mp3", (val) => {114 this._readyGo = val;115 }, this, "sound");116117 RES.getResByUrl(prefix + "drop_mp3", (val) => {118 this._drop = val;119 }, this, "sound");120121 RES.getResByUrl(prefix + "touch_mp3", (val) => {122 this._touch = val;123 }, this, "sound");124 125126 for (let i = 0; i < 10; i++) {127 let rushAudio = new Audio();128 rushAudio.src = "resource/assets/paopao/sound/paopaocrush1.mp3";129 this.paopaocrushArr[i] = rushAudio130 }131 for (let i = 0; i < 5; i++) {132 let rushAudio = new Audio();133 rushAudio.src = "resource/assets/paopao/sound/paopaoon.mp3";134 this.paopaoonArr[i] = rushAudio135 }136 for (let i = 0; i < 5; i++) {137 let rushAudio = new Audio();138 rushAudio.src = "resource/assets/paopao/sound/shoot.mp3";139 this.shootArr[i] = rushAudio;140 }141 for (let i = 0; i < 5; i++) {142 let rushAudio = new Audio();143 rushAudio.src = "resource/assets/paopao/sound/click.mp3";144 this.click_waArr[i] = rushAudio;145 }146 }147148149 private playwaindex: number = 0;150 public playWa() {151 if (!this.isOpen) {152 return;153 }154 if (this.click_waArr[this.playwaindex % 5] != null) {155 this.click_waArr[this.playwaindex % 5].play();156 }157 this.playwaindex++;158 }159160161162 public playGameover() {163 if (!this.isOpen) {164 return;165 }166 this.gameover && this.gameover.play(0, 1);167 }168169 public playGamestart1() {170 if (!this.isOpen) {171 return;172 }173 if (this.gamestart1) {174 let soundchannel: egret.SoundChannel = this.gamestart1.play(0, 1);175 soundchannel && soundchannel.addEventListener(egret.Event.SOUND_COMPLETE, () => {176 let s = this.gamestart0 && this.gamestart0.play(0, 1);177 }, this);178 }179 }180181 private curcrushArr: number = 0;182 private c1: egret.SoundChannel;183 private c2: egret.SoundChannel;184 public playPaopaocrush(loop: number) {185 if (!this.isOpen) {186 return;187 }188 // if (this.curcrushArr % 2) {189 // this.c1 = RES.getRes("paopaocrush1_mp3").play(0, 1);190 // } else {191 // this.c2 = RES.getRes("paopaocrush_mp3").play(0, 1);192 // }193 if (this.paopaocrushArr[this.curcrushArr % 10] != null) {194 this.paopaocrushArr[this.curcrushArr % 10].play();195 }196 this.curcrushArr++;197 }198199 private playonindex: number = 0;200 public playPaopaoon() {201 if (!this.isOpen) {202 return;203 }204 if (this.paopaoonArr[this.playonindex % 5] != null) {205 this.paopaoonArr[this.playonindex % 5].play();206 }207 this.playonindex++;208 }209210 public playCountdown() {211 if (!this.isOpen) {212 return;213 }214 this._countdown && this._countdown.play(0, 1);215 }216217 public playFantan() {218 return;219 if (!this.isOpen) {220 return;221 }222 this.paopaofantan && this.paopaofantan.play(0, 1);223 }224 private playShootindex: number = 0;225 public playShoot(): void {226 if (!this.isOpen) {227 return;228 }229 if (this.shootArr[this.playShootindex % 5] != null) {230 this.shootArr[this.playShootindex % 5].play();231 }232 this.playShootindex++;233 }234235 public playRainbow(): void {236 if (!this.isOpen) {237 return;238 }239 this.propRainbow && this.propRainbow.play(0, 1);240 }241242 public playLaser(): void {243 if (!this.isOpen) {244 return;245 }246 this.propLaser && this.propLaser.play(0, 1);247 }248249 public playGood(): void {250 if (!this.isOpen) {251 return;252 }253 this._good && this._good.play(0, 1);254 }255256 public playNice(): void {257 if (!this.isOpen) {258 return;259 }260 this._nice && this._nice.play(0, 1);261 }262263 public playPerfect(): void {264 if (!this.isOpen) {265 return;266 }267 this._perfect && this._perfect.play(0, 1);268 }269270 public playWin(): void {271 if (!this.isOpen) {272 return;273 }274 this._win && this._win.play(0, 1);275 }276 public playLose(): void {277 if (!this.isOpen) {278 return;279 }280 this._lose && this._lose.play(0, 1);281 }282 public playDraw(): void {283 if (!this.isOpen) {284 return;285 }286 this._draw && this._draw.play(0, 1);287 }288289 public playReady(): void {290 if (!this.isOpen) {291 return;292 }293 this._readyGo && this._readyGo.play(0, 1);294 }295296 public playDrop(): void {297 if (!this.isOpen) {298 return;299 }300 this._drop && this._drop.play(0, 1);301 }302303 public playTouch(): void {304 if (!this.isOpen) {305 return;306 }307 this._touch && this._touch.play(0, 1);308 }309310 private _bgSoundChannel: egret.SoundChannel;311 public playBGM(): void {312 egret.log("ææ¾èæ¯é³ä¹" + this.isOpen);313 if (!this.isOpen) {314 return;315 }316 if (this._bgSoundChannel) {317 this._bgSoundChannel.stop();318 this._bgSoundChannel = null;319 }320 if (this._bg) {321 this._bgSoundChannel = this._bg.play(0, -1);322 }323324 }325326 public stopBGM(): void {327 this._bgSoundChannel && this._bgSoundChannel.stop();328 this._bgSoundChannel = null;329 }330331332 public changeSoundStatus() {333 this.isOpen = !this.isOpen;334 if (this.isOpen) {335 this.playBGM();336 } else {337 this.stopBGM();338 }339 }
...
ReplayFailures.spec.ts
Source:ReplayFailures.spec.ts
1import * as fc from '../../src/fast-check';2import { seed } from './seed';3describe(`ReplayFailures (seed: ${seed})`, () => {4 const propArbitrary = fc.uniqueArray(fc.hexaString());5 const propCheck = (data: string[]) => {6 // element at <idx> should not contain the first character of the element just before7 // 01, 12, 20 - is correct8 // 01, 12, 21 - is not9 if (data.length === 0) return true;10 for (let idx = 1; idx < data.length; ++idx) {11 if (data[idx].indexOf(data[idx - 1][0]) !== -1) return false;12 }13 return true;14 };15 const prop = fc.property(propArbitrary, propCheck);16 describe('fc.sample', () => {17 it('Should rebuild counterexample using sample and (path, seed)', () => {18 const out = fc.check(prop, { seed: seed });19 expect(out.failed).toBe(true);20 expect(fc.sample(propArbitrary, { seed: seed, path: out.counterexamplePath!, numRuns: 1 })).toEqual(21 out.counterexample22 );23 });24 it('Should rebuild the whole shrink path using sample', () => {25 const failuresRecorded: string[][] = [];26 const out = fc.check(27 fc.property(propArbitrary, (data) => {28 if (propCheck(data)) return true;29 failuresRecorded.push(data);30 return false;31 }),32 { seed: seed }33 );34 expect(out.failed).toBe(true);35 const replayedFailures = [];36 const segments = out.counterexamplePath!.split(':');37 for (let idx = 1; idx !== segments.length + 1; ++idx) {38 const p = segments.slice(0, idx).join(':');39 const g = fc.sample(propArbitrary, { seed: seed, path: p, numRuns: 1 });40 replayedFailures.push(g[0]);41 }42 expect(replayedFailures).toEqual(failuresRecorded);43 });44 });45 describe('fc.assert', () => {46 it('Should start from the minimal counterexample given its path', () => {47 const out = fc.check(prop, { seed: seed });48 expect(out.failed).toBe(true);49 let numCalls = 0;50 let numValidCalls = 0;51 let validCallIndex = -1;52 const out2 = fc.check(53 fc.property(propArbitrary, (data) => {54 try {55 expect(data).toEqual(out.counterexample![0]);56 validCallIndex = numCalls;57 ++numValidCalls;58 } catch (err) {59 // noop60 }61 ++numCalls;62 return propCheck(data);63 }),64 { seed: seed, path: out.counterexamplePath! }65 );66 expect(numValidCalls).toEqual(1);67 expect(validCallIndex).toEqual(0);68 expect(out2.numRuns).toEqual(1);69 expect(out2.numShrinks).toEqual(0);70 expect(out2.counterexamplePath).toEqual(out.counterexamplePath);71 expect(out2.counterexample).toEqual(out.counterexample);72 });73 it('Should start from any position in the path', () => {74 const out = fc.check(prop, { seed: seed });75 expect(out.failed).toBe(true);76 const segments = out.counterexamplePath!.split(':');77 for (let idx = 1; idx !== segments.length + 1; ++idx) {78 const p = segments.slice(0, idx).join(':');79 const outMiddlePath = fc.check(prop, { seed: seed, path: p });80 expect(outMiddlePath.numRuns).toEqual(1);81 expect(outMiddlePath.numShrinks).toEqual(out.numShrinks - idx + 1);82 expect(outMiddlePath.counterexamplePath).toEqual(out.counterexamplePath);83 expect(outMiddlePath.counterexample).toEqual(out.counterexample);84 }85 });86 it('Should only execute one test given path for failure and noShrink flag', () => {87 const out = fc.check(prop, { seed: seed });88 expect(out.failed).toBe(true);89 const segments = out.counterexamplePath!.split(':');90 for (let idx = 1; idx !== segments.length + 1; ++idx) {91 const p = segments.slice(0, idx).join(':');92 const outMiddlePath = fc.check(prop, { seed: seed, path: p, endOnFailure: true });93 expect(outMiddlePath.numRuns).toEqual(1);94 expect(outMiddlePath.numShrinks).toEqual(0);95 expect(outMiddlePath.counterexamplePath).toEqual(p);96 }97 });98 it('Should take initial path into account when computing path', () => {99 const out = fc.check(prop, { seed: seed });100 expect(out.failed).toBe(true);101 const segments = out.counterexamplePath!.split(':');102 const playOnIndex = (seed >>> 0) % segments.length; // seed could be <0103 for (let offset = 0; offset !== +segments[playOnIndex]; ++offset) {104 const p = [...segments.slice(0, playOnIndex), offset].join(':');105 const outMiddlePath = fc.check(prop, { seed: seed, path: p });106 expect(outMiddlePath.counterexamplePath).toEqual(out.counterexamplePath);107 expect(outMiddlePath.counterexample).toEqual(out.counterexample);108 }109 });110 });...
Using AI Code Generation
1const fc = require('fast-check');2const { playOnIndex } = require('fast-check-monorepo');3const { Arbitrary } = require('fast-check/lib/types/definition/Arbitrary');4const { Shrinkable } = require('fast-check/lib/types/definition/Shrinkable');5const arb = new Arbitrary();6arb.generate = () => new Shrinkable(1);7arb.canGenerate = () => true;8arb.shrink = () => [new Shrinkable(2), new Shrinkable(3)];9const settings = {
Using AI Code Generation
1const fc = require("fast-check");2const { playOnIndex } = require("fast-check/lib/check/arbitrary/PlaygroundArbitrary");3const arb = fc.integer();4const index = 3;5const value = playOnIndex(arb, index);6console.log(value);
Using AI Code Generation
1const fc = require('fast-check');2const { playOnIndex } = require('fast-check/lib/check/arbitrary/PlaygroundArbitrary.js');3const { PathReporter } = require('io-ts/lib/PathReporter');4const { Type } = require('io-ts');5const arb = fc.tuple(fc.integer(), fc.integer(), fc.integer(), fc.integer());6const arb2 = playOnIndex(arb, 2, fc.nat(10));7const arb3 = playOnIndex(arb, 3, fc.nat(10));8const test = Type({ x: Type.number, y: Type.number, z: Type.number, w: Type.number });9const test2 = Type({ x: Type.number, y: Type.number, z: Type.number, w: Type.number });10fc.assert(11 fc.property(arb, (val) => {12 const result = test.decode(val);13 if (result.isLeft()) {14 console.log(PathReporter.report(result));15 throw new Error('test failed');16 }17 }),18 { verbose: true }19);20fc.assert(21 fc.property(arb2, (val) => {22 const result = test2.decode(val);23 if (result.isLeft()) {24 console.log(PathReporter.report(result));25 throw new Error('test failed');26 }27 }),28 { verbose: true }29);30fc.assert(31 fc.property(arb3, (val) => {32 const result = test2.decode(val);33 if (result.isLeft()) {34 console.log(PathReporter.report(result));35 throw new Error('test failed');36 }37 }),38 { verbose: true }39);
Using AI Code Generation
1const fc = require("fast-check");2const { playOnIndex } = require("fast-check-monorepo");3const run = () => {4 const arb = fc.array(fc.integer(), 1, 10);5 const idx = 1;6 const shrink = playOnIndex(arb, idx);7 console.log(shrink(10));8};9run();10const fc = require("fast-check");11const { playOnIndex } = require("fast-check-monorepo");12const run = () => {13 const arb = fc.array(fc.integer(), 1, 10);14 const idx = 1;15 const shrink = playOnIndex(arb, idx);16 console.log(shrink(11));17};18run();19const fc = require("fast-check");20const { playOnIndex } = require("fast-check-monorepo");21const run = () => {22 const arb = fc.array(fc.integer(), 1, 10);23 const idx = 2;24 const shrink = playOnIndex(arb, idx);25 console.log(shrink(10));26};27run();28const fc = require("fast-check");29const { playOnIndex } = require("fast-check-monorepo");30const run = () => {31 const arb = fc.array(fc.integer(), 1, 10);32 const idx = 2;33 const shrink = playOnIndex(arb, idx);34 console.log(shrink(11));35};36run();37const fc = require("fast-check");38const {
Using AI Code Generation
1const fc = require('fast-check');2const { playOnIndex } = require('fast-check-monorepo');3const { check, property } = fc;4const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];5const isOdd = (n) => n % 2 === 1;6const isEven = (n) => n % 2 === 0;7playOnIndex(array, isOdd, 0);8playOnIndex(array, isOdd, 1);9playOnIndex(array, isOdd, 2);10playOnIndex(array, isOdd, 3);11playOnIndex(array, isOdd, 4);12playOnIndex(array, isOdd, 5);13playOnIndex(array, isOdd, 6);14playOnIndex(array, isOdd, 7);15playOnIndex(array, isOdd, 8);16playOnIndex(array, isOdd, 9);17playOnIndex(array, isOdd, 10);18playOnIndex(array, isOdd, 11);19playOnIndex(array, isOdd, 12);20playOnIndex(array, isOdd, 13);21playOnIndex(array, isOdd, 14);22playOnIndex(array, isOdd, 15);23playOnIndex(array, isOdd, 16);24playOnIndex(array, isOdd, 17);25playOnIndex(array, isOdd, 18);26playOnIndex(array, isOdd, 19);27playOnIndex(array, isOdd, 20);28playOnIndex(array, is
Using AI Code Generation
1import { playOnIndex } from "fast-check-monorepo";2import { array } from "fp-ts/lib/Array";3import { none, some } from "fp-ts/lib/Option";4import { option } from "fp-ts/lib/Option";5import { pipe } from "fp-ts/lib/pipeable";6import { ordNumber } from "fp-ts/lib/Ord";7import { ordString } from "fp-ts/lib/Ord";8import { ord } from "fp-ts/lib/Ord";9import { setoidNumber } from "fp-ts/lib/Setoid";10import { setoidString } from "fp-ts/lib/Setoid";11import { setoid } from "fp-ts/lib/Setoid";12import { ordSet } from "fp-ts/lib/Ord";13import { ordOption } from "fp-ts/lib/Ord";14import { ordArray } from "fp-ts/lib/Ord";15import { ordDate } from "fp-ts/lib/Ord";16import { ordBoolean } from "fp-ts/lib/Ord";17import { ordTuple } from "fp-ts/lib/Ord";18import { ordRecord } from "fp-ts/lib/Ord";19import { ordEither } from "fp-ts/lib/Ord";20import { ordFunction } from "fp-ts/lib/Ord";21import { ordConst } from "fp-ts/lib/Ord";22import { ordEndo } from "fp-ts/lib/Ord";23import { ordIO } from "fp-ts/lib/Ord";24import { ordIOEither } from "fp-ts/lib/Ord";25import { ordReader } from "fp-ts/lib/Ord";26import { ordReaderEither } from "fp-ts/lib/Ord";27import { ordTask } from "fp-ts/lib/Ord";28import { ordTaskEither } from "fp-ts/lib/Ord";29import { ordThese } from "fp-ts/lib/Ord";30import { ordNonEmptyArray } from "fp-ts/lib/Ord";31import { ordEitherT } from "fp-ts/lib/Ord";32import { ordOptionT } from "fp-ts/lib/Ord";33import { ordReaderTaskEither } from "fp-ts/lib/Ord";34import { ordState } from "fp-ts/lib/Ord";35import { ordStateEither } from "fp-ts/lib/Ord";36import { ordStrMap } from "fp-ts/lib/Ord";37import { ord
Using AI Code Generation
1const fc = require("fast-check");2const { playOnIndex } = require("fast-check-monorepo");3 .integer(0, 100)4 .array()5 .filter((arr) => arr.length === 5)6 .noBias()7 .noShrink();8fc.assert(9 fc.property(randomSequence, (arr) => {10 const result = playOnIndex(arr);11 return arr.reduce((acc, curr) => acc + curr, 0) === result;12 })13);
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!!