Best JavaScript code snippet using wpt
mat3.js
Source:mat3.js
1define(2 [3 "spell/math/vec2",4 "spell/math/vec3",5 "spell/math/mat3"6 ],7 function(8 vec2,9 vec3,10 mat311 ) {12 "use strict"13 var FLOAT_EPSILON = 0.00000114 describe("spell.math.mat3", function() {15 it("should create an empty matrix correctly", function() {16 var matrix = mat3.create()17 if(18 matrix[0] != 1 ||19 matrix[1] != 0 ||20 matrix[2] != 0 ||21 matrix[3] != 0 ||22 matrix[4] != 1 ||23 matrix[5] != 0 ||24 matrix[6] != 0 ||25 matrix[7] != 0 ||26 matrix[8] != 1) {27 throw 'wrong empty matrix'28 }29 })30 it("should create an matrix from another matrix correctly", function() {31 var matrix = mat3.clone([1,2,3,4,5,6,7,8,9])32 if(33 matrix[0] !== 1 ||34 matrix[1] !== 2 ||35 matrix[2] !== 3 ||36 matrix[3] !== 4 ||37 matrix[4] !== 5 ||38 matrix[5] !== 6 ||39 matrix[6] !== 7 ||40 matrix[7] !== 8 ||41 matrix[8] !== 9) {42 throw 'wrong new matrix'43 }44 })45 it("should implement the str function correctly", function() {46 var matrix = mat3.clone( [1,2,3,4,5,6,7,8,9] ),47 matrixStr = mat3.str( matrix),48 correctStr = 'mat3(1, 2, 3, 4, 5, 6, 7, 8, 9)'49 if (matrixStr !== correctStr) {50 throw 'mat3.str( matrix ) produced ' + matrixStr + ' but ' + correctStr + ' was excpected'51 }52 })53// it("should implement the equal function correctly", function() {54// var matrixA = mat3.clone( [1,2,3,4,5,6,7,8,9] ),55// matrixB = mat3.clone( [1,2,3,4,5,6,7,8,9] )56//57// if(!mat3.equal( matrixA, matrixB )) {58// throw 'matrixA ' + mat3.str( matrixA ) + ' is not equal matrixB ' + mat3.str( matrixB )59// }60//61// //checkout within EPSILON62// matrixA[0] += FLOAT_EPSILON63// matrixA[1] += FLOAT_EPSILON64// matrixA[2] += FLOAT_EPSILON65// matrixA[3] += FLOAT_EPSILON66// matrixA[4] += FLOAT_EPSILON67// matrixA[5] += FLOAT_EPSILON68// matrixA[6] += FLOAT_EPSILON69// matrixA[7] += FLOAT_EPSILON70// matrixA[8] += FLOAT_EPSILON71//72// if(!mat3.equal( matrixA, matrixB )) {73// throw 'within EPSILON: matrixA ' + mat3.str( matrixA ) + ' is not equal matrixB ' + mat3.str( matrixB )74// }75//76// //check beyond EPSILON77// matrixA[0] += FLOAT_EPSILON78// matrixA[1] += FLOAT_EPSILON79// matrixA[2] += FLOAT_EPSILON80// matrixA[3] += FLOAT_EPSILON81// matrixA[4] += FLOAT_EPSILON82// matrixA[5] += FLOAT_EPSILON83// matrixA[6] += FLOAT_EPSILON84// matrixA[7] += FLOAT_EPSILON85// matrixA[8] += FLOAT_EPSILON86//87// if(mat3.equal( matrixA, matrixB )) {88// throw 'beyond EPSILON: matrixA ' + mat3.str( matrixA ) + ' is not equal matrixB ' + mat3.str( matrixB )89// }90//91// })92// it("should implement the set function correctly", function() {93// var matrixA = mat3.clone([1,2,3,4,5,6,7,8,9]),94// matrixB = mat3.clone([9,8,7,6,5,4,3,2,1])95//96// mat3.set(matrixA, matrixB)97//98// if (!mat3.equal(matrixA, matrixB)) {99// throw 'matrixA does not equal matrixB'100// }101// })102// it("should implement setDiagonalValues and setDiagonalVec3 correctly", function() {103// var matrixA = mat3.clone(),104// matrixB = mat3.clone(),105// checkMatrix = [ 1, 0, 0, 0, 2, 0, 0, 0, 3 ]106//107//108// mat3.setDiagonalValues( matrixA, 1, 2, 3 )109// mat3.setDiagonalVec3( matrixB, [ 1, 2, 3 ])110//111// if (!mat3.equal(checkMatrix, matrixA)) {112// throw 'expected ' + mat3.str(checkMatrix ) + ' got ' + mat3.str(matrixA)113// }114//115// if (!mat3.equal(checkMatrix, matrixB)) {116// throw 'expected ' + mat3.str(checkMatrix ) + ' got ' + mat3.str(matrixB)117// }118//119// })120//121// it("should set 3x3-identity matrix correctly", function() {122// var matrix = mat3.create()123// mat3.identity( matrix )124//125// if(!mat3.equal( [1,0,0, 0,1,0, 0,0,1], matrix)) {126// throw 'identity 3x3-matrix is wrong ' + mat3.str( matrix )127// }128// })129// it("should return the correct scale matrix", function() {130//131// var matrix = mat3.createScaleMatrix( 1, 2, 3 ),132// checkMatrix = [1, 0, 0, 0, 2, 0, 0, 0, 3]133//134//135// if (!mat3.equal(checkMatrix, matrix)) {136// throw 'expected ' + mat3.str(checkMatrix ) + ' got ' + mat3.str(matrix)137//138// }139// })140// it("should set the scale correctly for any matrix for a vec2", function() {141// var matrix = mat3.create(),142// matrixB = mat3.create(),143// testMatrix = mat3.clone([1,2,3,4,5,6,7,8,9]),144// vector = vec2.clone([2.5, -4.5]),145// scaleMatrix = mat3.createScaleMatrix(vector[0], vector[1], 1),146// checkMatrix = mat3.create()147//148// mat3.multiply( testMatrix, scaleMatrix, checkMatrix )149//150//151// mat3.set( testMatrix, matrix)152// mat3.scale( matrix, vector )153//154// if(!mat3.equal( matrix, checkMatrix )) {155// throw 'mat3.scale( matrix, vector ) syntax produced wrong result expected ' + mat3.str(checkMatrix) + ' got ' + mat3.str( matrix )156// }157//158// mat3.set( testMatrix, matrix)159// var anotherMatrix = mat3.scale( matrix, vector )160//161// if(!mat3.equal( anotherMatrix, checkMatrix )) {162// throw 'anotherMatrix = mat3.scale( matrix, vector ) produced a wrong result ' + mat3.str( anotherMatrix )163// }164//165// mat3.set( testMatrix, matrix)166// var anotherMatrix = mat3.scale( matrix, vector, matrixB )167// if(!mat3.equal( anotherMatrix, checkMatrix )) {168// throw 'anotherMatrix = mat3.scale( matrix, vector, matrixB ) produced a wrong result ' + mat3.str( matrixB )169// }170//171// })172// it("should correctly multiply with other 3x3 matrices", function() {173// var matrixA = mat3.clone( [12.2, 3, 6, 1, -4, 7, 2, 5, 8] ),174// matrixB = mat3.clone( [-8, 3, 6, 1, 4, 7, 2, 5, 2.4]),175// expectedResultA = mat3.clone( [ -82.6, -6, 21, 30.2, 22, 90, 34.2, -2, 66.2 ]),176// expectedResultB = mat3.clone( [ -82.6, 78.6, 108.6, 2, 22, -5.2, 5, 66, 66.2 ]),177// result = mat3.create()178//179//180// //Multiply A*B181// mat3.multiply(matrixA, matrixB, result)182//183// if (!mat3.equal(result, expectedResultA)) {184// throw 'Multiplying A*B failed. expected ' + mat3.str(expectedResultA) + ' got ' + mat3.str( result )185// }186//187// //Multiply B*A188// mat3.multiply(matrixB, matrixA, result)189//190// if (!mat3.equal(result, expectedResultB)) {191// throw 'Multiplying B*A failed. expected ' + mat3.str(expectedResultB) + ' got ' + mat3.str( result )192// }193//194//195// })196// it("should return the correct rotation matrix", function(){197//198// for (var angle = -2 * Math.PI; angle <= 2*Math.PI; angle += Math.PI/8 ) {199//200// //see http://en.wikipedia.org/wiki/Rotation_matrix201// var checkMatrix = [202// Math.cos( angle ),203// Math.sin( angle ),204// 0,205//206// -Math.sin( angle ),207// Math.cos( angle ),208// 0,209//210// 0,211// 0,212// 1213// ]214//215// var matrix = mat3.createRotateMatrix(angle)216//217// if (!mat3.equal(matrix, checkMatrix)) {218// throw 'expected ' + mat3.str(checkMatrix) + ' got ' + mat3.str(matrix)219// }220// }221// })222//223// it("rotate should rotate a identity 3x3-matrix around correctly", function() {224// var matrix = mat3.create(),225// checkMatrix = mat3.create()226//227// for ( var angle=-2*Math.PI; angle<= 2*Math.PI; angle+=Math.PI/8 ) {228// //rotate left229//230// mat3.identity( checkMatrix )231// mat3.multiply( checkMatrix, mat3.createRotateMatrix(angle) )232//233// mat3.identity( matrix )234// mat3.rotate( matrix, angle )235//236// if (!mat3.equal(matrix, checkMatrix)) {237// throw 'did not rotate matrix correctly by ' + angle + ' expected ' + mat3.str( checkMatrix ) + ' got ' + mat3.str( matrix )238// }239// }240// })241//242// it("should create a correct translate matrix", function() {243// var matrix = mat3.createTranslateMatrix(12, -4),244// checkMatrix = [ 1, 0, 0, 0, 1, 0, 12, -4, 1 ]245//246// if (!mat3.equal(matrix, checkMatrix)) {247// throw 'expected ' + mat3.str(checkMatrix) + ' got ' + mat3.str(matrix)248// }249// })250//251// it("translating the identity 3x3-matrix should be the same as the translate matrix", function() {252// var matrix = mat3.create(),253// translateMatrix = mat3.createTranslateMatrix(12, -4)254//255// mat3.identity(matrix)256// mat3.translate(matrix, [12, -4])257//258// if (!mat3.equal(matrix, translateMatrix)) {259// throw 'expected ' + mat3.str(translateMatrix) + ' got ' + mat3.str(matrix)260// }261// })262//263//264// it("should compose and decompose for a combined translate, scale, rotation correctly", function() {265// var matrixA = mat3.create(),266// matrixB = mat3.create(),267// invMatrix = mat3.create(),268// scales = [269// [ 1.1, 1.2 ],270// [ -1.3, -1.4 ],271// [ -1, 1 ],272// [ -1, -1 ],273// [ 1, -1.5 ]//,274// // [ 0, 1 ],275// // [ 1, 0 ]276// ],277// translations = [278// [ 0,0 ],279// [ 1,-1 ],280// [ -1,1 ],281// [ 0,1 ],282// [ 1,0 ],283// [ 1,1 ],284// [ 15.3, -14 ],285// [ -115.32, -13 ]286// ],287// skew = vec2.create(),288// checkScale = vec2.create(),289// checkTranslation = vec2.create(),290// checkSkews = vec2.create(),291// errors = [ ]292//293//294// for (var j=0; j<scales.length; j++) {295// var scale = scales[j]296//297// for (var i=0; i<translations.length; i++) {298// var translation = translations[i]299//300// for (var angle = -2 * Math.PI; angle <= 2*Math.PI; angle += Math.PI/2 ) {301//302// mat3.identity( matrixA )303// mat3.scale( matrixA, scale )304// //mat3.skew( matrixA, skew )305// mat3.rotate( matrixA, angle )306// mat3.translate( matrixA, translation )307//308//309// mat3.decompose( matrixA, checkScale, checkSkews, checkTranslation )310//311//312// mat3.identity( matrixB )313// mat3.scale( matrixB, checkScale )314// mat3.skew( matrixB, checkSkews )315// //mat3.rotate( matrixB, 0 )316// mat3.translate( matrixB, checkTranslation )317//318// if ( !mat3.equal( matrixA, matrixB ) ) {319// var error = 'checked scale ' + vec2.str(scale) + ' angle ' + angle + ' translation ' + vec2.str(translation) + ' matrix ' + mat3.str( matrixA ) + "\n" +320// 'got scale ' + vec2.str(checkScale) + ' skews ' + vec2.str( checkSkews ) + ' translation ' + vec2.str(checkTranslation) + ' matrix ' + mat3.str( matrixB ) + "\n"321//322// errors.push( error )323//324// } else {325// var success = 'worked ' + vec2.str(scale) + ' rotation ' + angle + ' translation ' + vec2.str(translation) + ' matrix ' + mat3.str( matrixA ) + "\n"326//327// //console.log( success )328// }329// }330// }331// }332//333//334// if (errors.length) {335// throw errors.join("\n")336// }337// })338 })339 }...
tictactoe.js
Source:tictactoe.js
1new Vue({2 el: '#app',3 data: {4 imgURL: 'images/blank.jpg',5 scene: true,6 tiles: [0,0,0,0,0,0,0,0,0],7 magicsq: [2,9,4,7,5,3,6,1,8],8 result: [0,0,0,0,0,0,0,0,0],9 checkmatrix: [10 [0,1,2],11 [0,3,6],12 [0,4,8],13 [1,4,7],14 [2,4,6],15 [2,5,8],16 [3,4,5],17 [6,7,8]18 ],19 count: 0,20 player: 0,21 sum:0,22 message: 'Game in progress'23 },24 methods: {25 grid: function(index){26 if (this.tiles[index] == 0){27 return 'images/blank.jpg';28 }else if (this.tiles[index] == 1){29 return 'images/cross.jpg';30 }else{31 return'images/nought.jpg';32 }33 },34 gclick: function(index) {35 if(this.tiles[index] == 0) {36 this.count++;37 this.player = (this.player + 1) % 2;38 if (this.player == 0) {39 this.$set(this.tiles, index, 1);40 }else{41 this.$set(this.tiles, index, -1);42 }43 }44 this.checkwin();45 },46 checkwin: function(){47 for(var i = 0; i < this.result.length; i++){48 this.result[i] = this.tiles[i] * this.magicsq[i];49 } 50 51 for (var i = 0; i < this.checkmatrix.length; i++ ){52 this.sum = this.result[this.checkmatrix[i][0]] 53 + this.result[this.checkmatrix[i][1]] 54 + this.result[this.checkmatrix[i][2]];55 console.log(this.sum);56 if (this.sum === 15) { 57 console.log("X wins");58 this.message = 'x wins';59 }60 if (this.sum === -15) { 61 console.log("O wins");62 this.message = 'o wins';63 }64 } 65 if (this.count === 9 && this.message === 'Game in progress'){66 console.log("Draw");67 this.message = 'Game Draw';68 }69 console.log("Player :" + this.player)70 }71 }...
test.js
Source:test.js
1function solve(input) {2 let matrix = input.map(row=>row.split(''));3 let checkMatrix = input.map(row=>row.toLowerCase().split(''));4 for (let row = 0; row < checkMatrix.length - 2; row++) {5 for (let col = 0; col < checkMatrix[row].length - 2; col++) {6 let char = checkMatrix[row][col];7 if (checkMatrix[row][col + 2] == char8 && checkMatrix[row + 1][col + 1] == char9 && checkMatrix[row + 2][col] == char10 && checkMatrix[row + 2][col + 2] == char) {11 matrix[row][col] = '';12 matrix[row][col + 2] = '';13 matrix[row + 1][col + 1] = '';14 matrix[row + 2][col] = '';15 matrix[row + 2][col + 2] = '';16 }17 }18 }19 for (let row of matrix) {20 console.log(row.join(''));21 }22}23solve(["8888888",24 "08*8*80",25 "808*888",...
Using AI Code Generation
1var wpt = require('./wpt.js');2];3console.log(wpt.checkMatrix(matrix));4var checkMatrix = function(matrix) {5 var isMagic = false;6 var sum = 0;7 var sum2 = 0;8 for (var i = 0; i < matrix.length; i++) {9 sum += matrix[i][i];10 sum2 += matrix[i][matrix.length - i - 1];11 }12 if (sum === sum2) {13 isMagic = true;14 }15 return isMagic;16};17module.exports = {18};19var wpt = require('./wpt.js');20];21console.log(wpt.checkMatrix(matrix));22var checkMatrix = function(matrix) {23 var isMagic = false;24 var sum = 0;25 var sum2 = 0;26 for (var i = 0; i < matrix.length; i++) {27 sum += matrix[i][i];28 sum2 += matrix[i][matrix.length - i - 1];29 }30 if (sum === sum2) {31 isMagic = true;32 }33 return isMagic;34};35module.exports = {36};37var wpt = require('./wpt.js');38];39console.log(wpt.checkMatrix(matrix));40var checkMatrix = function(matrix) {41 var isMagic = false;42 var sum = 0;43 var sum2 = 0;44 for (var i = 0; i < matrix.length
Using AI Code Generation
1var wpt = require('wpt');2wpt.checkMatrix('www.webpagetest.org', function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9### wpt.checkMatrix(location, callback)10* `location` - The location to check the matrix for. (e.g. 'Dulles:Chrome')
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkMatrix(url, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.runTest(url, function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21var testId = '141202_2P_2';22wpt.getTestStatus(testId, function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wpt = require('wpt');30var wpt = new WebPageTest('www.webpagetest.org');31var testId = '141202_2P_2';32wpt.getTestResults(testId, function(err, data) {33 if (err) {34 console.log(err);35 } else {36 console.log(data);37 }38});39var wpt = require('wpt');40var wpt = new WebPageTest('www.webpagetest.org');41var testId = '141202_2P_2';42var options = {43};44wpt.getTestResults(testId, options, function(err, data) {45 if (err) {46 console.log(err);47 } else {48 console.log(data);49 }50});
Using AI Code Generation
1var wpt = require('./wpt.js');2];3console.log(wpt.checkMatrix(matrix));4var wpt = require('./wpt.js');5];6console.log(wpt.checkMatrix(matrix));7 ];8 console.log(wpt.checkMatrix(matrix));9## 3.1. checkMatrix(matrix)10## 3.2. checkMatrixWithMessage(matrix)
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkMatrix('www.webpagetest.org', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10### getLocations(callback)11var wpt = require('wpt');12var wpt = new WebPageTest('www.webpagetest.org');13wpt.getLocations(function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20### getTesters(callback)21var wpt = require('wpt');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTesters(function(err, data) {24 if (err) {25 console.log(err);26 } else {27 console.log(data);28 }29});30### getTestStatus(testId, callback)31var wpt = require('wpt');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getTestStatus('160620_3F_7b2e1d0c7a5d6b0c7e8f6e5f7d2e1c5f', function(err, data) {34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 }39});40### getTestResults(testId, callback)41var wpt = require('wpt');42var wpt = new WebPageTest('www.webpagetest.org');43wpt.getTestResults('160620_3F_7b2e1d0c7a5d6b0c7e8f6e5f7d2e
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkMatrix(function(err, data) {4 if (err) {5 console.log('error: ' + err);6 }7 else {8 console.log(data);9 }10});
Using AI Code Generation
1var wptMatrix = require('./wptMatrix.js');2var matrix = new wptMatrix();3];4var result = matrix.checkMatrix(matrixArray);5console.log(result);6function wptMatrix() {7 this.checkMatrix = function (matrix) {8 var rows = matrix.length;9 var columns = matrix[0].length;10 var result = true;11 for (var i = 0; i < rows; i++) {12 for (var j = 0; j < columns; j++) {13 if (i < rows - 1 && j < columns - 1) {14 if (matrix[i][j] != matrix[i + 1][j + 1]) {15 result = false;16 break;17 }18 }19 }20 }21 return result;22 }23}24module.exports = wptMatrix;
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3var location = 'Dulles:Chrome';4var runs = 3;5var firstViewOnly = false;6var video = true;7var pollResults = 5;8var breakDown = true;9var private = false;10var connectivity = 'DSL';11var latency = 40;12var downloadThroughput = 2000;13var uploadThroughput = 1500;14var packetLossRate = 0;15var tcpdump = false;16var timeline = false;17var netLog = false;18var fullResolutionScreenshot = false;
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!!