How to use nextCaptures method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

Engine.js

Source:Engine.js Github

copy

Full Screen

1/**2 * Created by nathan on 13/12/16.3 */4"use strict";5var ENGINE = {6 BOARD: {7 _board: [[]],8 _tokenBlack: 0,9 _tokenWhite: 0,10 _history: [],11 12 __init: function() {13 this._board = [14 [0,0,0,0,0,0,0,0],15 [2,2,2,2,2,2,2,2],16 [2,2,2,2,2,2,2,2],17 [0,0,0,0,0,0,0,0],18 [0,0,0,0,0,0,0,0],19 [1,1,1,1,1,1,1,1],20 [1,1,1,1,1,1,1,1],21 [0,0,0,0,0,0,0,0],22 ];23 24 this._tokenBlack = 16;25 this._tokenWhite = 16;26 },27 28 show: function() {29 var buffer = "";30 for(var i = 0 ; i<8 ;i++) {31 for(var j = 0 ; j<8 ; j++) {32 buffer += this.getCell(i, j) + " ";33 }34 buffer += "\n";35 }36 37 console.log(buffer);38 return;39 },40 41 getBoard: function() {42 return this._board;43 },44 45 copyBoard: function() {46 return this._board.slice(0);47 },48 49 setBoard: function(board) {50 this._board = board.slice(0);51 return;52 },53 54 getCell: function(line, column) {55 if (!this.isInBoard(line, column)) {56 throw new Error("Coordonnées incorrectes : sortie du plateau");57 }58 59 return this._board[line][column];60 },61 62 setCell: function(line, column, value) {63 if (!this.isInBoard(line, column)) {64 throw new Error("Coordonnées incorrectes : sortie du plateau");65 }66 67 this._board[line][column] = value;68 return;69 },70 71 isInBoard: function(line, column) {72 if (line<0 || line>=8 || column<0 || column>=8) {73 return false;74 }75 return true;76 },77 78 containsToken: function(line, column) {79 if (this.isInBoard(line, column)) {80 var tokenValue = this.getCell(line, column);81 if (tokenValue > 0 && tokenValue <= 4) {82 return true;83 } 84 }85 86 return false;87 },88 89 isEmpty: function(line, column) {90 if (this.isInBoard(line, column)) {91 var tokenValue = this.getCell(line, column);92 if (tokenValue == 0) {93 return true;94 } 95 }96 97 return false;98 }, 99 addToken: function (token) {100 var value = this.getTokenValue(token.type, token.color);101 this.setCell(token.line, token.column, value);102 103 if (value % 2 == 1) {104 this._tokenWhite++;105 } else {106 this._tokenBlack++;107 }108 return;109 },110 111 removeToken: function (token) {112 var value = this.getCell(token.line, token.column);113 this.setCell(token.line, token.column, 0);114 115 if (value % 2 == 1) {116 this._tokenWhite--;117 } else {118 this._tokenBlack--;119 }120 121 return;122 },123 getTokenValue: function (type, color) {124 if (type == "pawn" && color == "white") {125 return 1;126 }127 if (type == "pawn" && color == "black") {128 return 2;129 }130 if (type == "queen" && color == "white") {131 return 3;132 }133 if (type == "queen" && color == "black") {134 return 4;135 }136 throw new Error("Valeur du jeton inconnue");137 }, 138 139 /**140 Retourne un jeton du modèle141 @param int142 @param int143 @return Object::token144 */145 getToken: function(line, column) {146 if(!ENGINE.BOARD.containsToken(line, column)) {147 return {};148 }149 150 var tokenValue = ENGINE.BOARD.getCell(line, column);151 var token = {152 line: line, 153 column: column, 154 type: undefined,155 color: undefined156 };157 158 if(tokenValue == 1 || tokenValue == 2) {159 token.type = "pawn";160 } else if (tokenValue == 3 || tokenValue == 4) {161 token.type = "queen";162 } else {163 throw new Error("Type de la pièce inconnu");164 }165 166 if(tokenValue == 1 || tokenValue == 3) {167 token.color = "white";168 } else if (tokenValue == 2 || tokenValue == 4) {169 token.color = "black";170 } else {171 throw new Error("Couleur de la pièce inconnue");172 }173 174 return token;175 },176 177 buildToken: function(type, color, line, column) {178 if(type != "pawn" && type != "queen") {179 throw new Error("Type du jeton inconnu");180 }181 if(color != "black" && color != "white") {182 throw new Error("Couleur du jeton inconnue");183 }184 if(!ENGINE.BOARD.isInBoard(line, column)) {185 throw new Error("Coordonnées inconnues");186 }187 188 var token = {189 color: color,190 type: type,191 line: line,192 column: column193 };194 return token;195 },196 197 addMovement: function (move) {198 this._history.push(move);199 },200 201 getHistory: function () {202 return this._history;203 },204 205 /**206 Retourne l'historique des mouvements en fonction de la couleur (pair : white).207 @param {string}208 @return {[string]}209 */210 getHistory$color: function (color) {211 var hist = this.getHistory();212 var histPlayer = [];213 var begin = 0;214 215 if (color == "black") {216 begin++;217 }218 219 for (var i = begin ; i<hist.length ; i=i+2) {220 histPlayer.push(hist[i]);221 }222 223 return histPlayer;224 },225 },226 227 LOGIC: {228 /**229 Surcharge la méthode pour lister les jetons230 */231 getTokenAll: function(player) {232 if(typeof(player) == "undefined") {233 return this.getTokenAll$both();234 } 235 else if(typeof(player) == "string") {236 return this.getTokenAll$player(player);237 }238 },239 240 /**241 Liste les jetons du plateau242 @return [token]243 */244 getTokenAll$both: function() {245 var tokens = [];246 247 for(var i=0 ; i<8 ; i++) {248 for(var j=0 ; j<8 ; j++) {249 if(ENGINE.BOARD.containsToken(i,j)) {250 tokens.push(ENGINE.BOARD.getToken(i,j));251 }252 }253 }254 255 return tokens;256 },257 258 getTokenAll$player: function(player) {259 var tokens = this.getTokenAll$both();260 var tokensPlayer = [];261 262 for(let token of tokens) {263 if(token.color == player) {264 tokensPlayer.push(token);265 }266 }267 268 return tokensPlayer;269 },270 271 /**272 Retourne tous les déplacements possibles d'un jeton.273 @param {Object::token}274 @param {string}275 @return {[Object::displacement]}276 */277 getDisplacement: function(token) {278 var sens = this.getSens(token);279 var destinations = [];280 281 for (let s of sens) {282 var destination = this.getFreeDestinations(token, token, s);283 if (destination.length > 0) {284 for (let dest of destination) {285 var d = {};286 d.destination = dest;287 d.source = token;288 289 destinations.push(d);290 }291 }292 }293 294 return destinations;295 },296 297 /**298 Retourne les captures simples par un pion ou une dame.299 @param {Object::token}300 @param {BOARD}301 @param {string}302 @return {[Object::capture]}303 */304 getCapture: function(token, board, backtrack) { 305 var sens = this.getSens(token, backtrack);306 307 var memory = ENGINE.BOARD.copyBoard();308 ENGINE.BOARD.setBoard(board);309 310 var captures = [];311 for (let s of sens) {312 var capture = this.getCaptureTo(token, s);313 if (Object.keys(capture).length > 0) {314 captures.push(capture);315 }316 }317 318 ENGINE.BOARD.setBoard(memory);319 return captures;320 },321 322 getSens: function (token, backtrack) {323 var sens = ["north", "east", "south", "west"];324 if (token.type == "queen") {325 var index = sens.indexOf(backtrack);326 if (index != -1) {327 sens.splice(index, 1);328 }329 } else if (token.type == "pawn") {330 if (token.color == "black") {331 var index = sens.indexOf("north");332 } else if (token.color == "white") {333 var index = sens.indexOf("south");334 }335 sens.splice(index, 1);336 }337 338 return sens;339 },340 341 /**342 Retourne une capture simple pour une direction donnée.343 @param {Object::token}344 @param {string}345 @return {Object::capture}346 */347 getCaptureTo: function(token, sens) { 348 var token = clone(token);349 var ennemy = this.getEnnemy(token, sens);350 351 if (Object.keys(ennemy).length === 0) {352 return {};353 }354 355 var destinations = this.getFreeDestinations(token, ennemy, sens);356 357 if (destinations.length == 0) {358 return {};359 }360 361 var capture = {};362 capture.source = token;363 capture.target = ennemy;364 capture.destinations = destinations;365 366 if (sens == "north") {367 capture.backtrack = "south";368 } else if (sens == "south") {369 capture.backtrack = "north";370 } else if (sens == "west") {371 capture.backtrack = "east";372 } else if (sens == "east") {373 capture.backtrack = "west";374 }375 376 return capture;377 },378 379 /**380 Retourne les destinations disponibles après une capture.381 @param {Object::token}382 @param {Object::token}383 @param {string}384 @return {[Object::coord]}385 */386 getFreeDestinations: function (token, target, sens) {387 var target = clone(target);388 var searchDestinations = true;389 var destinations = [];390 391 while (searchDestinations) {392 target = this.moveTo(target.line, target.column, sens);393 394 if (ENGINE.BOARD.isInBoard(target.line, target.column)395 && !ENGINE.BOARD.containsToken(target.line, target.column)) {396 var destination = clone(target);397 destinations.push(destination);398 } else {399 searchDestinations = false;400 }401 402 if (token.type == "pawn") {403 searchDestinations = false;404 }405 }406 407 return destinations;408 },409 410 /**411 Retourne le premier ennemi trouvé.412 @param {Object::token}413 @param {string}414 @return {Object::token}415 */416 getEnnemy: function(token, sens) {417 var token = clone(token)418 var target = {line: token.line, column: token.column};419 var ennemy = {};420 var searchEnnemy = true;421 422 while (searchEnnemy) {423 target = this.moveTo(target.line, target.column, sens);424 if (token.type == "pawn" || !ENGINE.BOARD.isInBoard(target.line, target.column)) {425 searchEnnemy = false;426 } 427 if (ENGINE.BOARD.containsToken(target.line, target.column)) {428 ennemy = ENGINE.BOARD.getToken(target.line, target.column);429 searchEnnemy = false;430 }431 }432 433 if (Object.keys(ennemy).length > 0 && ennemy.color !== token.color) {434 return ennemy;435 }436 return {};437 },438 439 /**440 Retourne les coordonnées déplacées d'une case selon une direction spécifiée.441 @param int442 @param int443 @param string444 @return Object::coord445 */446 moveTo: function (line, column, sens) {447 var coord = {line: line, column: column};448 switch (sens) {449 case "north":450 coord.line--;451 break;452 case "south":453 coord.line++;454 break;455 case "west":456 coord.column--;457 break;458 case "east":459 coord.column++;460 break;461 default:462 throw new Error("Sens inconnu");463 }464 465 return coord;466 },467 468 /**469 Retourne les plus longues captures possibles par un jeton.470 @param {Object::token}471 @return {[Object::capture}}472 */473 getCaptureAll: function(token) {474 var board = ENGINE.BOARD.copyBoard();475 var racine = {476 parent: null,477 source: token,478 target: null,479 backtrack: null,480 board: board481 }482 var captures = this.getCaptureAll$process([racine]);483 return captures;484 },485 486 /**487 Recherche les plus longues captures possibles par un jeton.488 @param {[Object::capture]}489 @return {[Object::capture]}490 */491 getCaptureAll$process: function(captures) {492 var nextSources = [];493 for (let capture of captures) {494 var nextCaptures = this.getCapture(capture.source, capture.board, capture.backtrack);495 496 if (nextCaptures.length > 0) {497 for (let nc of nextCaptures) {498 for (let destination of nc.destinations) {499 var newBoard = this.updateBoard(capture.board, nc.source, nc.target, destination);500 var token = this.updateToken(capture.source, destination);501 502 var nextSource = {};503 nextSource.parent = capture;504 nextSource.source = token;505 nextSource.target = nc.target;506 nextSource.backtrack = nc.backtrack;507 nextSource.board = newBoard;508 509 nextSources.push(nextSource);510 }511 }512 }513 }514 515 if (nextSources.length == 0) {516 return captures;517 } else {518 return this.getCaptureAll$process(nextSources);519 }520 },521 522 updateToken: function (token, destination) {523 var token = clone(token);524 if ((token.color == "black" && destination.line == 7) 525 || (token.color == "white" && destination.line == 0)) {526 token.type = "queen";527 }528 529 token.line = destination.line;530 token.column = destination.column;531 532 return token;533 },534 535 updateBoard: function(board, source, target, destination) {536 var board = board.map(function(arr) {537 return arr.slice();538 });539 540 board[source.line][source.column] = 0;541 board[target.line][target.column] = 0;542 board[destination.line][destination.column] = ENGINE.BOARD.getTokenValue(source.type, source.color);543 544 return board;545 },546 547 /**548 Sérialise les captures549 @param Object:capture550 @return [String]551 */552 serializeCaptureAll: function(captures) {553 var serializedCaptureAll = [];554 for (let capture of captures) {555 var serializedCapture = this.serializeCapture(capture);556 serializedCaptureAll.push(serializedCapture);557 }558 559 return serializedCaptureAll;560 },561 562 /**563 Sérialise les captures.564 @param {[Object::capture]}565 @return {[string]}566 */567 serializeCapture: function (capture) {568 var sources = [];569 var targets = [];570 571 var current = capture;572 while (current.parent != null) {573 sources.push({line: current.source.line, column: current.source.column});574 targets.push({line: current.target.line, column: current.target.column});575 current = current.parent;576 }577 578 sources.push({line: current.source.line, column: current.source.column});579 580 // sérialise la capture en fonction du nombre de prises581 var serializedCapture = "";582 if (targets.length == 0) {583 return serializedCapture;584 } else if (targets.length == 1) {585 serializedCapture += "C1-";586 } else {587 serializedCapture += "C" + targets.length + "-";588 }589 590 sources.reverse();591 targets.reverse();592 serializedCapture += sources[0].line + "" + sources[0].column;593 sources.splice(0,1);594 595 for(var i = 0 ; i<sources.length ; i++) {596 serializedCapture += "-" + targets[i].line + "" + targets[i].column;597 serializedCapture += "-" + sources[i].line + "" + sources[i].column;598 }599 600 601 return serializedCapture;602 },603 604 /**605 Sérialise les déplacements.606 @param {[Object::displacement]}607 @return {[string]}608 */609 serializeDisplacement: function(displacements) {610 if (displacements.length == 0) {611 return "";612 }613 614 var serialDisplacementAll = [];615 for (let displacement of displacements) {616 var serialDisplacement = "D-";617 serialDisplacement += displacement.source.line + "" + displacement.source.column + "-";618 serialDisplacement += displacement.destination.line + "" + displacement.destination.column;619 620 serialDisplacementAll.push(serialDisplacement);621 }622 623 return serialDisplacementAll;624 },625 626 /**627 Récupère tous les mouvements possibles d'un jeton sous forme sérialisée.628 @param {Object::token}629 @return {[string]}630 */631 getMovement: function (token) {632 var captures = this.getCaptureAll(token);633 if (captures.length > 1 || (captures.length == 1 && captures[0].target != null)) {634 captures = this.serializeCaptureAll(captures);635 return captures;636 }637 638 var displacements = this.getDisplacement(token);639 if (displacements.length > 0) {640 displacements = this.serializeDisplacement(displacements);641 return displacements;642 }643 644 return;645 },646 647 /**648 Récupère tous les mouvement possibles d'un joueur sous forme sérialisée.649 @param {string}650 @param {[string]}651 */652 getMovementAll: function (color) {653 var tokens = this.getTokenAll(color);654 var moves = [];655 for (let token of tokens) {656 var movesToken = this.getMovement(token);657 if (typeof movesToken != "undefined" && movesToken.length > 0) {658 for (let m of movesToken) {659 moves.push(m);660 }661 }662 }663 664 var moves = this.filterMoves(moves);665 return moves;666 },667 668 filterMoves: function (moves) {669 // cherche le mouvement avec la plus grande priorité 0:deplacement et +1point par prise670 var maxValueMove = 0;671 for (let move of moves) {672 if (this.getValueMove(move) > maxValueMove) {673 maxValueMove = move[1];674 }675 }676 677 // filtre tout sauf les mouvements avec la valeur max678 var movesCopy = moves.slice(0);679 for (let move of movesCopy) {680 if (this.getValueMove(move) < maxValueMove) {681 moves.splice(moves.indexOf(move), 1);682 }683 }684 return moves;685 },686 687 getValueMove: function (move) {688 if (move[0] == "D") {689 return 0;690 } else if (move[0] == "C") {691 return move[1];692 }693 },694 695 /**696 Effectue un mouvement (déplacement ou capture) sur le plateau.697 @param {string}698 */699 doMovement: function (move) {700 if (move[0] == "D") {701 this.doMovement$displacement(move);702 } else if (move[0] == "C") {703 this.doMovement$captureAll(move);704 }705 ENGINE.BOARD.addMovement(move);706 },707 708 doMovement$displacement: function (move) {709 var split = move.split("-");710 var source = {line: split[1][0], column: split[1][1]};711 var destination = {line: split[2][0], column: split[2][1]};712 var sourceToken = ENGINE.BOARD.getToken(source.line, source.column);713 var newToken = ENGINE.BOARD.buildToken(sourceToken.type, sourceToken.color, destination.line, destination.column);714 this.upgradePawn(newToken);715 716 ENGINE.BOARD.addToken(newToken);717 ENGINE.BOARD.removeToken(sourceToken);718 719 return;720 },721 722 doMovement$captureAll: function (move) {723 var split = move.split("-");724 split.splice(0, 1);725 var sources = [];726 var targets = [];727 728 for (let i in split) {729 if (i % 2 == 0) {730 sources.push({line: split[i][0], column: split[i][1]});731 } else if (i % 2 == 1) {732 targets.push({line: split[i][0], column: split[i][1]});733 }734 }735 736 for (var i = 0, n = targets.length; i < n ; i++) {737 this.doMovement$capture(sources[0], targets[i], sources[1]);738 sources.splice(0, 1);739 }740 741 return;742 },743 744 doMovement$capture: function (source, captured, destination) {745 var sourceToken = ENGINE.BOARD.getToken(source.line, source.column);746 var targetToken = ENGINE.BOARD.getToken(captured.line, captured.column);747 var newToken = ENGINE.BOARD.buildToken(sourceToken.type, sourceToken.color, destination.line, destination.column);748 this.upgradePawn(newToken);749 ENGINE.BOARD.addToken(newToken);750 ENGINE.BOARD.removeToken(targetToken);751 ENGINE.BOARD.removeToken(sourceToken);752 return;753 },754 755 /**756 Vérifie si la partie est terminée :757 - Retourne 0 si la partie continue758 - Retourne 1 si la partie est nulle759 - Retourne la couleur gagnante en cas de vainqueur760 @return Int761 */762 victory: function () {763 if (this.draw()) {764 return 1;765 } else if (ENGINE.BOARD._tokenBlack > 0 && ENGINE.BOARD._tokenWhite > 0 ) {766 return 0;767 } else if (ENGINE.BOARD._tokenBlack == 0) {768 return "white";769 } else if (ENGINE.BOARD._tokenWhite == 0) {770 return "black";771 } else {772 throw new Error("Détection de la fin du jeu introuvable.");773 }774 },775 776 draw: function () {777 var hist = ENGINE.BOARD.getHistory();778 var index = hist.length - 25;779 if (index < 0) {780 return false;781 }782 hist = hist.splice(hist.length-25, 25);783 for (let move of hist) {784 if (move[0] != "D") {785 return false;786 }787 }788 return true;789 },790 791 upgradePawn: function (token) {792 if (token.type == "pawn") {793 if (token.color == "black" || token.color == "white") {794 if (token.line == 7 || token.line == 0) {795 token.type = "queen";796 var value = ENGINE.BOARD.getCell(token.line, token.column);797 value += 2;798 ENGINE.BOARD.setCell(token.line, token.column, value);799 } 800 }801 }802 803 return token;804 },805 },806 807 AI: {808 _memory: {},809 810 memento: function (board, tokenWhite, tokenBlack) {811 board = ENGINE.BOARD.copyBoard();812 this._memory = {813 board: board,814 tokenWhite: tokenWhite,815 tokenBlack: tokenBlack,816 };817 },818 819 restaure: function () {820 ENGINE.BOARD.setBoard(this._memory.board);821 ENGINE.BOARD._tokenBlack = this._memory.tokenBlack;822 ENGINE.BOARD._tokenWhite = this._memory.tokenWhite;823 return824 },825 826 simulate: function (player) {827 // this.memento(board, ENGINE.BOARD._tokenBlack, ENGINE.BOARD._tokenWhite);828 // ENGINE.BOARD.setBoard(board);829 830 var turn = 0; var color;831 if (player == "black") {832 turn = 1;833 }834 835 while (ENGINE.LOGIC.victory() == 0) {836 if (turn % 2 == 0) {837 color ="white";838 } else {839 color ="black";840 }841 var moves = ENGINE.LOGIC.getMovementAll(color);842 var value = Math.floor((Math.random() * moves.length));843 var move = moves[value];844 845 ENGINE.LOGIC.doMovement(move);846 847 turn++;848 }849 return ENGINE.LOGIC.victory();850 },851 }852};853function clone(obj) {854 if (obj === null || typeof(obj) !== 'object' || 'isActiveClone' in obj)855 return obj;856 if (obj instanceof Date)857 var temp = new obj.constructor(); //or new Date(obj);858 else859 var temp = obj.constructor();860 for (var key in obj) {861 if (Object.prototype.hasOwnProperty.call(obj, key)) {862 obj['isActiveClone'] = null;863 temp[key] = clone(obj[key]);864 delete obj['isActiveClone'];865 }866 }867 return temp;...

Full Screen

Full Screen

CaptureAllGlobals.ts

Source:CaptureAllGlobals.ts Github

copy

Full Screen

1import { PoisoningFreeArray, MapSymbol, SortSymbol, ShiftSymbol, PushSymbol } from './PoisoningFreeArray.js';2import { GetSymbol, HasSymbol, SetSymbol, PoisoningFreeMap } from './PoisoningFreeMap.js';3import { AddSymbol, HasSymbol as SetHasSymbol, PoisoningFreeSet } from './PoisoningFreeSet.js';4import { AllGlobals, GlobalDetails } from './types/AllGlobals.js';5const SString = String;6const safeObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;7const safeObjectGetOwnPropertyNames = Object.getOwnPropertyNames;8const safeObjectGetOwnPropertySymbols = Object.getOwnPropertySymbols;9function compareKeys(keyA: [string | symbol, PropertyDescriptor], keyB: [string | symbol, PropertyDescriptor]): number {10 const sA = SString(keyA[0]);11 const sB = SString(keyB[0]);12 return sA < sB ? -1 : sA > sB ? 1 : 0;13}14function extractAllDescriptorsDetails(instance: unknown): [string | symbol, PropertyDescriptor][] {15 const descriptors: Record<string | symbol, PropertyDescriptor> = safeObjectGetOwnPropertyDescriptors(instance);16 const allDescriptors = PoisoningFreeArray.from([17 ...safeObjectGetOwnPropertyNames(descriptors),18 ...safeObjectGetOwnPropertySymbols(descriptors),19 ]);20 const allDescriptorsDetails = PoisoningFreeArray.from(21 allDescriptors[MapSymbol]((name): [string | symbol, PropertyDescriptor] => [22 name,23 descriptors[name as keyof typeof descriptors],24 ])25 );26 return allDescriptorsDetails[SortSymbol](compareKeys);27}28/** Flag the roots on already existing globals */29function flagRootRecursively(knownGlobals: AllGlobals, instance: unknown, currentRoot: string): void {30 const storedGlobal = knownGlobals[GetSymbol](instance);31 if (storedGlobal === undefined) {32 // Unknown global, we can stop the recursion33 return;34 }35 if (storedGlobal.rootAncestors[SetHasSymbol](currentRoot)) {36 // Already flagged with this root, we can stop the recursion37 return;38 }39 // Add the new root to the existing list40 storedGlobal.rootAncestors[AddSymbol](currentRoot);41 // Stop if the currently scanned global is a root42 if (storedGlobal.depth <= 1) {43 return;44 }45 // Recurse into children of the current node46 for (const [, descriptor] of storedGlobal.properties) {47 flagRootRecursively(knownGlobals, descriptor.value, currentRoot);48 }49}50type NextCapture = {51 instance: unknown;52 name: string;53 currentDepth: number;54 lastRootInPath: string;55};56/** Capture all globals accessible from globalThis */57export function captureAllGlobals(): AllGlobals {58 const knownGlobals = PoisoningFreeMap.from<unknown, GlobalDetails>();59 const nextCaptures = PoisoningFreeArray.from<NextCapture>([60 { instance: globalThis, name: 'globalThis', currentDepth: 0, lastRootInPath: 'globalThis' },61 ]);62 while (nextCaptures.length !== 0) {63 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion64 const { instance, name, currentDepth, lastRootInPath } = nextCaptures[ShiftSymbol]()!;65 if (typeof instance !== 'function' && typeof instance !== 'object') {66 continue;67 }68 if (instance === null || instance === undefined) {69 continue;70 }71 if (knownGlobals[HasSymbol](instance)) {72 flagRootRecursively(knownGlobals, instance, lastRootInPath);73 continue;74 }75 const allDescriptorsDetails = extractAllDescriptorsDetails(instance);76 const localGlobal: GlobalDetails = {77 name,78 depth: currentDepth,79 properties: PoisoningFreeMap.from<string | symbol, PropertyDescriptor>(),80 rootAncestors: PoisoningFreeSet.from([lastRootInPath]),81 };82 knownGlobals[SetSymbol](instance, localGlobal);83 for (let index = 0; index !== allDescriptorsDetails.length; ++index) {84 const descriptorName = allDescriptorsDetails[index][0];85 const descriptor = allDescriptorsDetails[index][1];86 localGlobal.properties[SetSymbol](descriptorName, descriptor);87 if (typeof descriptorName === 'symbol') {88 // Do not scan the internal data within keys attached symbol89 // For instance: do not monitor the content of globalThis.Symbol(JEST_STATE_SYMBOL)90 continue;91 }92 const subGlobalName = currentDepth !== 0 ? name + '.' + SString(descriptorName) : SString(descriptorName);93 const newLastRootInPath = currentDepth <= 1 ? name : lastRootInPath;94 nextCaptures[PushSymbol]({95 instance: descriptor.value,96 name: subGlobalName,97 currentDepth: currentDepth + 1,98 lastRootInPath: newLastRootInPath,99 });100 }101 }102 return knownGlobals;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import * as fc from 'fast-check';2import { NextArbitrary } from 'fast-check/lib/check/arbitrary/NextArbitrary.js';3const nextArbitrary = new NextArbitrary(fc.integer(), 10, 20);4const nextArbitrary2 = nextArbitrary.filter((x) => x % 2 === 0);5const nextArbitrary3 = nextArbitrary2.map((x) => x * 2);6const nextArbitrary4 = nextArbitrary3.chain((x) => new NextArbitrary(fc.constant(x), 5, 10));7const nextArbitrary5 = nextArbitrary4.noShrink();8const nextArbitrary6 = nextArbitrary5.withBias(1.5);9const nextArbitrary7 = nextArbitrary6.withBias(0.5);10const nextArbitrary8 = nextArbitrary7.withBias(1);11const nextArbitrary9 = nextArbitrary8.withBias(1);12const nextArbitrary10 = nextArbitrary9.withBias(1);13const nextArbitrary11 = nextArbitrary10.withBias(1);14const nextArbitrary12 = nextArbitrary11.withBias(1);15const nextArbitrary13 = nextArbitrary12.withBias(1);16const nextArbitrary14 = nextArbitrary13.withBias(1);17const nextArbitrary15 = nextArbitrary14.withBias(1);18const nextArbitrary16 = nextArbitrary15.withBias(1);19const nextArbitrary17 = nextArbitrary16.withBias(1);20const nextArbitrary18 = nextArbitrary17.withBias(1);21const nextArbitrary19 = nextArbitrary18.withBias(1);22const nextArbitrary20 = nextArbitrary19.withBias(1);23const nextArbitrary21 = nextArbitrary20.withBias(1);24const nextArbitrary22 = nextArbitrary21.withBias(1);25const nextArbitrary23 = nextArbitrary22.withBias(1);26const nextArbitrary24 = nextArbitrary23.withBias(1);27const nextArbitrary25 = nextArbitrary24.withBias(1);28const nextArbitrary26 = nextArbitrary25.withBias(1);29const nextArbitrary27 = nextArbitrary26.withBias(1);30const nextArbitrary28 = nextArbitrary27.withBias(1);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const {nextCaptures} = require('fast-check/lib/check/arbitrary/NextArbitrary.js');3const a = fc.string();4const b = fc.string();5const c = fc.string();6const gen = fc.tuple(a, b, c);7const captures = nextCaptures(gen);8const result = captures.next().value;9console.log(result);10const fc = require('fast-check');11const {nextCaptures} = require('fast-check/lib/check/arbitrary/NextArbitrary.js');12const a = fc.string();13const b = fc.string();14const c = fc.string();15const gen = fc.tuple(a, b, c);16const captures = nextCaptures(gen);17const result = captures.next().value;18console.log(result);19const fc = require('fast-check');20const {nextCaptures} = require('fast-check/lib/check/arbitrary/NextArbitrary.js');21const a = fc.string();22const b = fc.string();23const c = fc.string();24const gen = fc.tuple(a, b, c);25const captures = nextCaptures(gen);26const result = captures.next().value;27console.log(result);28const fc = require('fast-check');29const {nextCaptures} = require('fast-check/lib/check/arbitrary/NextArbitrary.js');30const a = fc.string();31const b = fc.string();32const c = fc.string();33const gen = fc.tuple(a, b, c);34const captures = nextCaptures(gen);35const result = captures.next().value;36console.log(result);37const fc = require('fast-check');38const {nextCaptures} = require('fast-check/lib/check/arbitrary/NextAr

Full Screen

Using AI Code Generation

copy

Full Screen

1import { nextCaptures } from 'fast-check';2import { NextArbitrary } from 'fast-check/build/lib/check/arbitrary/NextArbitrary';3import { Random } from 'fast-check/build/lib/random/generator/Random';4import { Stream } from 'fast-check/build/lib/stream/Stream';5import { NextValue } from 'fast-check/build/lib/check/arbitrary/definition/NextValue';6const myNextArbitrary = new NextArbitrary();7const myNextValue: NextValue = {8};9const myRandom: Random = new Random(1);10const myStream: Stream<NextValue> = myNextArbitrary.nextCaptures(11);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { nextCaptures } = require('fast-check/lib/check/arbitrary/NextArbitrary');3const arb = fc.integer();4const next = arb.generate(mrng);5const captures = nextCaptures(next.value);6console.log(captures);7const fc = require('fast-check');8const { nextCaptures } = require('fast-check/lib/check/arbitrary/NextArbitrary');9const arb = fc.integer();10const next = arb.generate(mrng);11const captures = nextCaptures(next.value);12console.log(captures);13const fc = require('fast-check');14const { nextCaptures } = require('fast-check/lib/check/arbitrary/NextArbitrary');15const arb = fc.integer();16const next = arb.generate(mrng);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { nextCaptures } = require('fast-check-monorepo');3 .array(fc.integer(), 1, 5)4 .chain((arr) => fc.tuple(fc.constant(arr), fc.constant(arr)));5nextCaptures(generator, 5).then((captures) => {6 console.log(captures);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { nextCaptures } = require('fast-check-monorepo');3const myArbitrary = fc.string();4const myArbitraryWithNextCaptures = nextCaptures(myArbitrary);5fc.assert(6 fc.property(myArbitraryWithNextCaptures, (value) => {7 console.log(value);8 return true;9 })10);

Full Screen

Using AI Code Generation

copy

Full Screen

1function nextCaptures(regexp, str) {2 const captures = regexp.exec(str);3 if (captures === null) {4 return [];5 }6 if (captures.length === 1) {7 return [[]];8 }9 const restCaptures = nextCaptures(regexp, str.substring(captures

Full Screen

Using AI Code Generation

copy

Full Screen

1import { nextString, nextCaptures } from 'fast-check';2const nextStringArb = nextString();3const nextIntArb = nextCaptures(/[0-9]{1,2}/);4const stringList = nextStringArb.next().value;5const intList = nextIntArb.next().value;6console.log(stringList);7console.log(intList);

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