How to use sameType method in Mocha

Best JavaScript code snippet using mocha

type.js

Source:type.js Github

copy

Full Screen

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()...

Full Screen

Full Screen

prog.js

Source:prog.js Github

copy

Full Screen

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 }...

Full Screen

Full Screen

Convert.js

Source:Convert.js Github

copy

Full Screen

...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]) {...

Full Screen

Full Screen

life-like.js

Source:life-like.js Github

copy

Full Screen

...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();...

Full Screen

Full Screen

ap.spec.js

Source:ap.spec.js Github

copy

Full Screen

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()...

Full Screen

Full Screen

test.dependent.js

Source:test.dependent.js Github

copy

Full Screen

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();...

Full Screen

Full Screen

sameType.spec.js

Source:sameType.spec.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

is.js

Source:is.js Github

copy

Full Screen

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)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').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});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var chai = require('chai');3var expect = chai.expect;4var should = chai.should();5var should = require('should');6var util = require('util');7var _ = require('underscore');8var _ = require('lodash');9var _ = require('underscore');10var _ = require('lodash');11var _ = require('underscore');12var _ = require('lodash');13var _ = require('underscore');14var _ = require('lodash');15var _ = require('underscore');16var _ = require('lodash');17var _ = require('underscore');18var _ = require('lodash');19var _ = require('underscore');20var _ = require('lodash');21var _ = require('underscore');22var _ = require('lodash');23var _ = require('underscore');24var _ = require('lodash');25var _ = require('underscore');26var _ = require('lodash');27var _ = require('underscore');

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var sameType = require('mocha').utils.sameType;3assert(sameType(1, 2));4assert(sameType('foo', 'bar'));5assert(sameType(true, false));6assert(sameType(null, null));7assert(sameType(undefined, undefined));8assert(sameType([1, 2, 3], [4, 5, 6]));9assert(sameType({foo: 'bar'}, {baz: 'qux'}));10assert(sameType(function(){}, function(){}));11assert(!sameType(1, '1'));12assert(!sameType(1, true));13assert(!sameType('foo', 1));14assert(!sameType('foo', true));15assert(!sameType(true, 1));16assert(!sameType(true, 'foo'));17assert(!sameType(null, undefined));18assert(!sameType(undefined, null));19assert(!sameType([1, 2, 3], {foo: 'bar'}));20assert(!sameType({foo: 'bar'}, [1, 2, 3]));21assert(!sameType(function(){}, {foo: 'bar'}));22assert(!sameType({foo: 'bar'}, function(){}));23var assert = require('assert');24var sameType = require('mocha').utils.sameType;25assert(sameType(1, 2));26assert(sameType('foo', 'bar'));27assert(sameType(true, false));28assert(sameType(null, null));29assert(sameType(undefined, undefined));30assert(sameType([1, 2, 3], [4, 5, 6]));31assert(sameType({foo: 'bar'}, {baz: 'qux'}));32assert(sameType(function(){}, function(){}));33assert(!sameType(1, '1'));34assert(!sameType(1, true));35assert(!sameType('foo', 1));36assert(!sameType('foo', true));37assert(!sameType(true, 1));38assert(!sameType(true, 'foo'));39assert(!sameType(null, undefined));40assert(!sameType(undefined, null));41assert(!sameType([1, 2, 3], {foo: 'bar'}));42assert(!sameType({foo: 'bar'}, [1, 2, 3]));

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var chai = require('chai');3var expect = chai.expect;4var should = chai.should();5describe('sameType', function() {6 it('should return true for same type', function() {7 assert.equal(true, sameType(1, 2));8 });9 it('should return false for different type', function() {10 assert.equal(false, sameType(1, "2"));11 });12});13describe('expect', function() {14 it('should return true for same type', function() {15 expect(sameType(1, 2)).to.be.true;16 });17 it('should return false for different type', function() {18 expect(sameType(1, "2")).to.be.false;19 });20});21describe('should', function() {22 it('should return true for same type', function() {23 sameType(1, 2).should.be.true;24 });25 it('should return false for different type', function() {26 sameType(1, "2").should.be.false;27 });28});29describe('assert', function() {30 it('should return true for same type', function() {31 assert.equal(true, sameType(1, 2));32 });33 it('should return false for different type', function() {34 assert.equal(false, sameType(1, "2"));35 });36});37describe('assert', function() {38 it('should return true for same type', function() {39 assert.equal(true, sameType(1, 2));40 });41 it('should return false for different type', function() {42 assert.equal(false, sameType(1, "2"));43 });44});45describe('assert', function() {46 it('should return true for same type', function() {47 assert.equal(true, sameType(1, 2));48 });49 it('should return false for different type', function() {50 assert.equal(false, sameType(1, "2"));51 });52});53describe('assert', function() {54 it('should return true for same type

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var sameType = require('../lib/sameType.js');3describe('sameType', function() {4 it('should return true if all values are of the same type', function() {5 assert.equal(sameType([1, 2, 3]), true);6 });7 it('should return false if all values are not of the same type', function() {8 assert.equal(sameType([1, 2, '3']), false);9 });10});11var sameType = function(arr) {12 var type = typeof arr[0];13 for (var i = 0; i < arr.length; i++) {14 if (typeof arr[i] !== type) {15 return false;16 }17 }18 return true;19};20module.exports = sameType;21var assert = require('chai').assert;22var sameType = require('../lib/sameType.js');23describe('sameType', function() {24 it('should return true if all values are of the same type', function() {25 assert.equal(sameType([1, 2, 3]), true);26 });27 it('should return false if all values are not of the same type', function() {28 assert.equal(sameType([1, 2, '3']), false);29 });30});31var sameType = function(arr) {32 var type = typeof arr[0];33 for (var i = 0; i < arr.length; i++) {34 if (typeof arr[i] !== type) {35 return false;36 }37 }38 return true;39};40module.exports = sameType;41var assert = require('chai').assert;42var sameType = require('../lib/sameType.js');43describe('sameType', function() {44 it('should return true if all values are of the same type', function() {45 assert.equal(sameType([1, 2, 3]), true);46 });47 it('should return false if all values are not of the same type', function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2expect(1).to.have.sameType(1);3var should = require('chai').should();4(1).should.have.sameType(1);5var assert = require('assert');6assert.sameType(1,1);7var assert = require('chai').assert;8assert.sameType(1,1);9var expect = require('chai').expect;10expect(1).to.have.sameType(1);11var should = require('chai').should();12(1).should.have.sameType(1);13var assert = require('assert');14assert.sameType(1,1);15var assert = require('chai').assert;16assert.sameType(1,1);17var expect = require('chai').expect;18expect(1).to.have.sameType(1);19var should = require('chai').should();20(1).should.have.sameType(1);21var assert = require('assert');22assert.sameType(1,1);23var assert = require('chai').assert;24assert.sameType(1,1);25var expect = require('chai').expect;26expect(1).to.have.sameType(1);27var should = require('chai').should();

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var sameType = require('../src/sameType.js');3describe('sameType', function() {4 it('should return true if the given arguments are of same type', function() {5 assert.equal(sameType(1, 2), true);6 });7 it('should return false if the given arguments are of different type', function() {8 assert.equal(sameType(1, "2"), false);9 });10});11module.exports = function (a, b) {12 return typeof a === typeof b;13};

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var expect = require('chai').expect;3var assert = require('assert');4describe('Test', function() {5 it('should return true when the two values are of same type', function() {6 assert.sameType(1, 2);7 expect(1).to.have.sameType(2);8 assert.strictEqual(typeof 1, typeof 2);9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var sameType = require('mocha').utils.sameType;3describe('sameType', function() {4 it('should return true if the types of the two arguments are the same', function() {5 assert(sameType(10, 20));6 });7});8 1 passing (5ms)9 1 passing (5ms)10 1 passing (5ms)11 1 passing (5ms)12 1 passing (5ms)13 1 passing (5ms)14 1 passing (5ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const sameType = require('./sameType.js')3describe('sameType', function() {4 it('should return true if the two parameters are of same type', function() {5 assert.equal(sameType(1, 2), true);6 });7 it('should return false if the two parameters are not of same type', function() {8 assert.equal(sameType(1, "1"), false);9 });10});11 2 passing (6ms)

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 Mocha 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