How to use shrunkResults method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

TrialDeathScene.ts

Source:TrialDeathScene.ts Github

copy

Full Screen

1import { GameWidth, GameHeight, zLevels, GameAreaTopOffset, NotchOffset } from "../../constants"2import * as Phaser from "phaser"3import { launchMainMenu } from "../../menus/MainMenuScene"4import { BattleScene, getNumberWithOrdinal } from "../Scene"5import { becomeButton } from "../../menus/utils/becomeButton"6import {7 livesExtensionStateForSeed,8 livesExtensionsButtonTitleForState,9 LifeStateForSeed,10 bumpLivesExtensionState,11 addLives,12 getDailyTrialRuns,13 getLives,14 getUserSettings,15 getUserStatistics,16 DailyTrialRun,17 livesExtensionsButtonToAdID18} from "../../user/userManager"19import { Bird } from "../../user/UserSettingsTypes"20import { requestModalAd, prepareModalAd } from "../../nativeComms/requestModalAd"21import { centerAlignTextLabel } from "../utils/alignTextLabel"22import { BirdSprite } from "../BirdSprite"23import { shareNatively } from "../../nativeComms/share"24import { setupLogoCornerImages, preloadBackgroundBlobImages } from "../../menus/utils/backgroundColors"25import { getTrialDeathLeaderboard, Leaderboard, LeaderboardResult } from "../../playFab"26import _ = require("lodash")27import { Prompt, showPrompt, PromptOptions } from "../../menus/Prompt"28import { isAndroidApp } from "../../nativeComms/deviceDetection"29declare const DEMO: boolean30export interface TrialDeathProps {31 lives: number32 battle: BattleScene33 livesState: LifeStateForSeed34 seed: string35 score: number36 isHighScore: boolean37}38export const deathPreload = (game: Phaser.Scene) => {39 game.load.image("green-sash", require("../../../assets/menu/GreenSash.png"))40 game.load.image("white-sash", require("../../../assets/menu/WhiteSash.png"))41 game.load.image("share-ios", require("../../../assets/menu/share-ios.png"))42 game.load.image("red-sash", require("../../../assets/menu/RedSash.png"))43 game.load.image("green-sash-small", require("../../../assets/menu/GreenSashSmall.png"))44 game.load.image("footer-bg", require("../../../assets/menu/BottomSash.png"))45 game.load.image("back", require("../../../assets/menu/Back2.png"))46 game.load.image("medal", require("../../../assets/battle/best-medal.png"))47 game.load.image("button-small-bg", require("../../../assets/menu/ButtonSmallBG.png"))48 game.load.image("button-bg", require("../../../assets/menu/ButtonBG.png"))49 game.load.image("white-circle", require("../../../assets/menu/Circle.png"))50 game.load.bitmapFont(51 "fipps-bit",52 require("../../../assets/fonts/fipps.png"),53 require("../../../assets/fonts/fipps.fnt")54 )55 game.load.bitmapFont(56 "fipps-bit-black",57 require("../../../assets/fonts/fipps-black.png"),58 require("../../../assets/fonts/fipps.fnt")59 )60}61export const DeathSceneKey = "TrialDeath"62export class TrialDeath extends Phaser.Scene {63 constructor(id: string, public props: TrialDeathProps) {64 super(id)65 }66 againButton!: Phaser.GameObjects.BitmapText67 footerObjects: (Phaser.GameObjects.Image | Phaser.GameObjects.BitmapText | Phaser.GameObjects.Rectangle)[] = []68 shareLogoObjects: (Phaser.GameObjects.Image | Phaser.GameObjects.BitmapText)[] = []69 preload() {70 deathPreload(this)71 preloadBackgroundBlobImages(this)72 }73 create() {74 // Fill the BG75 const bg = this.add.rectangle(GameWidth / 2, GameHeight / 2, GameWidth, GameHeight, 0x000000, 0.5)76 this.footerObjects.push(bg)77 this.addFooter()78 if (this.props.isHighScore) {79 getTrialDeathLeaderboard().then(leaderboard => {80 const { player } = leaderboard81 if (!player) {82 console.log("ERROR: Trial death leaderboard did not contain player")83 return84 }85 if (player.position === 0) {86 this.cameInFirst(leaderboard)87 } else if (player.position <= 2) {88 this.cameInTopThree(leaderboard)89 } else {90 this.didntComeTopThree(leaderboard)91 }92 if (player.score === this.props.score && player.score > 0) {93 this.time.delayedCall(500, this.addTopMedal, [player], this)94 }95 })96 } else {97 const dailyTrialRuns = getDailyTrialRuns(this.props.seed)98 const leaderboard = this.localTrialCacheToLeaderboard(dailyTrialRuns)99 const { player } = leaderboard100 if (!player) {101 console.log("ERROR: Trial death leaderboard did not contain player")102 return103 }104 if (player.position === 0) {105 this.cameInFirst(leaderboard)106 } else if (player.position <= 2) {107 this.cameInTopThree(leaderboard)108 } else {109 this.didntComeTopThree(leaderboard)110 }111 }112 }113 private addFooter() {114 const bg = this.add.image(80, GameHeight - 8, "footer-bg")115 this.footerObjects.push(bg)116 const back = this.add.image(16, GameHeight - 20, "back")117 becomeButton(back, this.backToMainMenu, this)118 this.footerObjects.push(back)119 const newGame = this.add.image(90, GameHeight - 20, "button-bg")120 this.footerObjects.push(newGame)121 let againText = "AGAIN"122 const outOfLives = this.props.lives <= 0123 if (outOfLives) {124 if (DEMO) {125 againText = "OUT OF LIVES"126 this.againButton.disableInteractive()127 this.againButton.setAlpha(0.5)128 } else {129 againText = livesExtensionsButtonTitleForState(this.props.livesState)130 const adID = livesExtensionsButtonToAdID(this.props.livesState)131 prepareModalAd(adID)132 }133 }134 const newGameText = this.add.bitmapText(GameWidth / 2, GameHeight - 27, "fipps-bit", againText, 8)135 this.footerObjects.push(newGameText)136 centerAlignTextLabel(newGameText, -10)137 becomeButton(newGame, this.again, this, [newGameText])138 this.againButton = newGameText139 if (!isAndroidApp()) {140 const share = this.add.image(125, GameHeight - 51, "button-small-bg")141 share.setScale(0.6, 1)142 this.footerObjects.push(share)143 const shareIcon = this.add.image(125, GameHeight - 51, "share-ios")144 becomeButton(share, this.shareStats, this, [shareIcon])145 this.footerObjects.push(shareIcon)146 }147 }148 private cameInFirst(leaderboard: Leaderboard) {149 if (!leaderboard.player) {150 console.log("ERROR: Trial death leaderboard did not contain player")151 return152 }153 const top = GameAreaTopOffset154 // TOP BIT155 // The green BG is two sashes156 this.add.image(80, top + 40, "green-sash")157 this.add.image(80, top + 30, "green-sash")158 this.add.image(80, top + 50, "green-sash").toggleFlipX()159 this.add.image(80, top + 60, "green-sash").toggleFlipX()160 // White161 this.add.rectangle(92, top + 48, 160, 34, 0xffffff)162 // white circle for bird + pos163 const circle = this.add.image(40, top + 40, "white-circle")164 circle.setScale(1.6, 1.6)165 const settings = getUserSettings()166 new BirdSprite(this, 33, top + 18, { isPlayer: false, isImage: true, settings: settings })167 // 1st of x168 this.add.bitmapText(10, top + 20, "fipps-bit-black", "1st", 24)169 // TODO: There's no obvious way to get the total number of leaderboard results with PlayFab170 // const ofX = this.add.bitmapText(26, top + 56, "fipps-bit-black", `of ${this.props.totalPlayers}`, 8)171 // ofX.x = 40 - ofX.width / 2 // makes it centered172 // Username + score173 this.add.bitmapText(80, top + 34, "fipps-bit-black", settings.name, 8)174 const pipes = leaderboard.player.score === 1 ? "pipe" : "pipes"175 this.add.bitmapText(80, top + 48, "fipps-bit-black", `${leaderboard.player.score} ${pipes}`, 8)176 /// MIDDLE BIT177 if (leaderboard.results[0])178 this.drawPlayerRow({ white: true, x: 12, y: top + 90, opacity: 0.6 }, leaderboard.results[0])179 if (leaderboard.results[1])180 this.drawPlayerRow({ white: true, x: 12, y: top + 110, opacity: 0.4 }, leaderboard.results[1])181 if (leaderboard.results[2])182 this.drawPlayerRow({ white: true, x: 12, y: top + 130, opacity: 0.2 }, leaderboard.results[2])183 /// BOTTOM BIT184 // BG for bottom left185 this.add.image(-20, GameHeight - 70, "green-sash")186 this.add.bitmapText(8, GameHeight - 86, "fipps-bit", "Win", 16)187 this.add.image(20, GameHeight - 48, "green-sash")188 const userScores = getUserStatistics()189 const pos = getNumberWithOrdinal(userScores.trialWins)190 this.add.bitmapText(8, GameHeight - 56, "fipps-bit", `${pos} win`, 8)191 }192 private cameInTopThree(leaderboard: Leaderboard) {193 if (!leaderboard.player) {194 console.log("ERROR: Trial death leaderboard did not contain player")195 return196 }197 const { player, results } = leaderboard198 const top = GameAreaTopOffset199 const playerIsTwo = player.position === 1200 const playerIsThree = player.position === 2201 /// TOP-MIDDLE BIT202 this.add.image(80, top + 50, "red-sash").toggleFlipX()203 this.add.image(80, top + 78, "red-sash").toggleFlipX()204 this.add.image(80, top + 90, "red-sash")205 this.add.image(80, top + 70, "red-sash")206 // white circle for your bird + pos207 const yOffset = playerIsTwo ? 0 : 20208 this.add.image(80, top + 70 + yOffset, "white-sash")209 const circle = this.add.image(48, top + 70 + yOffset, "white-circle")210 circle.setScale(0.8, 0.8)211 this.drawPlayerRow({ white: true, x: 12, y: top + 50, opacity: 1 }, results[0])212 this.drawPlayerRow({ white: !playerIsTwo, x: 12, y: top + 70, opacity: 1 }, results[1])213 if (results[2]) {214 this.drawPlayerRow({ white: !playerIsThree, x: 12, y: top + 90, opacity: 1 }, results[2])215 }216 /// BOTTOM BIT217 this.footerObjects.push(this.add.image(-16, GameHeight - 70, "red-sash"))218 this.footerObjects.push(this.add.bitmapText(8, GameHeight - 86, "fipps-bit", "FAIL", 16))219 this.footerObjects.push(this.add.image(20, GameHeight - 48, "red-sash"))220 const lives = getLives(this.props.seed)221 this.footerObjects.push(222 this.add.bitmapText(8, GameHeight - 56, "fipps-bit", `${this.livesLeftString(lives)}`, 8)223 )224 }225 private didntComeTopThree(leaderboard: Leaderboard) {226 const { results } = leaderboard227 const top = GameAreaTopOffset228 // TOP BIT229 this.add.rectangle(80, top + 0, 160, 110, 0xd49d9d)230 this.add.rectangle(82, top + 2, 160, 110, 0xd49d9d)231 this.add.rectangle(84, top + 4, 160, 110, 0xd49d9d)232 this.add.rectangle(96, top + 6, 160, 110, 0xd49d9d)233 this.drawPlayerRow({ white: true, x: 4, y: top + 10, opacity: 1 }, results[0])234 this.drawPlayerRow({ white: true, x: 7, y: top + 30, opacity: 1 }, results[1])235 this.drawPlayerRow({ white: true, x: 10, y: top + 50, opacity: 1 }, results[2])236 // MIDDLE237 const yOffset = 34238 this.add.image(80, top + 50 + yOffset, "red-sash").toggleFlipX()239 this.add.image(80, top + 78 + yOffset, "red-sash").toggleFlipX()240 this.add.image(80, top + 90 + yOffset, "red-sash")241 this.add.image(80, top + 70 + yOffset, "red-sash")242 // white circle for your bird + pos243 this.add.image(80, top + 70 + yOffset, "white-sash")244 const circle = this.add.image(56, top + 70 + yOffset, "white-circle")245 circle.setScale(0.8, 0.8)246 if (results[3]) {247 this.drawPlayerRow({ white: true, x: 12, y: top + 50 + yOffset, opacity: 1 }, results[3])248 }249 if (results[4]) {250 this.drawPlayerRow({ white: false, x: 12, y: top + 70 + yOffset, opacity: 1 }, results[4])251 }252 if (results[5]) {253 this.drawPlayerRow({ white: true, x: 12, y: top + 90 + yOffset, opacity: 1 }, results[5])254 }255 // END256 this.footerObjects.push(this.add.image(-16, GameHeight - 70, "red-sash"))257 this.footerObjects.push(this.add.bitmapText(8, GameHeight - 86, "fipps-bit", "FAIL", 16))258 this.footerObjects.push(this.add.image(20, GameHeight - 48, "red-sash"))259 const lives = getLives(this.props.seed)260 this.footerObjects.push(261 this.add.bitmapText(8, GameHeight - 56, "fipps-bit", `${this.livesLeftString(lives)}`, 8)262 )263 }264 private drawPlayerRow(config: { white: boolean; opacity: number; x: number; y: number }, data: LeaderboardResult) {265 const font = config.white ? "fipps-bit" : "fipps-bit-black"266 let offset = config.x267 const place = this.add268 .bitmapText(offset, config.y - 8, font, `#${data.position + 1}`, 8)269 .setAlpha(config.opacity)270 offset += place.getTextBounds(true).local.width + 9271 // TODO: Generate birdSprite UserSettings from leaderboard272 const leaderboardBird: Bird = { name: data.name, aesthetics: { attire: data.attire } }273 const bird = new BirdSprite(this, offset + 2, config.y - 2, {274 isPlayer: false,275 isImage: true,276 settings: leaderboardBird277 })278 bird.setOpacity(config.opacity)279 offset += 21280 const scoreText = this.add281 .bitmapText(offset, config.y - 8, font, data.score.toString(), 8)282 .setAlpha(config.opacity)283 offset += scoreText.getTextBounds(true).local.width + 7284 this.add.bitmapText(offset, config.y - 8, font, data.name, 8).setAlpha(config.opacity)285 }286 private again() {287 if (getLives(this.props.seed) <= 0) {288 const adID = livesExtensionsButtonToAdID(this.props.livesState)289 requestModalAd(adID)290 return291 }292 this.game.scene.remove(this)293 this.props.battle.restartTheGame()294 }295 private shareStats(player: LeaderboardResult) {296 const won = player.position === 0297 const firstPipeFail = player.score === 0298 const lossMessage = `I managed to get past ${player.score} pipes on today's Flappy Royale Daily Trial! https://flappyroyale.io`299 const winMessage = `I have the high score for today's Flappy Royale Daily Trial! Think you can beat ${player.score}? https://flappyroyale.io`300 const firstPipeFailMessage =301 "I died on the first pipe in today's Flappy Royale Daily Trial! https://flappyroyale.io"302 let text = lossMessage303 if (won) text = winMessage304 if (firstPipeFail) text = firstPipeFailMessage305 shareNatively(text, this)306 }307 public showScreenshotUI() {308 this.footerObjects.forEach(o => o.setVisible(false))309 const offset = GameHeight - 70310 const logo = this.add.image(84, offset, "logo")311 const images = setupLogoCornerImages(this, offset)312 this.shareLogoObjects = [logo, ...images]313 }314 public removeScreenshotUI() {315 this.footerObjects.forEach(o => o.setVisible(true))316 this.shareLogoObjects.forEach(o => o.destroy())317 }318 private backToMainMenu() {319 this.game.scene.remove(this)320 this.game.scene.remove(this.props.battle)321 launchMainMenu(this.game)322 }323 private addTopMedal(player: LeaderboardResult) {324 const cameFirst = player.position === 0325 const top = GameAreaTopOffset326 const medalX = GameWidth - 52327 const medalY = cameFirst ? top + 16 : top + 160328 this.add.image(medalX, medalY, "medal").setScale(0.5, 0.5)329 this.add.bitmapText(GameWidth - 36, medalY - 6, "fipps-bit", "BEST", 8)330 // Do some cute little trash bounces331 const trash1 = this.physics.add.image(medalX, medalY, "trash-1")332 trash1.setVelocity(70, -150)333 trash1.setDepth(zLevels.birdWings + 2)334 const trash2 = this.physics.add.image(medalX, medalY, "trash-2")335 trash2.setVelocity(-80, -70)336 trash2.setDepth(zLevels.birdWings + 2)337 const trash3 = this.physics.add.image(medalX, medalY, "trash-3")338 trash3.setVelocity(-60, -20)339 trash3.setDepth(zLevels.birdWings + 2)340 const trash4 = this.physics.add.image(medalX, medalY, "trash-3")341 trash4.setVelocity(-75, -100)342 trash4.setDepth(zLevels.birdWings + 2)343 trash4.setAngle(90)344 const trash5 = this.physics.add.image(medalX, medalY, "trash-2")345 trash5.setVelocity(-75, -150)346 trash5.setDepth(zLevels.birdWings + 2)347 trash5.setAngle(180)348 const trash6 = this.physics.add.image(medalX, medalY, "trash-3")349 trash6.setVelocity(10, -160)350 trash6.setDepth(zLevels.birdWings + 2)351 trash6.setAngle(90)352 // give them a hint of spin353 const trash1Body = trash1.body as Phaser.Physics.Arcade.Body354 trash1Body.setAngularVelocity(2)355 const trash2body = trash2.body as Phaser.Physics.Arcade.Body356 trash2body.setAngularVelocity(4)357 const trash3Body = trash3.body as Phaser.Physics.Arcade.Body358 trash3Body.setAngularVelocity(-6)359 }360 adsHaveBeenUnlocked() {361 const seed = this.props.seed362 bumpLivesExtensionState(seed)363 let livesToAdd = 0364 switch (livesExtensionStateForSeed(seed)) {365 case LifeStateForSeed.ExtraFive:366 livesToAdd = 5367 break368 case LifeStateForSeed.ExtraTen:369 livesToAdd = 10370 break371 case LifeStateForSeed.ExtraFifteen:372 livesToAdd = 15373 break374 }375 addLives(seed, livesToAdd)376 const options: PromptOptions = {377 title: `You've earned`,378 subtitle: `${livesToAdd} more tries!`,379 drawBgLayer: true,380 yes: "ok",381 completion: (response: boolean, prompt: Prompt) => {382 prompt.dismiss()383 }384 }385 showPrompt(options, this.game)386 this.againButton.setText("again")387 centerAlignTextLabel(this.againButton, -10)388 }389 private localTrialCacheToLeaderboard = (cache: DailyTrialRun[]): Leaderboard => {390 const settings = getUserSettings()391 const attire = settings.aesthetics.attire392 const sortedCache = _.sortBy(cache, "score").reverse()393 const lastRun = cache[cache.length - 1]394 const results = sortedCache.map((r, i) => {395 let name = r.timestamp.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })396 if (r === lastRun) {397 name = "just now"398 }399 return {400 name,401 attire,402 position: i,403 score: r.score,404 userId: name405 }406 })407 const player = results.find(r => r.name === "just now")408 // This isn't obvious from the signature, but in the new leaderboard world, there should be at most 6 elements in leaderboard.409 let shrunkResults = results.slice(0, 3)410 if (player && player.position >= 3) {411 if (player.position - 1 >= 3) {412 shrunkResults.push(results[player.position - 1])413 }414 shrunkResults.push(results[player.position])415 if (results[player.position + 1]) {416 shrunkResults.push(results[player.position + 1])417 }418 }419 console.log(shrunkResults, player)420 return { results: shrunkResults, player }421 }422 private livesLeftString(livesLeft: number): string {423 const livesText = livesLeft === 1 ? "life" : "lives"424 return `${livesLeft} ${livesText} left`425 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const shrunkResults = require('fast-check-monorepo').shrunkResults;2const fc = require('fast-check');3const property = fc.property(fc.integer(), fc.integer(), (a, b) => {4 return a + b === a + b;5});6const shrunkResult = shrunkResults(property);7console.log(shrunkResult);8const shrunkResults = require('fast-check-monorepo').shrunkResults;9const fc = require('fast-check');10const property = fc.property(fc.integer(), fc.integer(), (a, b) => {11 return a + b === a + b;12});13const shrunkResult = shrunkResults(property);14console.log(shrunkResult);15const shrunkResults = require('fast-check-monorepo').shrunkResults;16const fc = require('fast-check');17const property = fc.property(fc.integer(), fc.integer(), (a, b) => {18 return a + b === a + b;19});20const shrunkResult = shrunkResults(property);21console.log(shrunkResult);22const shrunkResults = require('fast-check-monorepo').shrunkResults;23const fc = require('fast-check');24const property = fc.property(fc.integer(), fc.integer(), (a, b) => {25 return a + b === a + b;26});27const shrunkResult = shrunkResults(property);28console.log(shrunkResult);29const shrunkResults = require('fast-check-monorepo').shrunkResults;30const fc = require('fast-check');

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { shrunkResults } = require('fast-check-monorepo');3const failingProperty = fc.property(4 fc.nat(),5 fc.nat(),6 (a, b) => a + b === 0,7);8shrunkResults(failingProperty).then(console.log);9- [shrunkResults](#shrunkresults)10- `property` **[Property](

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