Best JavaScript code snippet using mochawesome
type.js
Source:type.js
1describe( 'bundle:type' , function () {2 it( 'is.sameType' , function () {3 expect( is.sameType( null , null ) ).toBeTruthy()4 expect( is.sameType( null , void 0 ) ).not.toBeTruthy()5 expect( is.sameType( null , 0 ) ).not.toBeTruthy()6 expect( is.sameType( null , new Number() ) ).not.toBeTruthy()7 expect( is.sameType( null , '' ) ).not.toBeTruthy()8 expect( is.sameType( null , new String() ) ).not.toBeTruthy()9 expect( is.sameType( null , true ) ).not.toBeTruthy()10 expect( is.sameType( null , new Boolean() ) ).not.toBeTruthy()11 expect( is.sameType( null , {} ) ).not.toBeTruthy()12 expect( is.sameType( null , [] ) ).not.toBeTruthy()13 expect( is.sameType( null , function () {} ) ).not.toBeTruthy()14 expect( is.sameType( null , new Date() ) ).not.toBeTruthy()15 expect( is.sameType( null , new Error() ) ).not.toBeTruthy()16 expect( is.sameType( null , /^/ ) ).not.toBeTruthy()17 expect( is.sameType( void 0 , null ) ).not.toBeTruthy()18 expect( is.sameType( void 0 , void 0 ) ).toBeTruthy()19 expect( is.sameType( void 0 , 0 ) ).not.toBeTruthy()20 expect( is.sameType( void 0 , new Number() ) ).not.toBeTruthy()21 expect( is.sameType( void 0 , '' ) ).not.toBeTruthy()22 expect( is.sameType( void 0 , new String() ) ).not.toBeTruthy()23 expect( is.sameType( void 0 , true ) ).not.toBeTruthy()24 expect( is.sameType( void 0 , new Boolean() ) ).not.toBeTruthy()25 expect( is.sameType( void 0 , {} ) ).not.toBeTruthy()26 expect( is.sameType( void 0 , [] ) ).not.toBeTruthy()27 expect( is.sameType( void 0 , function () {} ) ).not.toBeTruthy()28 expect( is.sameType( void 0 , new Date() ) ).not.toBeTruthy()29 expect( is.sameType( void 0 , new Error() ) ).not.toBeTruthy()30 expect( is.sameType( void 0 , /^/ ) ).not.toBeTruthy()31 expect( is.sameType( 0 , null ) ).not.toBeTruthy()32 expect( is.sameType( 0 , void 0 ) ).not.toBeTruthy()33 expect( is.sameType( 0 , 0 ) ).toBeTruthy()34 expect( is.sameType( 0 , new Number() ) ).not.toBeTruthy()35 expect( is.sameType( 0 , '' ) ).not.toBeTruthy()36 expect( is.sameType( 0 , new String() ) ).not.toBeTruthy()37 expect( is.sameType( 0 , true ) ).not.toBeTruthy()38 expect( is.sameType( 0 , new Boolean() ) ).not.toBeTruthy()39 expect( is.sameType( 0 , {} ) ).not.toBeTruthy()40 expect( is.sameType( 0 , [] ) ).not.toBeTruthy()41 expect( is.sameType( 0 , function () {} ) ).not.toBeTruthy()42 expect( is.sameType( 0 , new Date() ) ).not.toBeTruthy()43 expect( is.sameType( 0 , new Error() ) ).not.toBeTruthy()44 expect( is.sameType( 0 , /^/ ) ).not.toBeTruthy()45 expect( is.sameType( new Number() , null ) ).not.toBeTruthy()46 expect( is.sameType( new Number() , void 0 ) ).not.toBeTruthy()47 expect( is.sameType( new Number() , 0 ) ).not.toBeTruthy()48 expect( is.sameType( new Number() , new Number() ) ).toBeTruthy()49 expect( is.sameType( new Number() , '' ) ).not.toBeTruthy()50 expect( is.sameType( new Number() , new String() ) ).not.toBeTruthy()51 expect( is.sameType( new Number() , true ) ).not.toBeTruthy()52 expect( is.sameType( new Number() , new Boolean() ) ).not.toBeTruthy()53 expect( is.sameType( new Number() , {} ) ).not.toBeTruthy()54 expect( is.sameType( new Number() , [] ) ).not.toBeTruthy()55 expect( is.sameType( new Number() , function () {} ) ).not.toBeTruthy()56 expect( is.sameType( new Number() , new Date() ) ).not.toBeTruthy()57 expect( is.sameType( new Number() , new Error() ) ).not.toBeTruthy()58 expect( is.sameType( new Number() , /^/ ) ).not.toBeTruthy()59 expect( is.sameType( '' , null ) ).not.toBeTruthy()60 expect( is.sameType( '' , void 0 ) ).not.toBeTruthy()61 expect( is.sameType( '' , 0 ) ).not.toBeTruthy()62 expect( is.sameType( '' , new Number() ) ).not.toBeTruthy()63 expect( is.sameType( '' , '' ) ).toBeTruthy()64 expect( is.sameType( '' , new String() ) ).not.toBeTruthy()65 expect( is.sameType( '' , true ) ).not.toBeTruthy()66 expect( is.sameType( '' , new Boolean() ) ).not.toBeTruthy()67 expect( is.sameType( '' , {} ) ).not.toBeTruthy()68 expect( is.sameType( '' , [] ) ).not.toBeTruthy()69 expect( is.sameType( '' , function () {} ) ).not.toBeTruthy()70 expect( is.sameType( '' , new Date() ) ).not.toBeTruthy()71 expect( is.sameType( '' , new Error() ) ).not.toBeTruthy()72 expect( is.sameType( '' , /^/ ) ).not.toBeTruthy()73 expect( is.sameType( new String() , null ) ).not.toBeTruthy()74 expect( is.sameType( new String() , void 0 ) ).not.toBeTruthy()75 expect( is.sameType( new String() , 0 ) ).not.toBeTruthy()76 expect( is.sameType( new String() , new Number() ) ).not.toBeTruthy()77 expect( is.sameType( new String() , '' ) ).not.toBeTruthy()78 expect( is.sameType( new String() , new String() ) ).toBeTruthy()79 expect( is.sameType( new String() , true ) ).not.toBeTruthy()80 expect( is.sameType( new String() , new Boolean() ) ).not.toBeTruthy()81 expect( is.sameType( new String() , {} ) ).not.toBeTruthy()82 expect( is.sameType( new String() , [] ) ).not.toBeTruthy()83 expect( is.sameType( new String() , function () {} ) ).not.toBeTruthy()84 expect( is.sameType( new String() , new Date() ) ).not.toBeTruthy()85 expect( is.sameType( new String() , new Error() ) ).not.toBeTruthy()86 expect( is.sameType( new String() , /^/ ) ).not.toBeTruthy()87 expect( is.sameType( true , null ) ).not.toBeTruthy()88 expect( is.sameType( true , void 0 ) ).not.toBeTruthy()89 expect( is.sameType( true , 0 ) ).not.toBeTruthy()90 expect( is.sameType( true , new Number() ) ).not.toBeTruthy()91 expect( is.sameType( true , '' ) ).not.toBeTruthy()92 expect( is.sameType( true , new String() ) ).not.toBeTruthy()93 expect( is.sameType( true , true ) ).toBeTruthy()94 expect( is.sameType( true , new Boolean() ) ).not.toBeTruthy()95 expect( is.sameType( true , {} ) ).not.toBeTruthy()96 expect( is.sameType( true , [] ) ).not.toBeTruthy()97 expect( is.sameType( true , function () {} ) ).not.toBeTruthy()98 expect( is.sameType( true , new Date() ) ).not.toBeTruthy()99 expect( is.sameType( true , new Error() ) ).not.toBeTruthy()100 expect( is.sameType( true , /^/ ) ).not.toBeTruthy()101 expect( is.sameType( new Boolean() , null ) ).not.toBeTruthy()102 expect( is.sameType( new Boolean() , void 0 ) ).not.toBeTruthy()103 expect( is.sameType( new Boolean() , 0 ) ).not.toBeTruthy()104 expect( is.sameType( new Boolean() , new Number() ) ).not.toBeTruthy()105 expect( is.sameType( new Boolean() , '' ) ).not.toBeTruthy()106 expect( is.sameType( new Boolean() , new String() ) ).not.toBeTruthy()107 expect( is.sameType( new Boolean() , true ) ).not.toBeTruthy()108 expect( is.sameType( new Boolean() , new Boolean() ) ).toBeTruthy()109 expect( is.sameType( new Boolean() , {} ) ).not.toBeTruthy()110 expect( is.sameType( new Boolean() , [] ) ).not.toBeTruthy()111 expect( is.sameType( new Boolean() , function () {} ) ).not.toBeTruthy()112 expect( is.sameType( new Boolean() , new Date() ) ).not.toBeTruthy()113 expect( is.sameType( new Boolean() , new Error() ) ).not.toBeTruthy()114 expect( is.sameType( new Boolean() , /^/ ) ).not.toBeTruthy()115 expect( is.sameType( {} , null ) ).not.toBeTruthy()116 expect( is.sameType( {} , void 0 ) ).not.toBeTruthy()117 expect( is.sameType( {} , 0 ) ).not.toBeTruthy()118 expect( is.sameType( {} , new Number() ) ).not.toBeTruthy()119 expect( is.sameType( {} , '' ) ).not.toBeTruthy()120 expect( is.sameType( {} , new String() ) ).not.toBeTruthy()121 expect( is.sameType( {} , true ) ).not.toBeTruthy()122 expect( is.sameType( {} , new Boolean() ) ).not.toBeTruthy()123 expect( is.sameType( {} , {} ) ).toBeTruthy()124 expect( is.sameType( {} , [] ) ).not.toBeTruthy()125 expect( is.sameType( {} , function () {} ) ).not.toBeTruthy()126 expect( is.sameType( {} , new Date() ) ).not.toBeTruthy()127 expect( is.sameType( {} , new Error() ) ).not.toBeTruthy()128 expect( is.sameType( {} , /^/ ) ).not.toBeTruthy()129 expect( is.sameType( [] , null ) ).not.toBeTruthy()130 expect( is.sameType( [] , void 0 ) ).not.toBeTruthy()131 expect( is.sameType( [] , 0 ) ).not.toBeTruthy()132 expect( is.sameType( [] , new Number() ) ).not.toBeTruthy()133 expect( is.sameType( [] , '' ) ).not.toBeTruthy()134 expect( is.sameType( [] , new String() ) ).not.toBeTruthy()135 expect( is.sameType( [] , true ) ).not.toBeTruthy()136 expect( is.sameType( [] , new Boolean() ) ).not.toBeTruthy()137 expect( is.sameType( [] , {} ) ).not.toBeTruthy()138 expect( is.sameType( [] , [] ) ).toBeTruthy()139 expect( is.sameType( [] , function () {} ) ).not.toBeTruthy()140 expect( is.sameType( [] , new Date() ) ).not.toBeTruthy()141 expect( is.sameType( [] , new Error() ) ).not.toBeTruthy()142 expect( is.sameType( [] , /^/ ) ).not.toBeTruthy()143 expect( is.sameType( function () {} , null ) ).not.toBeTruthy()144 expect( is.sameType( function () {} , void 0 ) ).not.toBeTruthy()145 expect( is.sameType( function () {} , 0 ) ).not.toBeTruthy()146 expect( is.sameType( function () {} , new Number() ) ).not.toBeTruthy()147 expect( is.sameType( function () {} , '' ) ).not.toBeTruthy()148 expect( is.sameType( function () {} , new String() ) ).not.toBeTruthy()149 expect( is.sameType( function () {} , true ) ).not.toBeTruthy()150 expect( is.sameType( function () {} , new Boolean() ) ).not.toBeTruthy()151 expect( is.sameType( function () {} , {} ) ).not.toBeTruthy()152 expect( is.sameType( function () {} , [] ) ).not.toBeTruthy()153 expect( is.sameType( function () {} , function () {} ) ).toBeTruthy()154 expect( is.sameType( function () {} , new Date() ) ).not.toBeTruthy()155 expect( is.sameType( function () {} , new Error() ) ).not.toBeTruthy()156 expect( is.sameType( function () {} , /^/ ) ).not.toBeTruthy()157 expect( is.sameType( new Date() , null ) ).not.toBeTruthy()158 expect( is.sameType( new Date() , void 0 ) ).not.toBeTruthy()159 expect( is.sameType( new Date() , 0 ) ).not.toBeTruthy()160 expect( is.sameType( new Date() , new Number() ) ).not.toBeTruthy()161 expect( is.sameType( new Date() , '' ) ).not.toBeTruthy()162 expect( is.sameType( new Date() , new String() ) ).not.toBeTruthy()163 expect( is.sameType( new Date() , true ) ).not.toBeTruthy()164 expect( is.sameType( new Date() , new Boolean() ) ).not.toBeTruthy()165 expect( is.sameType( new Date() , {} ) ).not.toBeTruthy()166 expect( is.sameType( new Date() , [] ) ).not.toBeTruthy()167 expect( is.sameType( new Date() , function () {} ) ).not.toBeTruthy()168 expect( is.sameType( new Date() , new Date() ) ).toBeTruthy()169 expect( is.sameType( new Date() , new Error() ) ).not.toBeTruthy()170 expect( is.sameType( new Date() , /^/ ) ).not.toBeTruthy()171 expect( is.sameType( new Error() , null ) ).not.toBeTruthy()172 expect( is.sameType( new Error() , void 0 ) ).not.toBeTruthy()173 expect( is.sameType( new Error() , 0 ) ).not.toBeTruthy()174 expect( is.sameType( new Error() , new Number() ) ).not.toBeTruthy()175 expect( is.sameType( new Error() , '' ) ).not.toBeTruthy()176 expect( is.sameType( new Error() , new String() ) ).not.toBeTruthy()177 expect( is.sameType( new Error() , true ) ).not.toBeTruthy()178 expect( is.sameType( new Error() , new Boolean() ) ).not.toBeTruthy()179 expect( is.sameType( new Error() , {} ) ).not.toBeTruthy()180 expect( is.sameType( new Error() , [] ) ).not.toBeTruthy()181 expect( is.sameType( new Error() , function () {} ) ).not.toBeTruthy()182 expect( is.sameType( new Error() , new Date() ) ).not.toBeTruthy()183 expect( is.sameType( new Error() , new Error() ) ).toBeTruthy()184 expect( is.sameType( new Error() , /^/ ) ).not.toBeTruthy()185 expect( is.sameType( /^/ , null ) ).not.toBeTruthy()186 expect( is.sameType( /^/ , void 0 ) ).not.toBeTruthy()187 expect( is.sameType( /^/ , 0 ) ).not.toBeTruthy()188 expect( is.sameType( /^/ , new Number() ) ).not.toBeTruthy()189 expect( is.sameType( /^/ , '' ) ).not.toBeTruthy()190 expect( is.sameType( /^/ , new String() ) ).not.toBeTruthy()191 expect( is.sameType( /^/ , true ) ).not.toBeTruthy()192 expect( is.sameType( /^/ , new Boolean() ) ).not.toBeTruthy()193 expect( is.sameType( /^/ , {} ) ).not.toBeTruthy()194 expect( is.sameType( /^/ , [] ) ).not.toBeTruthy()195 expect( is.sameType( /^/ , function () {} ) ).not.toBeTruthy()196 expect( is.sameType( /^/ , new Date() ) ).not.toBeTruthy()197 expect( is.sameType( /^/ , new Error() ) ).not.toBeTruthy()198 expect( is.sameType( /^/ , /^/ ) ).toBeTruthy()199 } )200 it( 'is.primitive' , function () {201 expect( is.primitive( null ) ).toBeTruthy()202 expect( is.primitive( void 0 ) ).toBeTruthy()203 expect( is.primitive( 0 ) ).toBeTruthy()204 expect( is.primitive( new Number( 0 ) ) ).not.toBeTruthy()205 expect( is.primitive( '' ) ).toBeTruthy()206 expect( is.primitive( new String( '' ) ) ).not.toBeTruthy()207 expect( is.primitive( true ) ).toBeTruthy()208 expect( is.primitive( false ) ).toBeTruthy()209 expect( is.primitive( new Boolean( true ) ) ).not.toBeTruthy()210 expect( is.primitive( new Boolean( false ) ) ).not.toBeTruthy()211 expect( is.primitive( {} ) ).not.toBeTruthy()212 expect( is.primitive( [] ) ).not.toBeTruthy()...
prog.js
Source:prog.js
1var PriorityQueue = require('priorityqueuejs');2const readline = require('readline-sync');3function init(n) {4 var problem = {}; 5 // People[0][i] is married to People[1][i], the value of it is either 0 or 1, representing which side they are on6 problem.People = [];7 problem.People.push(new Array(n).fill(0));8 problem.People.push(new Array(n).fill(0));9 problem.BoatSide = false;10 return problem;11}12function checkFinal(state) {13 for(var husband of state.People[0]) {14 if(husband != 1)15 return false;16 }17 for(var wife of state.People[1]) {18 if(wife != 1)19 return false;20 }21 if(!state.BoatSide) 22 return false;23 return true;24}25// Checks if the transition is possible26function cloneState(state) {27 var newState = init(state.People[0].length);28 newState.BoatSide = state.BoatSide;29 for(var personType in newState.People) {30 for(var i = 0; i < newState.People[personType].length; i++) {31 newState.People[personType][i] = state.People[personType][i];32 }33 }34 return newState;35}36function transitionPossible(state, action) {37 if(action.length < 1 || action.length > 2)38 return false;39 // people on the same side as boat40 for(var person of action) {41 if(state.People[person[0]][person[1]] != state.BoatSide)42 return false;43 }44 45 // peform the action46 var newState = cloneState(state);47 for(var person in action) {48 newState.People[person[0]][person[1]] = state.BoatSide ? 0 : 1;49 }50 newState.BoatSide = state.BoatSide ? 0 : 1;51 //check if the rule is followed52 for(var i = 0; i < newState.People[0].length; i++) {53 // are on different shores54 if(newState.People[0][i] != newState.People[1][i]) {55 // if there's any man on the same side as the woman56 for(var manSide of newState.People[0]) {57 if(manSide == newState.People[1][i])58 return false;59 }60 }61 }62 return true;63}64function Transition(state, action) {65 for(var person of action) {66 state.People[person[0]][person[1]] = state.BoatSide ? 0 : 1;67 }68 state.BoatSide = state.BoatSide ? 0 : 1;69}70var visitedStates = [];71function checkStateVisited(state) {72 for(var visitedState of visitedStates) {73 var areEqual = true;74 if(visitedState.BoatSide != state.BoatSide)75 continue;76 for(var personType in state.People) {77 for(var i = 0; i < state.People[personType].length; i++) {78 if(state.People[personType][i] != visitedState.People[personType][i]) {79 areEqual = false;80 break;81 }82 }83 if(!areEqual)84 break;85 }86 if(areEqual) {87 return true;88 }89 }90 return false;91}92var finalTransitionList = []93function bkt(state) {94 if(checkStateVisited(state)) {95 return false;96 }else {97 visitedStates.push(cloneState(state));98 }99 if(checkFinal(state)) {100 return true;101 }102 for(var i in state.People[0]) {103 for(var j in state.People[1]) {104 for(var nrOfPassengers = 1; nrOfPassengers <= 2; nrOfPassengers++) {105 for(var type = 0; type <= 1; type++) {106 for(var sameType = 0; sameType <= 1; sameType++) {107 var newAction = [];108 newAction.push([type, i]);109 if(nrOfPassengers > 1) {110 if(sameType == 0)111 newAction.push([type ? 0 : 1, j]);112 else113 newAction.push([type, j]);114 }115 if(transitionPossible(state, newAction)) {116 Transition(state, newAction);117 if(bkt(cloneState(state))) {118 finalTransitionList.push(state);119 return true;120 }121 Transition(state, newAction);122 }123 }124 }125 }126 }127 }128 129 return false;130}131function bfs(initialState) {132 var queue = [initialState];133 while(queue.length) {134 135 state = queue.shift();136 if(checkFinal(state)) {137 while(state != null) {138 console.log(state);139 state = state.ParentState;140 }141 return true;142 }143 if(checkStateVisited(state)) {144 continue;145 }else {146 visitedStates.push(cloneState(state));147 }148 for(var i in state.People[0]) {149 for(var j in state.People[1]) {150 for(var nrOfPassengers = 1; nrOfPassengers <= 2; nrOfPassengers++) {151 for(var type = 0; type <= 1; type++) {152 for(var sameType = 0; sameType <= 1; sameType++) {153 var newAction = [];154 newAction.push([type, i]);155 if(nrOfPassengers > 1) {156 if(sameType == 0)157 newAction.push([type ? 0 : 1, j]);158 else159 newAction.push([type, j]);160 }161 if(transitionPossible(state, newAction)) {162 var clonedState = cloneState(state);163 Transition(clonedState, newAction);164 clonedState.ParentState = state;165 queue.push(clonedState);166 }167 }168 }169 }170 }171 }172 }173 174 return false;175}176function hillHeuristic(state) {177 var result = 0;178 for(var personType in state.People) {179 for(var side of state.People[personType]) {180 result += side; 181 }182 }183 return result;184}185function hillClimbing(initialState) {186 var queue = new PriorityQueue((a, b) => {187 return hillHeuristic(a) - hillHeuristic(b);188 });189 queue.enq(initialState);190 while(queue.size()) {191 192 state = queue.deq();193 if(checkFinal(state)) {194 while(state != null) {195 console.log(state);196 state = state.ParentState;197 }198 return true;199 }200 if(checkStateVisited(state)) {201 continue;202 }else {203 visitedStates.push(cloneState(state));204 }205 for(var i in state.People[0]) {206 for(var j in state.People[1]) {207 for(var nrOfPassengers = 1; nrOfPassengers <= 2; nrOfPassengers++) {208 for(var type = 0; type <= 1; type++) {209 for(var sameType = 0; sameType <= 1; sameType++) {210 var newAction = [];211 newAction.push([type, i]);212 if(nrOfPassengers > 1) {213 if(sameType == 0)214 newAction.push([type ? 0 : 1, j]);215 else216 newAction.push([type, j]);217 }218 if(transitionPossible(state, newAction)) {219 var clonedState = cloneState(state);220 Transition(clonedState, newAction);221 clonedState.ParentState = state;222 if(hillHeuristic(clonedState) > hillHeuristic(state))223 queue.enq(clonedState);224 }225 }226 }227 }228 }229 }230 }231 232 while(state != null) {233 console.log(state);234 state = state.ParentState;235 }236 return false;237}238function starHeuristic(state) {239 var result = state.StepNumber;240 for(var personType in state.People) {241 for(var side of state.People[personType]) {242 result += side; 243 }244 }245 return result;246}247function aStar(initialState) {248 var queue = new PriorityQueue((a, b) => {249 return starHeuristic(a) - starHeuristic(b);250 });251 initialState.StepNumber = 0;252 queue.enq(initialState);253 while(queue.size()) {254 255 state = queue.deq();256 if(checkFinal(state)) {257 while(state != null) {258 console.log(state);259 state = state.ParentState;260 }261 return true;262 }263 if(checkStateVisited(state)) {264 continue;265 }else {266 visitedStates.push(cloneState(state));267 }268 for(var i in state.People[0]) {269 for(var j in state.People[1]) {270 for(var nrOfPassengers = 1; nrOfPassengers <= 2; nrOfPassengers++) {271 for(var type = 0; type <= 1; type++) {272 for(var sameType = 0; sameType <= 1; sameType++) {273 var newAction = [];274 newAction.push([type, i]);275 if(nrOfPassengers > 1) {276 if(sameType == 0)277 newAction.push([type ? 0 : 1, j]);278 else279 newAction.push([type, j]);280 }281 if(transitionPossible(state, newAction)) {282 var clonedState = cloneState(state);283 Transition(clonedState, newAction);284 clonedState.ParentState = state;285 clonedState.StepNumber = state.StepNumber + 1;286 queue.enq(clonedState);287 }288 }289 }290 }291 }292 }293 }294 295 while(state != null) {296 console.log(state);297 state = state.ParentState;298 }299 return false;300}301var endApplication = false;302while(!endApplication) {303 var state = init(3);304 console.log('Available algorithms:');305 console.log('bkt - Backtracking');306 console.log('bfs - Breadth First Search');307 console.log('hill - Hill Climbing');308 console.log('A* - A*');309 let command = readline.question('What algorithm should we use? Write exit in order to exit \n');310 finalTransitionList = [];311 visitedStates = [];312 313 switch(command) {314 case 'exit': 315 endApplication = true;316 break;317 case 'bkt': 318 console.log("there exists a solution: " + bkt(state));319 console.log(JSON.stringify(finalTransitionList, 2, 4));320 break;321 case 'bfs': 322 console.log("there exists a solution: " + bfs(state));323 break;324 case 'hill': 325 console.log("there exists a solution: " + hillClimbing(state));326 break;327 case 'A*': 328 console.log("there exists a solution: " + aStar(state));329 break;330 default:331 console.log('invalid command');332 break;333 }...
Convert.js
Source:Convert.js
...42 var key1 = schema.fieldsNames[i1];43 var newT = __map_reserved[key1] != null ? ourMap.getReserved(key1) : ourMap.h[key1];44 var c = new (hxbit_ConvertField().default)(oldT,newT);45 if(newT != null) {46 if(Convert.sameType(oldT,newT)) {47 c.same = true;48 } else {49 c.defaultValue = Convert.getDefault(newT);50 }51 }52 c.index = this.read.length;53 this.read.push(c);54 var key2 = schema.fieldsNames[i1];55 if(__map_reserved[key2] != null) {56 map.setReserved(key2,c);57 } else {58 map.h[key2] = c;59 }60 }61 this.write = [];62 var _g12 = 0;63 var _g3 = ourSchema.fieldsNames.length;64 while(_g12 < _g3) {65 var i2 = _g12++;66 var newT1 = ourSchema.fieldsTypes[i2];67 var key3 = ourSchema.fieldsNames[i2];68 var c1 = __map_reserved[key3] != null ? map.getReserved(key3) : map.h[key3];69 if(c1 == null) {70 c1 = new (hxbit_ConvertField().default)(null,newT1);71 c1.defaultValue = Convert.getDefault(newT1);72 }73 this.write.push(c1);74 }75 }76 toString() {77 var _g = [];78 var _g2 = 0;79 var _g1 = this.write.length;80 while(_g2 < _g1) {81 var i = _g2++;82 var w = this.write[i];83 _g.push(w.from == null ? "insert:" + (Std().default).string(w.defaultValue) : w.same ? i == w.index ? "s" : "@" + w.index : "@" + w.index + ":" + (Std().default).string(w.to));84 }85 return _g.toString();86 }87 static sameType(a,b) {88 switch(a[1]) {89 case 0:90 switch(b[1]) {91 case 10:92 var b1 = b[2];93 return Convert.sameType(a,b1);94 case 16:95 return true;96 default:97 return (Type().default).enumEq(a,b);98 }99 break;100 case 7:101 switch(b[1]) {102 case 7:103 var ak = a[2];104 var av = a[3];105 var bv = b[3];106 var bk = b[2];107 if(Convert.sameType(ak,bk)) {108 return Convert.sameType(av,bv);109 } else {110 return false;111 }112 break;113 case 10:114 var b2 = b[2];115 return Convert.sameType(a,b2);116 default:117 return (Type().default).enumEq(a,b);118 }119 break;120 case 8:121 switch(b[1]) {122 case 8:123 var a1 = a[2];124 var b3 = b[2];125 return Convert.sameType(a1,b3);126 case 10:127 var b4 = b[2];128 return Convert.sameType(a,b4);129 default:130 return (Type().default).enumEq(a,b);131 }132 break;133 case 9:134 switch(b[1]) {135 case 9:136 var fa = a[2];137 var fb = b[2];138 if(fa.length != fb.length) {139 return false;140 }141 var _g1 = 0;142 var _g = fa.length;143 while(_g1 < _g) {144 var i = _g1++;145 var a2 = fa[i];146 var b5 = fb[i];147 if(a2.name != b5.name || a2.opt != b5.opt || !Convert.sameType(a2.type,b5.type)) {148 return false;149 }150 }151 return true;152 case 10:153 var b6 = b[2];154 return Convert.sameType(a,b6);155 default:156 return (Type().default).enumEq(a,b);157 }158 break;159 case 10:160 if(b[1] == 10) {161 var a3 = a[2];162 var b7 = b[2];163 return Convert.sameType(a3,b7);164 } else {165 var a4 = a[2];166 return Convert.sameType(a4,b);167 }168 break;169 case 11:170 switch(b[1]) {171 case 10:172 var b8 = b[2];173 return Convert.sameType(a,b8);174 case 11:175 var a5 = a[2];176 var b9 = b[2];177 return Convert.sameType(a5,b9);178 default:179 return (Type().default).enumEq(a,b);180 }181 break;182 case 12:183 switch(b[1]) {184 case 10:185 var b10 = b[2];186 return Convert.sameType(a,b10);187 case 12:188 var a6 = a[2];189 var b11 = b[2];190 return Convert.sameType(a6,b11);191 default:192 return (Type().default).enumEq(a,b);193 }194 break;195 case 16:196 switch(b[1]) {197 case 0:198 return true;199 case 10:200 var b12 = b[2];201 return Convert.sameType(a,b12);202 default:203 return (Type().default).enumEq(a,b);204 }205 break;206 default:207 if(b[1] == 10) {208 var b13 = b[2];209 return Convert.sameType(a,b13);210 } else {211 return (Type().default).enumEq(a,b);212 }213 }214 }215 static getDefault(t) {216 switch(t[1]) {217 case 1:218 return 0.;219 case 2:220 return false;221 case 7:222 var k = t[2];223 switch(k[1]) {...
life-like.js
Source:life-like.js
...41 var height = getCanvasHeightInPixel();42 var p;43 var sum = 0;44 if (wrap) {45 sameType(wrapPixel({x:x+1, y:y}, width,height), type) ? ++sum : sum;46 sameType(wrapPixel({x:x, y:y+1}, width,height), type) ? ++sum : sum;47 sameType(wrapPixel({x:x+1, y:y+1}, width,height), type) ? ++sum : sum;48 sameType(wrapPixel({x:x-1, y:y}, width,height), type) ? ++sum : sum;49 sameType(wrapPixel({x:x, y:y-1}, width,height), type) ? ++sum : sum;50 sameType(wrapPixel({x:x-1, y:y-1}, width,height), type) ? ++sum : sum;51 sameType(wrapPixel({x:x+1, y:y-1}, width,height), type) ? ++sum : sum;52 sameType(wrapPixel({x:x-1, y:y+1}, width,height), type) ? ++sum : sum;53 } else {54 p = {x:x+1, y:y};55 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;56 p = {x:x, y:y+1};57 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;58 p = {x:x+1, y:y+1};59 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;60 p = {x:x-1, y:y};61 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;62 p = {x:x, y:y-1};63 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;64 p = {x:x-1, y:y-1};65 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;66 p = {x:x-1, y:y+1};67 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum;68 p = {x:x+1, y:y-1};69 (validPixel(p, width, height) && sameType(p,type)) ? ++sum : sum; 70 }71 return sum;72}73function wrapPixel(pixel, width, height) {74 if (pixel.x >= width) {75 pixel.x = 0;76 } else if (pixel.x < 0) {77 pixel.x = width-1;78 }79 if (pixel.y >= height) {80 pixel.y = 0;81 } else if (pixel.y < 0) {82 pixel.y = height-1;83 }84 return pixel;85}86function validPixel(pixel, width, height) {87 return (pixel.x < width && pixel.x >= 0 && pixel.y < height && pixel.y >= 0);88}89function sameType(pixel, type) {90 return population[pixel.x][pixel.y] === type;91}92// https://en.wikipedia.org/wiki/Life-like_cellular_automaton#Notation_for_rules93// "237" returns [2,3,7]94function parseMirekString(str) {95 var tmp = [];96 for (var i = 0; i < str.length; i++) {97 tmp.push(parseInt(str.charAt(i)));98 }99 return tmp;100}101function colorCanvas() {102 clearCanvas();103 var x = getCanvasWidthInPixel();...
ap.spec.js
Source:ap.spec.js
1const test = require('tape')2const sinon = require('sinon')3const helpers = require('../test/helpers')4const bindFunc = helpers.bindFunc5const isFunction = require('../core/isFunction')6const unit = require('../core/_unit')7const constant = x => () => x8const identity = x => x9const mock = x => Object.assign({}, x, {10 map: unit, of: unit, chain: unit, type: constant('silly')11})12const ap = require('./ap')13test('ap pointfree', t => {14 const a = bindFunc(ap)15 const m = mock({ ap: identity })16 t.ok(isFunction(ap), 'is a function')17 const sameType = /ap: Both arguments must be Applys of the same type/18 t.throws(a(undefined, m), sameType, 'throws if first arg is undefined')19 t.throws(a(null, m), sameType, 'throws if first arg is null')20 t.throws(a(0, m), sameType, 'throws if first arg is a falsey number')21 t.throws(a(1, m), sameType, 'throws if first arg is a truthy number')22 t.throws(a('', m), sameType, 'throws if first arg is a falsey string')23 t.throws(a('string', m), sameType, 'throws if first arg is a truthy string')24 t.throws(a(false, m), sameType, 'throws if first arg is false')25 t.throws(a(true, m), sameType, 'throws if first arg is true')26 t.throws(a([], m), sameType, 'throws if first arg is an empty array')27 t.throws(a({}, m), sameType, 'throws if first arg is an object without an ap method')28 t.throws(a(m, undefined), sameType, 'throws if second arg is undefined')29 t.throws(a(m, null), sameType, 'throws if second arg is null')30 t.throws(a(m, 0), sameType, 'throws if second arg is a falsey number')31 t.throws(a(m, 1), sameType, 'throws if second arg is a truthy number')32 t.throws(a(m, ''), sameType, 'throws if second arg is a falsey string')33 t.throws(a(m, 'string'), sameType, 'throws if second arg is a truthy string')34 t.throws(a(m, false), sameType, 'throws if second arg is false')35 t.throws(a(m, true), sameType, 'throws if second arg is true')36 t.throws(a(m, []), sameType, 'throws if second arg is an array')37 t.throws(a(m, {}), sameType, 'throws if second arg is an object without an ap method')38 const noFuncs = /ap: Second Array must all be functions/39 t.throws(a([ 2 ], []), noFuncs, 'throws if second array is empty')40 t.throws(a([ 2 ], [ 2, 3 ]), noFuncs, 'throws if second array contains no functions')41 t.throws(a([ 2 ], [ identity, 3 ]), noFuncs, 'throws if second is not all functions')42 t.end()43})44test('ap applicative', t => {45 const m = mock({ ap: sinon.spy(identity) })46 const x = mock({ ap: sinon.spy(identity) })47 ap(m, x)48 t.ok(x.ap.calledWith(m), 'calls the ap method on the second arg passing in the first arg')49 t.end()50})51test('ap array', t => {52 const f = x => x + 253 const g = x => x + 154 const funcs = [ f, g ]55 const values = [ 1 , 2 ]56 const result = ap(values, funcs)57 t.same(result, [ 3, 4, 2, 3 ], 'applies functions to values as expected')58 t.end()...
test.dependent.js
Source:test.dependent.js
1new Test('Contract/Dependent/1', function() {2 function plus (x, y) {3 return (x+y);4 }5 function addOne(z) {6 return plus(z, 1);7 }8 function faultyAddOne(z) {9 return plus(z, "1");10 }11 this.expect(function() {12 const addOneSameType = Contract.assert(addOne, Contract.Dependent(Contract.Constructor(function(z) {13 return Contract.Base(function(value) {14 return (typeof value) === (typeof z);15 },"SameType");16 },"SameType")));17 addOneSameType(1);18 }).noBlame();19 this.expect(function() {20 const addOneSameType = Contract.assert(addOne, Contract.Dependent(Contract.Constructor(function(z) {21 return Contract.Base(function(value) {22 return (typeof value) === (typeof z);23 },"SameType");24 },"SameType")));25 addOneSameType("1");26 }).noBlame();27 this.expect(function() {28 const addOneSameType = Contract.assert(addOne, Contract.Dependent(Contract.Constructor(function(z) {29 return Contract.Base(function(value) {30 return (typeof value) === (typeof z);31 },"SameType");32 },"SameType")));33 addOneSameType(true);34 }).subjectBlame();35 this.expect(function() {36 const addOneSameType = Contract.assert(faultyAddOne, Contract.Dependent(Contract.Constructor(function(z) {37 return Contract.Base(function(value) {38 return (typeof value) === (typeof z);39 },"SameType");40 },"SameType")));41 addOneSameType(1);42 }).subjectBlame();...
sameType.spec.js
Source:sameType.spec.js
1const is = require('../../../dist/umd/ispro.js');2describe('type/sameType', () => {3 test('should return true if passed parameter types are same', () => {4 expect(is.sameType(1, 2)).toBe(true);5 expect(is.sameType('test', 'test')).toBe(true);6 });7 test('should return false if passed parameter types are not same', () => {8 expect(is.sameType(1, 'test')).toBe(false);9 });10 test('is.not.sameType(42, 7) => false', () => {11 expect(is.not.sameType(42, 7)).toBe(false);12 });...
is.js
Source:is.js
1const sameType = x => y => typeof(x) === typeof(y)2module.exports = {3 String: sameType(""),4 Function: sameType(sameType),5 Object: sameType({}),6 Number: sameType(0),7 Null: x => x === null,8 Undefined: sameType(undefined),9 Array: x => Array.isArray(x)...
Using AI Code Generation
1var assert = require('assert');2describe('Array', function() {3 describe('#indexOf()', function() {4 it('should return -1 when the value is not present', function() {5 assert.equal([1, 2, 3].indexOf(4), -1);6 });7 });8});9{10 "stats": {11 },12 "suites": {13 {14 {15 "title": "#indexOf()",16 {17 "fullTitle": "Array #indexOf() should return -1 when the value is not present",18 "code": "assert.equal([1, 2, 3].indexOf(4), -1);",19 "err": {20 at Context.it (test.js:7:16)21 at callFn (node_modules/mocha/lib/runnable.js:334:21)22 at Test.Runnable.run (node_modules/mocha/lib/runnable.js:327:7)23 at Runner.runTest (node
Using AI Code Generation
1const sameType = require('mochawesome-screenshots').sameType;2const sameType = require('mochawesome-screenshots').sameType;3const sameType = require('mochawesome-screenshots').sameType;4const sameType = require('mochawesome-screenshots').sameType;5const sameType = require('mochawesome-screenshots').sameType;6const sameType = require('mochawesome-screenshots').sameType;7const sameType = require('mochawesome-screenshots').sameType;8const sameType = require('mochawesome-screenshots').sameType;9const sameType = require('mochawesome-screenshots').sameType;10const sameType = require('mochawesome-screenshots').sameType;11const sameType = require('mochawesome-screenshots').sameType;12const sameType = require('mochawesome-screenshots').sameType;13const sameType = require('mochawesome-screenshots').sameType;14const sameType = require('mochawesome-screenshots').sameType;
Using AI Code Generation
1const mochawesome = require('mochawesome')2const expect = require('chai').expect3describe('sameType', () => {4 it('should return true if types match', () => {5 expect(sameType(1, 2)).to.be.true6 expect(sameType('foo', 'bar')).to.be.true7 expect(sameType([1,2], [3,4])).to.be.true8 })9 it('should return false if types do not match', () => {10 expect(sameType(1, 'foo')).to.be.false11 expect(sameType(1, [1,2])).to.be.false12 expect(sameType('foo', [1,2])).to.be.false13 })14})
Using AI Code Generation
1const assert = require('assert');2const mochawesome = require('mochawesome');3const { sameType } = mochawesome.addContext;4describe('sameType', function() {5 it('should return true for the same type', function() {6 assert.equal(sameType(1, 2), true);7 });8 it('should return false for different types', function() {9 assert.equal(sameType(1, '1'), false);10 });11});12const assert = require('assert');13const mochawesome = require('mochawesome');14const { sameType } = mochawesome.addContext;15describe('sameType', function() {16 it('should return true for the same type', function() {17 assert.equal(sameType(1, 2), true);18 });19 it('should return false for different types', function() {20 assert.equal(sameType(1, '1'), false);21 });22});23{24 "stats": {25 },26 "suites": {27 {28 {29 "code": "assert.equal(sameType(1, 2
Using AI Code Generation
1const assert = require('assert');2const { sameType } = require('mochawesome/addContext');3describe('Test', function() {4 it('should be same type', function() {5 assert(sameType(1, 2));6 });7});
Using AI Code Generation
1const assert = require('assert');2const mocha = require('mocha');3const mochawesome = require('mochawesome');4describe('test', function() {5 it('should have same type', function() {6 assert.strictEqual(mocha, mochawesome);7 });8});9const assert = require('assert');10const mocha = require('mocha');11const mochawesome = require('mochawesome');12describe('test2', function() {13 it('should have same type', function() {14 assert.strictEqual(mocha, mochawesome);15 });16});17const assert = require('assert');18const mocha = require('mocha');19const mochawesome = require('mochawesome');20describe('test3', function() {21 it('should have same type', function() {22 assert.strictEqual(mocha, mochawesome);23 });24});25const assert = require('assert');26const mocha = require('mocha');27const mochawesome = require('mochawesome');28describe('test4', function() {29 it('should have same type', function() {30 assert.strictEqual(mocha, mochawesome);31 });32});33const assert = require('assert');34const mocha = require('mocha');35const mochawesome = require('mochawesome');36describe('test5', function() {37 it('should have same type', function() {38 assert.strictEqual(mocha, mochawesome);39 });40});41const assert = require('assert');42const mocha = require('mocha');43const mochawesome = require('mochawesome');44describe('test6', function() {45 it('should have same type', function() {46 assert.strictEqual(mocha, mochawesome);47 });48});49const assert = require('assert');50const mocha = require('mocha');51const mochawesome = require('mochawesome');52describe('test7',
Using AI Code Generation
1const sameType = require('mochawesome/addContext');2describe('Test', function() {3 it('Test', function() {4 sameType('test');5 });6});7const sameType = require('mochawesome/addContext');8describe('Test', function() {9 it('Test', function() {10 sameType('test');11 });12});13const sameType = require('mochawesome/addContext');14describe('Test', function() {15 it('Test', function() {16 sameType('test');17 });18});19const sameType = require('mochawesome/addContext');20describe('Test', function() {21 it('Test', function() {22 sameType('test');23 });24});25const sameType = require('mochawesome/addContext');26describe('Test', function() {27 it('Test', function() {28 sameType('test');29 });30});31const sameType = require('mochawesome/addContext');32describe('Test', function() {33 it('Test', function() {34 sameType('test');35 });36});37const sameType = require('mochawesome/addContext');38describe('Test', function() {39 it('Test', function() {40 sameType('test');41 });42});43const sameType = require('mochawesome/addContext');44describe('Test', function() {45 it('Test', function() {46 sameType('test');47 });48});49const sameType = require('mochawesome/addContext');50describe('Test', function() {51 it('Test', function() {52 sameType('test');53 });54});55const sameType = require('mochawesome/addContext');
Using AI Code Generation
1const mocha = require('mochawesome');2const sameType = mocha.sameType;3const assert = require('assert');4describe('Test Suite', function() {5 it('Test case', function() {6 assert.equal(sameType(1, 2), true);7 });8});9{10 "stats": {11 },12 {13 {14 "code": "assert.equal(sameType(1, 2), true);",15 "err": {},16 }17 {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!