Best JavaScript code snippet using wpt
random.test.js
Source:random.test.js
...48 //lower error considering the issue with Math.random()49 var test = random.distribution.normal(100000),50 mu = statistic.mean(test),51 sigma = statistic.standardDev(test);52 testing.approxEquals(mu, 0);53 testing.approxEquals(sigma, 1);54 var test = random.distribution.normal(100000, 20),55 mu = statistic.mean(test),56 sigma = statistic.standardDev(test);57 testing.approxEquals(mu, 20);58 testing.approxEquals(sigma, 1);59 for (var i = 0; i <= 4; i+=2) {60 for (var j = 0; j <= 1; j+=.5) {61 var n = Math.floor(Math.random()*100)+100000;62 var test = random.distribution.normal(n, i, j),63 mu = statistic.mean(test),64 sigma = statistic.standardDev(test);65 assert.equal(n, test.length);66 testing.approxEquals(mu, i);67 testing.approxEquals(sigma, j);68 }69 }70 numbers.EPSILON = t;71 done();72 });73 // random.distribution.logNormal74 test('random.distribution.logNormal should return a log normal distribution of length n', function(done) {75 var t = numbers.EPSILON;76 numbers.EPSILON = .1;77 var test = random.distribution.logNormal(100000),78 mu = statistic.mean(test),79 sigma = statistic.standardDev(test),80 expectedMu = Math.exp((0 + Math.pow(1, 2))/2),81 expectedSigma = Math.sqrt((Math.exp(Math.pow(1, 2)) - 1) * Math.exp(2 * 0 + Math.pow(1, 2)));82 testing.approxEquals(mu, expectedMu);83 testing.approxEquals(sigma, expectedSigma);84 // var i = 1,85 // j = 1,86 // test = random.distribution.logNormal(100000, i),87 // mu = statistic.mean(test),88 // sigma = statistic.standardDev(test),89 // expectedMu = Math.exp((i + Math.pow(j, 2))/2),90 // expectedSigma = Math.sqrt((Math.exp(Math.pow(j, 2)) - 1) * Math.exp(2 * i + Math.pow(j, 2)));91 // testing.approxEquals(mu, expectedMu);92 // testing.approxEquals(sigma, expectedSigma);93 // for (var i = 0; i <= 4; i+=2) {94 // for (var j = 0; j <= 1; j+=.5) {95 // var n = Math.floor(Math.random()*100)+100000;96 // var test = random.distribution.logNormal(n, i, j),97 // mu = statistic.mean(test),98 // sigma = statistic.standardDev(test),99 // expectedMu = Math.exp((i + Math.pow(j, 2))/2),100 // expectedSigma = Math.sqrt((Math.exp(Math.pow(j, 2)) - 1) * Math.exp(2 * i + Math.pow(j, 2)));101 // assert.equal(n, test.length);102 // testing.approxEquals(mu, expectedMu);103 // testing.approxEquals(sigma, expectedSigma);104 // }105 // }106 numbers.EPSILON = t;107 done();108 });109 // random.distribution.boxMuller110 test('random.distribution.boxMuller should return a n-sample of a normal distribution', function(done) {111 var t = numbers.EPSILON;112 numbers.EPSILON = .01;113 //lower error considering the issue with Math.random()114 var test = random.distribution.boxMuller(100000),115 mu = statistic.mean(test),116 sigma = statistic.standardDev(test);117 testing.approxEquals(mu, 0);118 testing.approxEquals(sigma, 1);119 var test = random.distribution.boxMuller(100000, 20),120 mu = statistic.mean(test),121 sigma = statistic.standardDev(test);122 testing.approxEquals(mu, 20);123 testing.approxEquals(sigma, 1);124 for (var i = 0; i <= 4; i+=2) {125 for (var j = 0; j <= 1; j+=.5) {126 var n = Math.floor(Math.random()*100)+100000;127 var test = random.distribution.boxMuller(n, i, j),128 mu = statistic.mean(test),129 sigma = statistic.standardDev(test);130 assert.equal(n, test.length);131 testing.approxEquals(mu, i);132 testing.approxEquals(sigma, j);133 }134 }135 numbers.EPSILON = t;136 done();137 });138 // random.distribution.irwinHall139 test('random.distribution.irwinHall should return a normal distribution of length n within bounds of (m/2 - sub, m/2)', function(done) {140 var test = random.distribution.irwinHall(100);141 testing.approxEquals(statistic.mean(test), 100 / 2, .5);142 testing.approxEquals(statistic.standardDev(test), Math.sqrt(100 / 12), .5);143 var test = random.distribution.irwinHall(100, 500);144 testing.approxEquals(statistic.mean(test), 500 / 2, 10);145 testing.approxEquals(statistic.standardDev(test), Math.sqrt(500 / 12), 5);146 var test = random.distribution.irwinHall(100, 500, 4);147 testing.approxEquals(statistic.mean(test), (500 - 4) / 2, 10);148 testing.approxEquals(statistic.standardDev(test), Math.sqrt((500 - 4) / 12), 5);149 done();150 });151 // random.distribution.irwinHallNormal152 test('random.distribution.irwinHallNormal should return a n-sample of a normal distribution with a bound of (-6, 6)', function(done) {153 var test = random.distribution.irwinHallNormal(50);154 testing.approxEquals(statistic.mean(test), 0, .3);155 testing.approxEquals(statistic.standardDev(test), 1, .3);156 done();157 });158 // random.distribution.bates159 test('random.distribution.bates should return a n-sample of a bates distribution', function(done) {160 var test = random.distribution.bates(100, 2);161 testing.approxEquals(statistic.mean(test), 1, .5);162 testing.approxEquals(statistic.standardDev(test), Math.sqrt((Math.pow(2 - 0, 2) / (12 * 100))), .5);163 var test = random.distribution.bates(100, 20, 10);164 testing.approxEquals(statistic.mean(test), 15, .5);165 testing.approxEquals(statistic.standardDev(test), Math.sqrt((Math.pow(20 - 10, 2) / (12 * 100))), .5);166 done();167 });...
simple_ai.js
Source:simple_ai.js
...4 if(distanceWithBall < 25.5) {5 return "kick";6 }7 var angle = vec.angle(env.ball.position);8 if(approxEquals(angle, 0)) {9 return "forward";10 }11 else if(approxEquals(angle, 45)) {12 return "forward-left";13 }14 else if(approxEquals(angle, 90)) {15 return "left";16 }17 else if(approxEquals(angle, 135)) {18 return "backward-left";19 }20 else if(approxEquals(Math.abs(angle), 180)) {21 return "backward";22 }23 else if(approxEquals(angle, -135)) {24 return "backward-right";25 }26 else if(approxEquals(angle, -90)) {27 return "right";28 }29 else /*if(approxEquals(angle, -45))*/ {30 return "forward-right";31 }32}33function approxEquals(v1, v2) {34 return Math.abs(v1-v2) <= 22.5;35}...
Using AI Code Generation
1var wptools = require('wikidata-sdk');2var assert = require('assert');3var a = 0.1;4var b = 0.2;5assert.ok(wptools.approxEquals(a + b, 0.3));6assert.ok(!wptools.approxEquals(a + b, 0.4));7console.log('Tests passed');8{9 "scripts": {10 },11 "repository": {
Using AI Code Generation
1var wptools = require('wptools');2var a = 1.0;3var b = 1.0000000000000001;4var c = 1.0000000000000002;5var wptools = require('wptools');6var a = 1.0;7var b = 1.0000000000000001;8var c = 1.0000000000000002;9var wptools = require('wptools');10var a = 1.0;11var b = 1.0000000000000001;12var c = 1.0000000000000002;13var wptools = require('wptools');14var a = 1.0;15var b = 1.0000000000000001;16var c = 1.0000000000000002;17var wptools = require('wptools');18var a = 1.0;19var b = 1.0000000000000001;20var c = 1.0000000000000002;21var wptools = require('wptools');22var a = 1.0;23var b = 1.0000000000000001;24var c = 1.0000000000000002;25var wptools = require('wptools');26var a = 1.0;27var b = 1.0000000000000001;
Using AI Code Generation
1var wptools = require('wikimedia-page-library').wptools;2var approxEquals = wptools.approxEquals;3var wptools = require('wikimedia-page-library').wptools;4var approxEquals = wptools.approxEquals;5var wptools = require('wikimedia-page-library').wptools;6var approxEquals = wptools.approxEquals;7var wptools = require('wikimedia-page-library').wptools;8var approxEquals = wptools.approxEquals;9var wptools = require('wikimedia-page-library').wptools;10var approxEquals = wptools.approxEquals;11var wptools = require('wikimedia-page-library').wptools;12var approxEquals = wptools.approxEquals;
Using AI Code Generation
1var wpt = require('wpt');2var assert = require('assert');3var a = 1.0;4var b = 1.0000001;5assert.ok(wpt.approxEquals(a, b));6assert.ok(!wpt.approxEquals(a, b, 1e-9));7assert.ok(wpt.approxEquals(a, b, 1e-6));8assert.ok(wpt.approxEquals(a, b, 1e-7));9var wpt = require('wpt');10var assert = require('assert');11var a = 1.0;12var b = 1.0000001;13assert.ok(wpt.approxEquals(a, b));14assert.ok(!wpt.approxEquals(a, b, 1e-9));15assert.ok(wpt.approxEquals(a, b, 1e-6));16assert.ok(wpt.approxEquals(a, b, 1e-7));17var wpt = require('wpt');18var assert = require('assert');19var a = 1.0;20var b = 1.0000001;21assert.ok(wpt.approxEquals(a, b));22assert.ok(!wpt.approxEquals(a, b, 1e-9));23assert.ok(wpt.approxEquals(a, b, 1e-6));24assert.ok(wpt.approxEquals(a, b, 1e-7));25var wpt = require('wpt');26var assert = require('assert');27var a = 1.0;28var b = 1.0000001;29assert.ok(wpt.approxEquals(a, b));30assert.ok(!wpt.approxEquals(a, b, 1e
Using AI Code Generation
1var wptools = require("wptools");2var wp = wptools.page("Barack Obama");3wp.get(function(err, doc) {4 if (err) {5 console.log(err);6 }7 if (doc) {8 console.log("approxEquals() method of wptools");9 console.log("Barack Obama's birthdate: " + doc.birth_date);10 console.log("Barack Obama's birthdate: " + doc.birth_date.approxEquals("August 4, 1961"));11 }12});
Using AI Code Generation
1var wpt = new Wpt();2var wpt2 = new Wpt();3var wpt3 = new Wpt();4wpt.lat = 10.0;5wpt.lon = 20.0;6wpt2.lat = 10.0;7wpt2.lon = 20.0;
Using AI Code Generation
1var wptools = require('./wptools.js');2var result = wptools.approxEquals(1,1.1,0.2);3console.log(result);4var result = wptools.approxEquals(1,1.1,0.01);5console.log(result);6var result = wptools.approxEquals(1,1.1,0.11);7console.log(result);8var result = wptools.approxEquals(1,1.1,0.09);9console.log(result);10var result = wptools.approxEquals(1,1.1,0.1);11console.log(result);12var result = wptools.approxEquals(1,1.1,0.0);13console.log(result);14var result = wptools.approxEquals(1,1.1);15console.log(result);16var result = wptools.approxEquals(1,1.01,0.1);17console.log(result);18var result = wptools.approxEquals(1,1.01,0.01);19console.log(result);20var result = wptools.approxEquals(1,1.01);21console.log(result);22var result = wptools.approxEquals(1,1.01,0.0);23console.log(result);24var result = wptools.approxEquals(1,1.01,0.001);25console.log(result);
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!!