How to use state.get method in Cypress

Best JavaScript code snippet using cypress

opcodes.js

Source:opcodes.js Github

copy

Full Screen

1var misc = require ( './misc.js' );2function make_opcode ( code, name, argc, stack, func ) {3  return {4    code: code,5    name: name,6    argc: argc,7    stack: stack,8    func: func,9    };10  }11var opcodes = [12  make_opcode ( 0x00, 'next', 0, 0,13  function noop ( state ) {14    // Since noop's are shifted into the bunch, or used to pad bunches, as soon15    // as a noop is encountered, the next bunch needs to be loaded.16    // It might make sense to refactor this, but this is also the must17    // efficient way to implement.18    if ( state.get_pc () === state.func.length ) {19      state.run = false;20      }21    else {22      state.check_bunch ( state.func[state.get_pc ( )] );23      state.bunch = state.func[state.get_pc ( ) ].slice ( 0 );24      state.move_pc ( 1 );25      }26    } ),27  make_opcode ( 0x01, 'dup_1', 2, 1,28    function dup1 ( state ) {29    state.push ( state.get_stack ( state.get_arg ( 1 ) ) );30    } ),31  make_opcode ( 0x02, 'li_w', 1, 1,32  function li_w ( state ) {33    state.push ( state.func[ state.get_pc ( ) ] );34    state.move_pc ( 1 );35    } ),36  make_opcode ( 0x03, 'set_1', 2, -1,37    function set ( state ) {38    state.set_stack ( state.get_arg ( 1 ), state.pop ( ) );39    } ),40  make_opcode ( 0x04, 'pop', 1, -1,41  function pop ( state ) {42    state.pop ( );43    } ),44  make_opcode ( 0x05, 'call_1', 2, 0,45  function call ( state ) {46    var arg_count = state.get_arg ( 1 );47    var func = state.get_stack ( arg_count );48    if ( func.type === 'external' ) {49      var size = state.stack.length;50      var args = state.stack.splice ( size - arg_count, size );51      var res = func.func.apply ( null, args );52      // Pop the args.53      for ( var i = 0; i < arg_count; i++ ) {54        state.pop ( );55        }56      // Pop the function.57      state.pop ( );58      // Push the result59      state.push ( res );60      }61    else if ( func.type === 'internal' ) {62      state.call_stack[state.call_stack_top++] = [state.func, state._pc, state.stack_top - ( arg_count + 1 ) ];63      state.func = func.code;64      state._pc = 0;65      }66    } ),67  make_opcode ( 0x06, 'ret', 1, 0,68  function ret ( state ) {69    if ( state.call_stack_top === 0 ) {70      state.run = false;71      }72    else {73      var info = state.call_stack[--state.call_stack_top];74      state.func = info[0];75      state._pc = info[1];76      var out = state.pop ( );77      while ( state.stack_top > info[2] ) {78        state.pop ( );79        }80      state.push ( out );81      state.clear_bunch ( );82      }83    } ),84  make_opcode ( 0x07, 'eq', 1, -1,85  function eq ( state ) {86    state.push ( state.pop ( ) === state.pop ( ) );87    } ),88  make_opcode ( 0x08, 'j_1', 2, 0,89  function j_1 ( state ) {90    state.move_pc ( state.get_arg ( 1 ) );91    } ),92  make_opcode ( 0x09, 'j_2', 3, 0,93  function j_2 ( state ) {94    state.move_pc ( state.get_arg ( 1 ) << 8 + state.get_arg ( 2 ) );95    } ),96  make_opcode ( 0x0a, 'j_3', 4, 0,97  function j_3 ( state ) {98    state.move_pc ( ( state.get_arg ( 1 ) << 8 +99                      state.get_arg ( 2 ) << 8 ) +100                      state.get_arg ( 3 ) );101    } ),102  make_opcode ( 0x0b, 'j_w', 1, 0,103  function j_w ( state ) {104    state.move_pc ( state.func[ state.get_pc ( ) ] );105    } ),106  make_opcode ( 0x0c, 'bz_1', 2, -1,107  function bz_1 ( state ) {108    if ( ! state.pop ( ) ) {109      state.move_pc ( state.get_arg ( 1 ) );110      }111    } ),112  make_opcode ( 0x0d, 'bz_2', 3, -1,113  function bz_2 ( state ) {114    if ( ! state.pop ( ) ) {115      state.move_pc ( state.get_arg ( 1 ) << 8 + state.get_arg ( 2 ) );116      }117    } ),118  make_opcode ( 0x0e, 'bz_3', 4, -1,119  function bz_3 ( state ) {120    if ( ! state.pop ( ) ) {121    state.move_pc ( ( state.get_arg ( 1 ) << 8 +122                      state.get_arg ( 2 ) << 8 ) +123                      state.get_arg ( 3 ) );124      }125    } ),126  make_opcode ( 0x0f, 'bz_w', 1, -1,127  function bz_w ( state ) {128    if ( ! state.pop ( ) ) {129      state.move_pc ( state.func[ state.get_pc ( ) ] );130      }131    } ),132  make_opcode ( 0x10, 'not', 1, 0,133  function not ( state ) {134    state.push ( ! state.pop ( ) );135    } ),136  make_opcode ( 0x11, 'fadd', 1, -1,137  function fadd ( state ) {138    var right = state.pop ( );139    var left = state.pop ( );140    state.push ( left + right );141    } ),142  make_opcode ( 0x12, 'fsub', 1, -1,143  function fsub ( state ) {144    var right = state.pop ( );145    var left = state.pop ( );146    state.push ( left - right );147    } ),148  make_opcode ( 0x13, 'fmul', 1, -1,149  function fmul ( state ) {150    var right = state.pop ( );151    var left = state.pop ( );152    state.push ( left * right );153    } ),154  make_opcode ( 0x14, 'fdiv', 1, -1,155  function fdiv ( state ) {156    var right = state.pop ( );157    var left = state.pop ( );158    state.push ( left / right );159    } ),160  make_opcode ( 0x15, 'fmod', 1, -1,161  function fmod ( state ) {162    var right = state.pop ( );163    var left = state.pop ( );164    state.push ( left % right );165    } ),166  make_opcode ( 0x16, 'iadd', 1, -1,167  function iadd ( state ) {168    var right = state.pop ( );169    var left = state.pop ( );170    state.push ( left + right );171    } ),172  make_opcode ( 0x17, 'isub', 1, -1,173  function isub ( state ) {174    var right = state.pop ( );175    var left = state.pop ( );176    state.push ( left - right );177    } ),178  make_opcode ( 0x18, 'imul', 1, -1,179  function imul ( state ) {180    var right = state.pop ( );181    var left = state.pop ( );182    state.push ( left * right );183    } ),184  make_opcode ( 0x19, 'idiv', 1, -1,185  function idiv ( state ) {186    var right = state.pop ( );187    var left = state.pop ( );188    state.push ( left / right );189    } ),190  make_opcode ( 0x1a, 'imod', 1, -1,191  function imod ( state ) {192    var right = state.pop ( );193    var left = state.pop ( );194    state.push ( left % right );195    } ),196  make_opcode ( 0x1b, 'uadd', 1, -1,197  function uadd ( state ) {198    var right = state.pop ( );199    var left = state.pop ( );200    state.push ( left + right );201    } ),202  make_opcode ( 0x1c, 'usub', 1, -1,203  function usub ( state ) {204    var right = state.pop ( );205    var left = state.pop ( );206    state.push ( left - right );207    } ),208  make_opcode ( 0x1d, 'umul', 1, -1,209  function umul ( state ) {210    var right = state.pop ( );211    var left = state.pop ( );212    state.push ( left * right );213    } ),214  make_opcode ( 0x1e, 'udiv', 1, -1,215  function udiv ( state ) {216    var right = state.pop ( );217    var left = state.pop ( );218    state.push ( left / right );219    } ),220  make_opcode ( 0x1f, 'umod', 1, -1,221  function umod ( state ) {222    var right = state.pop ( );223    var left = state.pop ( );224    state.push ( left % right );225    } ),226  make_opcode ( 0x20, 'refi', 1, 0,227  function refi ( state ) {228    // TODO(kzentner): Do we want to emulate reference counting in javascript.229    } ),230  make_opcode ( 0x21, 'refd', 1, 0,231  function refd ( state ) {232    // TODO(kzentner): Do we want to emulate reference counting in javascript.233    state.pop ( );234    } ),235  make_opcode ( 0x22, 'make_1', 2, 0,236  function make1 ( state ) {237    var field_count = state.get_arg ( 1 );238    var size = state.stack.length;239    var obj = state.stack.splice ( size - field_count - 1, size );240    // Pop the fields.241    for ( var i = 0; i < field_count; i++ ) {242      state.pop ( );243      }244    // Pop the type tag.245    state.pop ( );246    state.push ( obj );247    } ),248  make_opcode ( 0x23, 'pushfree_1', 1, 0,249  function pushfree_1 ( state ) {250    // TODO(kzentner): Do we want to emulate reference counting in javascript?251    } ),252  make_opcode ( 0x24, 'popfree_1', 1, 0,253  function popfree_1 ( state ) {254    // TODO(kzentner): Do we want to emulate reference counting in javascript?255    } ),256  make_opcode ( 0x25, 'clone', 1, 0,257  function clone ( state ) {258    function copy ( obj ) {259      if ( typeof ( obj ) !== 'object' ) {260        return obj;261        }262      out = [];263      obj.forEach ( function ( val ) {264        // TODO(kzentner): Only recurse on mutable objects.265        out.push ( copy ( val ) );266        } );267      return out;268      }269    state.push ( copy ( state.pop ( ) ) );270    } ),271  make_opcode ( 0x26, 'safe', 1, 0,272  function safe ( state ) {273    // TODO(kzentner): Implement safe point instrumentation.274    } ),275  make_opcode ( 0x27, 'read_1', 2, 0,276  function read_1 ( state ) {277    state.push ( state.pop ( )[ state.get_arg ( 1 ) - 1 ] );278    } ),279  make_opcode ( 0x28, 'write_1', 2, 0,280  function write_1 ( state ) {281    var val = state.pop ( );282    var obj = state.pop ( );283    obj[ state.get_arg ( 1 ) - 1 ] = val;284    } ),285  make_opcode ( 0x29, 'stack_1', 2, 0,286  function stack_1 ( state ) {287    state.stack_top += state.get_arg ( 1 );288    } ),289  make_opcode ( 0x2a, 'noop', 1, 0,290  function noop ( state ) {291    } ),292  make_opcode ( 0x2b, 'end', 1, 0,293  function end ( state ) {294    state.run = false;295    } ),296  make_opcode ( 0x2c, 'debug', 1, 0,297  function debug ( state ) {298    state.debug = ! state.debug;299    } ),300  make_opcode ( 0x2d, 'f2i', 1, 0,301  function f2i ( state ) {302    // TODO(kzentner): Implement integer arithmetic in the vm.303    } ),304  make_opcode ( 0x2e, 'i2f', 1, 0,305  function i2f ( state ) {306    // TODO(kzentner): Implement integer arithmetic in the vm.307    } ),308  make_opcode ( 0x2f, 'band', 1, -1,309  function band ( state ) {310    var right = state.pop ( );311    var left = state.pop ( );312    state.push ( left & right );313    } ),314  make_opcode ( 0x30, 'bor', 1, -1,315  function band ( state ) {316    var right = state.pop ( );317    var left = state.pop ( );318    state.push ( left | right );319    } ),320  make_opcode ( 0x31, 'bxor', 1, -1,321  function bxor ( state ) {322    var right = state.pop ( );323    var left = state.pop ( );324    state.push ( left ^ right );325    } ),326  make_opcode ( 0x32, 'bnot', 1, 0,327  function bnot ( state ) {328    state.push ( ~state.pop ( ) );329    } ),330  make_opcode ( 0x33, 'bsl', 1, -1,331  function bsl ( state ) {332    var right = state.pop ( );333    var left = state.pop ( );334    state.push ( left << right );335    } ),336  make_opcode ( 0x34, 'bsrl', 1, -1,337  function bsra ( state ) {338    var right = state.pop ( );339    var left = state.pop ( );340    state.push ( left >>> right );341    } ),342  make_opcode ( 0x35, 'bsra', 1, -1,343  function bsrl ( state ) {344    var right = state.pop ( );345    var left = state.pop ( );346    state.push ( left >> right );347    } ),348  ];349function make_optables ( ops ) {350  var out = {351    op: {},352    code_to_obj: [],353    code: {},354    name: [],355    argc: [],356    func: [],357    stack: [],358    };359  for ( var i in ops ) {360    out.op[ops[i].name] = ops[i];361    out.code_to_obj[ops[i].code] = ops[i];362    out.code[ops[i].name] = ops[i].code;363    out.argc[ops[i].code] = ops[i].argc;364    out.func[ops[i].code] = ops[i].func;365    out.name[ops[i].code] = ops[i].name;366    out.stack[ops[i].code] = ops[i].stack;367    }368  return out;369  }370var tables = make_optables ( opcodes );371var code = tables.code;372var argc = tables.argc;373var func = tables.func;374var name = tables.name;375var code_to_obj = tables.code_to_obj;376var op = tables.op;377var stack = tables.stack;378exports.opcodes = opcodes;379exports.op = op;380exports.code_to_obj = code_to_obj;381exports.code = code;382exports.argc = argc;383exports.func = func;384exports.name = name;385exports.tables = tables;...

Full Screen

Full Screen

mcts.js

Source:mcts.js Github

copy

Full Screen

1const test = require('tape');2const createStore = require('../game/store');3const predictionReducer = require('../ai/reducers');4const gameReducer = require('../game/reducers');5const actions = require('../ai/actions');6const GameState = require('../game/state');7const {SimulationState} = require('../ai/state');8test('select a node in the tree and expand it (hero)', (t) => {9  let currentStatus = void 0;10  const initialGameState = GameState([11    {entity: 'hero', name: 'position', x: 0, y: 4},12    {entity: 'hero', name: 'lastMove', move: 'up'},13    {entity: 'hero', name: 'count', count: 0},14    {entity: 'hero', name: 'score', score: 0},15    {entity: 'hero', name: 'player', playerName: 'pole'},16    {entity: 'hero', name: 'target', target: 'reward'},17    {entity: 'hero', name: 'active', active: false},18    {entity: 'hero', name: 'render', avatar: 'H'},19    {entity: 'ghost', name: 'position', x: 7, y: 0},20    {entity: 'ghost', name: 'lastMove', move: 'up'},21    {entity: 'ghost', name: 'count', count: 0},22    {entity: 'ghost', name: 'score', score: 0},23    {entity: 'ghost', name: 'ai', aiName: 'terminator'},24    {entity: 'ghost', name: 'target', target: 'hero'},25    {entity: 'ghost', name: 'active', active: true},26    {entity: 'ghost', name: 'render', avatar: 'G'},27    {entity: 'reward', name: 'position', x: 6, y: 6},28    {entity: 'reward', name: 'render', avatar: 'R'}29  ]);30  const initialPredictionState = SimulationState(initialGameState);31  const simplePolicy = (entity) => {32    const ids = [0, 1];33    return (simulationState) => {34      return ids.shift();35    };36  }37  const predictionStore = createStore(predictionReducer(gameReducer, simplePolicy), initialPredictionState);38  predictionStore.dispatch(actions.selectState('ghost'));39  currentStatus = predictionStore.getState();40  t.equal(currentStatus.nodes.size, 1);41  t.equal(currentStatus.currentNodeId, 0);42  predictionStore.dispatch(actions.expandState());43  currentStatus = predictionStore.getState();44  t.equal(currentStatus.nodes.size, 4);45  t.equal(currentStatus.nodes.get(0).children.toJS().join(''), '123');46  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'x'), 0);47  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'y'), 3);48  t.equal(currentStatus.nodes.get(2).gameState.get('hero', 'x'), 0);49  t.equal(currentStatus.nodes.get(2).gameState.get('hero', 'y'), 5);50  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'x'), 1);51  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'y'), 4);52  predictionStore.dispatch(actions.selectState('hero'));53  currentStatus = predictionStore.getState();54  t.equal(currentStatus.currentNodeId, 1);55  predictionStore.dispatch(actions.simulate());56  currentStatus = predictionStore.getState();57  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'score'), 0);58  t.equal(currentStatus.nodes.get(1).gameState.get('ghost', 'score'), 0);59  predictionStore.dispatch(actions.backpropagate());60  currentStatus = predictionStore.getState();61  t.equal(currentStatus.nodes.get(1).count.get('hero'), 1);62  t.equal(currentStatus.nodes.get(1).score.get('hero'), 0);63  t.equal(currentStatus.nodes.get(0).count.get('hero'), 1);64  t.equal(currentStatus.nodes.get(0).score.get('hero'), 0);65  t.end();66});67test('test simulation, backpropagation (hero)', (t) => {68  let currentStatus = void 0;69  const initialGameState = GameState([70    {entity: 'hero', name: 'position', x: 5, y: 6},71    {entity: 'hero', name: 'lastMove', move: 'up'},72    {entity: 'hero', name: 'count', count: 0},73    {entity: 'hero', name: 'score', score: 0},74    {entity: 'hero', name: 'player', playerName: 'pole'},75    {entity: 'hero', name: 'target', target: 'reward'},76    {entity: 'hero', name: 'active', active: false},77    {entity: 'hero', name: 'render', avatar: 'H'},78    {entity: 'ghost', name: 'position', x: 6, y: 5},79    {entity: 'ghost', name: 'lastMove', move: 'up'},80    {entity: 'ghost', name: 'count', count: 0},81    {entity: 'ghost', name: 'score', score: 0},82    {entity: 'ghost', name: 'ai', aiName: 'terminator'},83    {entity: 'ghost', name: 'target', target: 'hero'},84    {entity: 'ghost', name: 'active', active: true},85    {entity: 'ghost', name: 'render', avatar: 'G'},86    {entity: 'reward', name: 'position', x: 6, y: 6},87    {entity: 'reward', name: 'render', avatar: 'R'}88  ]);89  const initialPredictionState = SimulationState(initialGameState);90  const simplePolicy = (entity) => (simulationState) => {91    return 3;92  };93  const predictionStore = createStore(predictionReducer(gameReducer, simplePolicy), initialPredictionState);94  predictionStore.dispatch(actions.selectState('ghost'));95  currentStatus = predictionStore.getState();96  t.equal(currentStatus.currentNodeId, 0);97  predictionStore.dispatch(actions.expandState());98  currentStatus = predictionStore.getState();99  t.equal(currentStatus.nodes.size, 5);100  t.equal(currentStatus.nodes.get(0).children.toJS().join(''), '1234');101  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'x'), 5);102  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'y'), 5);103  t.equal(currentStatus.nodes.get(2).gameState.get('hero', 'x'), 5);104  t.equal(currentStatus.nodes.get(2).gameState.get('hero', 'y'), 7);105  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'x'), 6);106  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'y'), 6);107  t.equal(currentStatus.nodes.get(4).gameState.get('hero', 'x'), 4);108  t.equal(currentStatus.nodes.get(4).gameState.get('hero', 'y'), 6);109  predictionStore.dispatch(actions.selectState('hero'));110  currentStatus = predictionStore.getState();111  t.equal(currentStatus.currentNodeId, 3);112  predictionStore.dispatch(actions.simulate());113  currentStatus = predictionStore.getState();114  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'score'), 1);115  t.equal(currentStatus.nodes.get(3).gameState.get('ghost', 'score'), 0);116  predictionStore.dispatch(actions.backpropagate());117  currentStatus = predictionStore.getState();118  t.equal(currentStatus.nodes.get(3).count.get('hero'), 1);119  t.equal(currentStatus.nodes.get(3).score.get('hero'), 1);120  t.equal(currentStatus.nodes.get(0).count.get('hero'), 1);121  t.equal(currentStatus.nodes.get(0).score.get('hero'), 1);122  t.end();123});124test('test simulation, backpropagation (ghost)', (t) => {125  let currentStatus = void 0;126  const initialGameState = GameState([127    {entity: 'hero', name: 'position', x: 4, y: 6},128    {entity: 'hero', name: 'lastMove', move: 'up'},129    {entity: 'hero', name: 'count', count: 0},130    {entity: 'hero', name: 'score', score: 0},131    {entity: 'hero', name: 'player', playerName: 'pole'},132    {entity: 'hero', name: 'target', target: 'reward'},133    {entity: 'hero', name: 'active', active: false},134    {entity: 'hero', name: 'render', avatar: 'H'},135    {entity: 'ghost', name: 'position', x: 5, y: 5},136    {entity: 'ghost', name: 'lastMove', move: 'up'},137    {entity: 'ghost', name: 'count', count: 0},138    {entity: 'ghost', name: 'score', score: 0},139    {entity: 'ghost', name: 'ai', aiName: 'terminator'},140    {entity: 'ghost', name: 'target', target: 'hero'},141    {entity: 'ghost', name: 'active', active: true},142    {entity: 'ghost', name: 'render', avatar: 'G'},143    {entity: 'reward', name: 'position', x: 6, y: 6},144    {entity: 'reward', name: 'render', avatar: 'R'}145  ]);146  const initialPredictionState = SimulationState(initialGameState);147  const simplePolicy = (entity) => {148    const ids = [3, 6];149    return (simulationState) => {150      return ids.shift();151    };152  }153  const predictionStore = createStore(predictionReducer(gameReducer, simplePolicy), initialPredictionState);154  predictionStore.dispatch(actions.selectState('ghost'));155  currentStatus = predictionStore.getState();156  t.equal(currentStatus.nodes.size, 1);157  t.equal(currentStatus.currentNodeId, 0);158  predictionStore.dispatch(actions.expandState());159  currentStatus = predictionStore.getState();160  t.equal(currentStatus.nodes.size, 5);161  t.equal(currentStatus.nodes.get(0).children.toJS().join(''), '1234');162  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'x'), 4);163  t.equal(currentStatus.nodes.get(1).gameState.get('hero', 'y'), 5);164  t.equal(currentStatus.nodes.get(2).gameState.get('hero', 'x'), 4);165  t.equal(currentStatus.nodes.get(2).gameState.get('hero', 'y'), 7);166  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'x'), 5);167  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'y'), 6);168  t.equal(currentStatus.nodes.get(4).gameState.get('hero', 'x'), 3);169  t.equal(currentStatus.nodes.get(4).gameState.get('hero', 'y'), 6);170  predictionStore.dispatch(actions.selectState('hero'));171  currentStatus = predictionStore.getState();172  t.equal(currentStatus.currentNodeId, 3);173  predictionStore.dispatch(actions.simulate());174  currentStatus = predictionStore.getState();175  t.equal(currentStatus.nodes.get(3).gameState.get('hero', 'score'), 0);176  t.equal(currentStatus.nodes.get(3).gameState.get('ghost', 'score'), 0);177  predictionStore.dispatch(actions.backpropagate());178  currentStatus = predictionStore.getState();179  t.equal(currentStatus.nodes.get(3).count.get('hero'), 1);180  t.equal(currentStatus.nodes.get(3).score.get('hero'), 0);181  t.equal(currentStatus.nodes.get(0).count.get('hero'), 1);182  t.equal(currentStatus.nodes.get(0).score.get('hero'), 0);183  predictionStore.dispatch(actions.selectState('hero'));184  predictionStore.dispatch(actions.expandState());185  currentStatus = predictionStore.getState();186  t.equal(currentStatus.nodes.size, 9);187  t.equal(currentStatus.nodes.get(3).children.toJS().join(''), '5678');188  t.equal(currentStatus.nodes.get(5).gameState.get('ghost', 'x'), 5);189  t.equal(currentStatus.nodes.get(5).gameState.get('ghost', 'y'), 4);190  t.equal(currentStatus.nodes.get(6).gameState.get('ghost', 'x'), 5);191  t.equal(currentStatus.nodes.get(6).gameState.get('ghost', 'y'), 6);192  t.equal(currentStatus.nodes.get(7).gameState.get('ghost', 'x'), 6);193  t.equal(currentStatus.nodes.get(7).gameState.get('ghost', 'y'), 5);194  t.equal(currentStatus.nodes.get(8).gameState.get('ghost', 'x'), 4);195  t.equal(currentStatus.nodes.get(8).gameState.get('ghost', 'y'), 5);196  predictionStore.dispatch(actions.selectState('ghost'));197  currentStatus = predictionStore.getState();198  t.equal(currentStatus.currentNodeId, 6);199  predictionStore.dispatch(actions.simulate());200  currentStatus = predictionStore.getState();201  t.equal(currentStatus.nodes.get(6).gameState.get('hero', 'score'), 0);202  t.equal(currentStatus.nodes.get(6).gameState.get('ghost', 'score'), 1);203  predictionStore.dispatch(actions.backpropagate());204  currentStatus = predictionStore.getState();205  t.equal(currentStatus.currentNodeId, 6);206  currentStatus = predictionStore.getState();207  t.equal(currentStatus.nodes.get(6).count.get('ghost'), 1);208  t.equal(currentStatus.nodes.get(6).score.get('ghost'), 1);209  t.equal(currentStatus.nodes.get(3).count.get('ghost'), 1);210  t.equal(currentStatus.nodes.get(3).score.get('ghost'), 1);211  t.equal(currentStatus.nodes.get(0).count.get('ghost'), 1);212  t.equal(currentStatus.nodes.get(0).score.get('ghost'), 1);213  t.end();...

Full Screen

Full Screen

selectors.js

Source:selectors.js Github

copy

Full Screen

1export default {2    recordCount: (state, {id}) => {3        const sharedView = state.getIn(['cache', 'SharedView', id])4        const view = state.getIn(['cache', 'View', sharedView.get('view')])5        return view.get('records').count()6    },7    primaryFieldId: (state, {id}) => {8        const sharedView = state.getIn(['cache', 'SharedView', id])9        const view = state.getIn(['cache', 'View', sharedView.get('view')])10        const table = state.getIn(['cache', 'Table', view.get('tableId')])11        return table.get('primaryFieldId')12    },13    coverFieldId: (state, {id}) => {14        const sharedView = state.getIn(['cache', 'SharedView', id])15        const view = state.getIn(['cache', 'View', sharedView.get('view')])16        return view.get('coverFieldId')17    },18    coverFitTypeId: (state, {id}) => {19        const sharedView = state.getIn(['cache', 'SharedView', id])20        const view = state.getIn(['cache', 'View', sharedView.get('view')])21        return view.get('coverFitTypeId')22    },23    visibleFieldOrder: (state, {id}) => {24        const sharedView = state.getIn(['cache', 'SharedView', id])25        const view = state.getIn(['cache', 'View', sharedView.get('view')])26        return view27            .get('fieldVisibilitiesById')28            .sort((a, b) => {29                const _a = state.getIn(['cache', 'FieldIndice', a, 'indice'])30                const _b = state.getIn(['cache', 'FieldIndice', b, 'indice'])31                return _a - _b32            })33            .map(id => {34                return state.getIn(['cache', 'FieldVisibility', id])35            })36            .filter(v => {37                return v.get('visibility')38            })39            .map(v => v.get('fieldId'))40            .toJS()41    },42    fieldOrder: (state, {id}) => {43        const sharedView = state.getIn(['cache', 'SharedView', id])44        const view = state.getIn(['cache', 'View', sharedView.get('view')])45        return view46            .get('fieldVisibilitiesById')47            .sort((a, b) => {48                const _a = state.getIn(['cache', 'FieldIndice', a, 'indice'])49                const _b = state.getIn(['cache', 'FieldIndice', b, 'indice'])50                return _a - _b51            })52            .map(id => {53                return state.getIn(['cache', 'FieldIndice', id])54            })55            .map(v => v.get('fieldId'))56            .toJS()57    },58    fields: (state, {id}) => {59        const sharedView = state.getIn(['cache', 'SharedView', id])60        const view = state.getIn(['cache', 'View', sharedView.get('view')])61        const table = state.getIn(['cache', 'Table', view.get('tableId')])62        return table63            .get('fields')64            .map(id => {65                return state.getIn(['cache', 'Field', id])66            })67            .toJS()68    },69    records: (state, {id}) => {70        const sharedView = state.getIn(['cache', 'SharedView', id])71        const view = state.getIn(['cache', 'View', sharedView.get('view')])72        return view.get('records')73    },74    recordName: (state, {id}) => {75        const record = state.getIn(['cache', 'Record', id])76        const table = state.getIn(['cache', 'Table', record.get('tableId')])77        const primaryFieldId = table.get('primaryFieldId')78        const cellId = [id, primaryFieldId].join('/')79        return state.getIn(['cache', 'SingleLineTextCell', cellId, 'text'])80    },81    coverAttachments: (state, {id, coverFieldId}) => {82        const cellId = [id, coverFieldId].join('/')83        const attachments = state.getIn(['cache', 'AttachmentCell', cellId, 'attachments'])84        return attachments ? attachments.toJS() : null85    },86    tableFields: (state, {id}) => {87        const table = state.getIn(['cache', 'Table', id])88        const fields = table.get('fields').map(id => {89            return state.getIn(['cache', 'Field', id])90        })91        return fields.toJS()92    },93    tableVisibleFieldOrder: (state, {id}) => {94        const table = state.getIn(['cache', 'Table', id])95        return table.get('fields').toJS()96    },97    recordFields: (state, {id}) => {98        const record = state.getIn(['cache', 'Record', id])99        const table = state.getIn(['cache', 'Table', record.get('tableId')])100        const fields = table.get('fields').map(id => {101            return state.getIn(['cache', 'Field', id])102        })103        return fields.toJS()104    },105    recordVisibleFieldOrder: (state, {id}) => {106        const record = state.getIn(['cache', 'Record', id])107        const table = state.getIn(['cache', 'Table', record.get('tableId')])108        return table.get('fields').toJS()109    },110    viewName: (state, {id}) => {111        const sharedView = state.getIn(['cache', 'SharedView', id])112        const view = state.getIn(['cache', 'View', sharedView.get('view')])113        return view.get('name')114    }...

Full Screen

Full Screen

welcome.js

Source:welcome.js Github

copy

Full Screen

...8let document;9let $;10function connectRadio(e) {11    disconnectRadio(e);12    let serPortName = global_state.get('serial_port');13    if (!serPortName) {14        throw "No serial port set!";15    }16    let serportObj = serport.open(serPortName);17    global_state.set('serial_port_object', serportObj);18}19function disconnectRadio(e) {20    let serportObj = global_state.get('serial_port_object');21    if (serportObj) {22        serportObj.close();23        global_state.set('serial_port_object', undefined);24    }25}26function xbeeAddrKeyup(e) {27    /* jshint validthis: true */28    if (this.validity.valid) {29        global_state.get('robot_application').radio_pairing_info =30            this.value;31    }32}33function serialPortKeyup(e) {34    /* jshint validthis: true */35    if (this.validity.valid) {36        global_state.set('serial_port', this.value);37        // TODO(rqou): Persist this somewhere?38    }39}40function updateFromSavedState() {41    let robotApp = global_state.get('robot_application');42    if (robotApp.radio_pairing_info) {43        $("#xbeeAddrInput").val(robotApp.radio_pairing_info);44    }45    let serportName = global_state.get('serial_port');46    if (serportName) {47        $("#serialPort").val(serportName);48    }49}50function onLoad() {51    if (!global_state.get('robot_application')) {52        let emptyApp = robot_application.CreateEmptyRobotApplication();53        // This assumes welcome is loaded first before other pages. Seems to be54        // a fine assumption for now.55        global_state.set('robot_application', emptyApp);56    }57    updateFromSavedState();58    $("#xbeeAddrInput").keyup(xbeeAddrKeyup);59    $("#openButton").click(onOpenClicked);60    $("#saveButton").click(onSaveClicked);61    $("#serialPort").keyup(serialPortKeyup);62    $("#connectButton").click(connectRadio);63    $("#disconnectButton").click(disconnectRadio);64}65function onOpenClicked(e) {66    let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);67    fp.init(window, "Open program", Ci.nsIFilePicker.modeOpen);68    fp.defaultExtension = "yaml";69    fp.defaultString = "*.yaml";70    fp.appendFilter("YAML files", "*.yaml");71    function openCallback(result) {72        if (result == Ci.nsIFilePicker.returnCancel) {73            return;74        }75        global_state.set('robot_application',76            robot_application.LoadRobotApplication(fp.file.path));77        updateFromSavedState();78    }79    fp.open({done: openCallback});80}81function onSaveClicked(e) {82    let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);83    fp.init(window, "Save program", Ci.nsIFilePicker.modeSave);84    fp.defaultExtension = "yaml";85    fp.defaultString = "untitled.yaml";86    fp.appendFilter("YAML files", "*.yaml");87    function saveCallback(result) {88        if (result == Ci.nsIFilePicker.returnCancel) {89            return;90        }91        global_state.get('robot_application').save(fp.file.path);92    }93    fp.open({done: saveCallback});94}95exports.init = function(_window) {96    window = _window;97    document = window.document;98    $ = require('jquery')(window);99    $(onLoad);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...38      });39    }40  );41};42const getAlertsBase = state => state.get('alerts');43export const getAlerts = createSelector([getAlertsBase], (base) => {44  let arr = [];45  base.forEach(item => {46    arr.push({47      message: item.get('message'),48      title: item.get('title'),49      key: item.get('key'),50      dismissAfter: 5000,51      barStyle: {52        zIndex: 200,53      },54    });55  });56  return arr;57});58export const makeGetNotification = () => {59  return createSelector([60    (_, base)             => base,61    (state, _, accountId) => state.getIn(['accounts', accountId]),62  ], (base, account) => {63    return base.set('account', account);64  });65};66export const getAccountGallery = createSelector([67  (state, id) => state.getIn(['timelines', `account:${id}:media`, 'items'], ImmutableList()),68  state       => state.get('statuses'),69], (statusIds, statuses) => {70  let medias = ImmutableList();71  statusIds.forEach(statusId => {72    const status = statuses.get(statusId);73    medias = medias.concat(status.get('media_attachments').map(media => media.set('status', status)));74  });75  return medias;...

Full Screen

Full Screen

view.multiview.test.js

Source:view.multiview.test.js Github

copy

Full Screen

...22    model: dataset,23    el: $el24  });25  var state = explorer.state;26  ok(state.get('query'));27  equal(state.get('readOnly'), false);28  equal(state.get('currentView'), null);29  equal(state.get('query').size, 100);30  deepEqual(state.get('view-graph').group, null);31  equal(state.get('backend'), 'memory');32  ok(state.get('url') === url);33  $el.remove();34});35test('initialize state', function () {36  var $el = $('<div class="test-view-explorer-init-state" />');37  $('.fixtures .data-explorer-here').append($el);38  var dataset = Fixture.getDataset();39  var explorer = new recline.View.MultiView({40    model: dataset,41    el: $el,42    state: {43      readOnly: true,44      currentView: 'graph',45      'view-grid': {46        hiddenFields: ['x']47      },48      'view-map': {49        latField: 'lat1',50        lonField: 'lon1'51      }52    }53  });54  ok(explorer.state.get('readOnly'));55  ok(explorer.state.get('currentView'), 'graph');56  // check the correct view is visible57  var css = explorer.el.find('.navigation a[data-view="graph"]').attr('class').split(' ');58  ok(_.contains(css, 'active'), css);59  var css = explorer.el.find('.navigation a[data-view="grid"]').attr('class').split(' ');60  ok(!(_.contains(css, 'active')), css);61  // check pass through of view config62  deepEqual(explorer.state.get('view-grid')['hiddenFields'], ['x']);63  equal(explorer.state.get('view-map')['lonField'], 'lon1');64  $el.remove();65});66test('restore (from serialized state)', function() {67  var dataset = Fixture.getDataset();68  var explorer = new recline.View.MultiView({69    model: dataset,70  });71  var state = explorer.state.toJSON();72  var explorerNew = recline.View.MultiView.restore(state);73  var out = explorerNew.state.toJSON();74  equal(out.backend, state.backend);75});...

Full Screen

Full Screen

reducer.js

Source:reducer.js Github

copy

Full Screen

...23  switch (action.type) {24    case DELETE_CONTENT_TYPE:25      return state26        .updateIn(['menu', '0', 'items'], (list) => list.splice(findIndex(state.getIn(['menu', '0', 'items']).toJS(), ['name', action.itemToDelete]), 1))27        .update('models', (array) => array.splice(findIndex(state.get('models').toJS(), ['name', action.itemToDelete]), 1));28    case MODELS_FETCH:29      return state.set('loading', true);30    case MODELS_FETCH_SUCCEEDED:31      return state32        .set('loading', false)33        .set('menu', List(action.menu.sections))34        .set('models', List(action.data.models));35    case STORE_TEMPORARY_MENU: {36      const modelsSize = size(state.get('models').toJS());37      return state38        .updateIn(['menu', '0', 'items'], (list) => list.splice(action.position, action.nbElementToRemove, action.newLink))39        .update('models', array => array.splice(action.nbElementToRemove === 0 ? modelsSize : modelsSize - 1 , 1, action.newModel));40    }41    case TEMPORARY_CONTENT_TYPE_FIELDS_UPDATED: {42      const newModel = state.getIn(['models', size(state.get('models').toJS()) - 1]);43      newModel.fields = action.fieldNumber;44      return state45        .updateIn(['models', size(state.get('models').toJS()) - 1], () => newModel);46    }47    case TEMPORARY_CONTENT_TYPE_POSTED: {48      const newModel = state.getIn(['models', size(state.get('models').toJS()) - 1]);49      newModel.isTemporary = false;50      newModel.fields = action.fieldNumber;51      const oldMenuItem = state.getIn(['menu', '0', 'items', size(state.getIn(['menu', '0', 'items']).toJS()) -2]);52      oldMenuItem.isTemporary = false;53      const newData = oldMenuItem;54      return state55        .updateIn(['menu', '0', 'items', size(state.getIn(['menu', '0', 'items']).toJS()) -2], () => newData)56        .updateIn(['models', size(state.get('models').toJS()) - 1], () => newModel);57    }58    default:59      return state;60  }61}...

Full Screen

Full Screen

compose_form_container.js

Source:compose_form_container.js Github

copy

Full Screen

1import { connect } from 'react-redux';2import ComposeForm from '../components/compose_form';3import { uploadCompose } from '../../../actions/compose';4import {5  changeCompose,6  submitCompose,7  clearComposeSuggestions,8  fetchComposeSuggestions,9  selectComposeSuggestion,10  changeComposeSpoilerText,11  insertEmojiCompose,12} from '../../../actions/compose';13const mapStateToProps = state => ({14  text: state.getIn(['compose', 'text']),15  suggestion_token: state.getIn(['compose', 'suggestion_token']),16  suggestions: state.getIn(['compose', 'suggestions']),17  spoiler: state.getIn(['compose', 'spoiler']),18  spoiler_text: state.getIn(['compose', 'spoiler_text']),19  privacy: state.getIn(['compose', 'privacy']),20  focusDate: state.getIn(['compose', 'focusDate']),21  caretPosition: state.getIn(['compose', 'caretPosition']),22  preselectDate: state.getIn(['compose', 'preselectDate']),23  is_submitting: state.getIn(['compose', 'is_submitting']),24  is_uploading: state.getIn(['compose', 'is_uploading']),25  showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']),26  anyMedia: state.getIn(['compose', 'media_attachments']).size > 0,27});28const mapDispatchToProps = (dispatch) => ({29  onChange (text) {30    dispatch(changeCompose(text));31  },32  onSubmit () {33    dispatch(submitCompose());34  },35  onClearSuggestions () {36    dispatch(clearComposeSuggestions());37  },38  onFetchSuggestions (token) {39    dispatch(fetchComposeSuggestions(token));40  },41  onSuggestionSelected (position, token, accountId) {42    dispatch(selectComposeSuggestion(position, token, accountId));43  },44  onChangeSpoilerText (checked) {45    dispatch(changeComposeSpoilerText(checked));46  },47  onPaste (files) {48    dispatch(uploadCompose(files));49  },50  onPickEmoji (position, data, needsSpace) {51    dispatch(insertEmojiCompose(position, data, needsSpace));52  },53});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', () => {2  it('test', () => {3    cy.get('#lst-ib').type('cypress')4    cy.get('.jsb > center > .lsb').click()5    cy.get('.r > a').first().click()6    cy.get('.page-title > h1').should('have.text', 'Cypress.io')7    cy.get('#menu-item-100 > a').click()8    cy.get('.page-title > h1').should('have.text', 'Documentation')9    cy.get('#menu-item-103 > a').click()10    cy.get('.page-title > h1').should('have.text', 'Introduction')11    cy.get('#menu-item-104 > a').click()12    cy.get('.page-title > h1').should('have.text', 'Installation')13    cy.get('#menu-item-105 > a').click()14    cy.get('.page-title > h1').should('have.text', 'Writing Your First Test')15    cy.get('#menu-item-106 > a').click()16    cy.get('.page-title > h1').should('have.text', 'Test Runner')17    cy.get('#menu-item-107 > a').click()18    cy.get('.page-title > h1').should('have.text', 'Dashboard Service')19    cy.get('#menu-item-108 > a').click()20    cy.get('.page-title > h1').should('have.text', 'Continuous Integration')21    cy.get('#menu-item-109 > a').click()22    cy.get('.page-title > h1').should('have.text', 'Recipes')23    cy.get('#menu-item-110 > a').click()24    cy.get('.page-title > h1').should('have.text', 'FAQ')25    cy.get('#menu-item-111 > a').click()26    cy.get('.page-title > h1').should('have.text', 'Plugins')27    cy.get('#menu-item-112 > a').click()28    cy.get('.page-title > h1').should('have.text', 'Support')29    cy.get('#menu-item-113 > a').click()30    cy.get('.page-title > h1').should('have.text', 'About')31    cy.get('#menu-item-114 > a').click()32    cy.get('.page-title > h1').should('have.text', 'Blog')33    cy.get('#menu

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.state('window').localStorage.getItem('token')2.then((token) => {3cy.state('window').localStorage.setItem('token', token)4})5})6cy.state('window').localStorage.getItem('token')7.then((token) => {8cy.state('window').localStorage.setItem('token', token)9})

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('input').then((input) => {2  const state = input[0].state()3  cy.log(state.value)4})5cy.get('input').then((input) => {6  const state = input[0].state()7  cy.log(state.value)8})9cy.get('input').then((input) => {10  const state = input[0].state()11  cy.log(state.value)12})13cy.get('input').then((input) => {14  const state = input[0].state()15  cy.log(state.value)16})17cy.get('input').then((input) => {18  const state = input[0].state()19  cy.log(state.value)20})21cy.get('input').then((input) => {22  const state = input[0].state()23  cy.log(state.value)24})25cy.get('input').then((input) => {26  const state = input[0].state()27  cy.log(state.value)28})29The state() method is used to get the current state of the component. The state() method returns an object that contains the current state

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('#name')2  .invoke('attr', 'data-test')3  .then((name) => {4    cy.log(name)5  })6cy.get('#name')7  .invoke('attr', 'data-test')8  .then((name) => {9    cy.log(nameValue)10  })11cy.get('#name')12  .invoke('attr', 'data-test')13  .then(({ name }) => {14    cy.log(nameValue)15  })16cy.get('#name')17  .invoke('attr', 'data-test')18  .then(({ name }) => (nameValue = name))19cy.log(nameValue)

Full Screen

Using AI Code Generation

copy

Full Screen

1const state = cy.state()2const value = state('prop')3cy.state('prop', 'value')4cy.state('clear')5cy.state('reset')6const runnable = cy.state('runnable')7cy.state('runnable', runnable)8const win = cy.state('window')9cy.state('window', win)10const doc = cy.state('document')11cy.state('document', doc)12const width = cy.state('viewportWidth')13cy.state('viewportWidth', 1000)14const height = cy.state('viewportHeight')15cy.state('viewportHeight', 500)16const orientation = cy.state('viewportOrientation')17cy.state('viewportOrientation', 'portrait')18const viewport = cy.state('viewport')19cy.state('viewport

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('@state').then(state => {2        expect(res.body).to.have.property('id').to.equal(state.id)3    })4})5cy.get('@state').then(state => {6        expect(res.body).to.have.property('id').to.equal(state.id)7    })8})9cy.get('@state').then(state => {10        expect(res.body).to.have.property('id').to.equal(state.id)11    })12})13cy.get('@state').then(state => {14        expect(res.body).to.have.property('id').to.equal(state.id)15    })16})17cy.get('@state').then(state => {18        expect(res.body).to.have.property('id').to.equal(state.id)19    })20})21cy.get('@state').then(state => {22        expect(res.body).to.have.property('id').to.equal(state.id)23    })24})25cy.get('@state').then(state => {26        expect(res.body).to.have.property('id').to.equal(state.id)27    })28})29cy.get('@state').then(state => {30        expect(res.body).to.have.property('id').to.equal(state.id)31    })32})33cy.get('@

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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