Best JavaScript code snippet using wpt
testharness.js
Source:testharness.js
...35 });36}37const assert_true = assertEquals.bind(null, true);38const assert_false = assertEquals.bind(null, false);39function same_value(x, y) {40 if (y !== y) {41 // NaN case42 return x!==x;43 }44 if (x === 0 && y === 0) {45 // Distinguish +0 and -046 return 1/x === 1/y;47 }48 return x === y;49}50function assert_equals(expected, found, description) {51 if (typeof found != typeof expected) {52 assert_true(false, "assert_equals", description,53 "expected (" + typeof expected + ") ${expected} but got (" +54 typeof found + ") ${found}", {expected:expected, found:found});55 }56 assert_true(same_value(found, expected), "assert_equals", description,57 "expected ${expected} but got ${found}",58 {expected:expected, found:found});59}60function assert_not_equals(expected, found, description) {61 assert_true(!same_value(found, expected), "assert_not_equals", description,62 "got disallowed value ${found}", {found:found});63}64function assert_array_equals(actual, expected, description) {65 assert_true(66 typeof actual === 'object' && actual !== null && 'length' in actual,67 'assert_array_equals', description, 'value is ${actual}, expected array',68 {actual: actual});69 assert_true(70 actual.length === expected.length, 'assert_array_equals', description,71 'lengths differ, expected ${expected} got ${actual}',72 {expected: expected.length, actual: actual.length});73 for (let i = 0; i < actual.length; i++) {74 assert_true(75 actual.hasOwnProperty(i) === expected.hasOwnProperty(i),76 'assert_array_equals', description,77 'property ${i}, property expected to be ${expected} but was ${actual}',78 {79 i: i,80 expected: expected.hasOwnProperty(i) ? 'present' : 'missing',81 actual: actual.hasOwnProperty(i) ? 'present' : 'missing'82 });83 assert_true(84 same_value(expected[i], actual[i]), 'assert_array_equals', description,85 'property ${i}, expected ${expected} but got ${actual}',86 {i: i, expected: expected[i], actual: actual[i]});87 }88}89function unreached_func(msg) {90 return function trap() {91 assert_unreached(msg);92 };93}94function assert_unreached(description) {95 throw new Error(`unreachable:\n${description}`);96}97function format_value(s) {98 // TODO...
index.js
Source:index.js
1function getPrediction() {2 document.getElementById('Btn-loading').style.display = 'flex';3 document.getElementById('Btn-predecir').style.display = 'none';4 //clear data5 document.getElementById("resultadoFormatBUY").value = '';6 document.getElementById("resultadoFormatSELL").value = '';7 document.getElementById("resultadoFormatSAME").value = '';8 document.getElementById("divColorResult").style.display = 'none';9 // init10 let v_apertura = 011 let v_maximo = 012 let v_minimo = 013 v_apertura = document.getElementById("apertura").value;14 v_maximo = document.getElementById("maximo").value;15 v_minimo = document.getElementById("minimo").value;16 // select17 const hiddenLayersSelect = document.getElementById('selectHL').value;18 const network = new brain.NeuralNetwork({19 hiddenLayers: [hiddenLayersSelect]20 });21 let result = 0;22 if (hiddenLayersSelect == 5) {23 fetch('../data/network_state_5layers.json').then(response => {24 response.json().then(jsondata => {25 network.fromJSON(jsondata);26 result = network.run({ apertura: v_apertura, maximo: v_maximo, minimo: v_minimo });27 imprimir(result);28 });29 });30 }31 if (hiddenLayersSelect == 10) {32 fetch('../data/network_state_10layers.json').then(response => {33 response.json().then(jsondata => {34 network.fromJSON(jsondata);35 result = network.run({ apertura: v_apertura, maximo: v_maximo, minimo: v_minimo });36 imprimir(result);37 });38 });39 }40 function imprimir(result) {41 let buy_value = result.BUY * 100;42 let sell_value = result.SELL * 100;43 let same_value = result.SAME * 100;44 //btns45 document.getElementById('Btn-loading').style.display = 'none';46 document.getElementById('Btn-predecir').style.display = 'flex';47 //results48 document.getElementById("resultadoFormatBUY").innerHTML = `BUY: ${buy_value.toFixed(4)}%`;49 document.getElementById("resultadoFormatSELL").innerHTML = `SELL: ${sell_value.toFixed(4)}%`;50 document.getElementById("resultadoFormatSAME").innerHTML = `SAME: ${same_value.toFixed(4)}%`;51 document.getElementById("divColorResult").style.display = 'flex';52 if (buy_value > sell_value && buy_value > same_value) {53 document.getElementById('divColorResult').style.backgroundColor = '#00df58';54 } else if (sell_value > buy_value && sell_value > same_value) {55 document.getElementById('divColorResult').style.backgroundColor = '#df002a';56 } else if (same_value > buy_value && same_value > sell_value) {57 document.getElementById('divColorResult').style.backgroundColor = '#d5e113';58 }59 document.getElementById('result').innerHTML = brain.utilities.toSVG(network);60 }...
redeclaration.js
Source:redeclaration.js
1// This file was procedurally generated from the following sources:2// - src/class-elements/redeclaration.case3// - src/class-elements/default/cls-decl.template4/*---5description: Redeclaration of public fields with the same name (field definitions in a class declaration)6esid: prod-FieldDefinition7features: [class-fields-public, computed-property-names, class]8flags: [generated]9includes: [propertyHelper.js, compareArray.js]10info: |11 2.13.2 Runtime Semantics: ClassDefinitionEvaluation12 ...13 30. Set the value of F's [[Fields]] internal slot to fieldRecords.14 ...15 2.14 [[Construct]] ( argumentsList, newTarget)16 ...17 8. If kind is "base", then18 ...19 b. Let result be InitializeInstanceFields(thisArgument, F).20 ...21 2.9 InitializeInstanceFields ( O, constructor )22 3. Let fieldRecords be the value of constructor's [[Fields]] internal slot.23 4. For each item fieldRecord in order from fieldRecords,24 a. If fieldRecord.[[static]] is false, then25 i. Perform ? DefineField(O, fieldRecord).26---*/27var x = [];28class C {29 y = (x.push("a"), "old_value");30 ["y"] = (x.push("b"), "another_value");31 "y" = (x.push("c"), "same_value");32 y = (x.push("d"), "same_value");33}34var c = new C();35assert.sameValue(Object.hasOwnProperty.call(C.prototype, "y"), false);36assert.sameValue(Object.hasOwnProperty.call(C, "y"), false);37verifyProperty(c, "y", {38 value: "same_value",39 enumerable: true,40 writable: true,41 configurable: true42});43assert(compareArray(x, ["a", "b", "c", "d"]));...
Using AI Code Generation
1function same_value(x, y) {2 if (x === y) {3 if (x === 0) {4 return 1 / x === 1 / y;5 }6 return true;7 }8 return x !== x && y !== y;9}10function same_value_zero(x, y) {11 return x === y || (x === 0 && y === 0);12}13function test() {14 var x = [0, 0, 0, 0, 0, 0, 0, 0];15 var y = [0, 0, 0, 0, 0, 0, 0, 0];16 var z = [0, 0, 0, 0, 0, 0, 0, 0];17 var w = [0, 0, 0, 0, 0, 0, 0, 0];18 var v = [0, 0, 0, 0, 0, 0, 0, 0];19 x[0] = 1;20 y[0] = -0;21 z[0] = 0;22 w[0] = NaN;23 v[0] = NaN;24 x[1] = 2;25 y[1] = -0;26 z[1] = 0;27 w[1] = NaN;28 v[1] = NaN;29 x[2] = 3;30 y[2] = -0;31 z[2] = 0;32 w[2] = NaN;33 v[2] = NaN;34 x[3] = 4;35 y[3] = -0;36 z[3] = 0;37 w[3] = NaN;38 v[3] = NaN;39 x[4] = 5;40 y[4] = -0;41 z[4] = 0;42 w[4] = NaN;43 v[4] = NaN;44 x[5] = 6;45 y[5] = -0;46 z[5] = 0;47 w[5] = NaN;48 v[5] = NaN;
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(url, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status check: ' + data.statusText);6 var testId = data.data.testId;7 wpt.getTestResults(testId, function(err, data) {8 if (err) return console.error(err);9 console.log('Test results: ' + data.data.average.firstView.loadTime);10 });11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.runTest(url, function(err, data) {15 if (err) return console.error(err);16 console.log('Test status check: ' + data.statusText);17 var testId = data.data.testId;18 wpt.getTestResults(testId, function(err, data) {19 if (err) return console.error(err);20 console.log('Test results: ' + data.data.average.firstView.loadTime);21 });22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25wpt.runTest(url, function(err, data) {26 if (err) return console.error(err);27 console.log('Test status check: ' + data.statusText);28 var testId = data.data.testId;29 wpt.getTestResults(testId, function(err, data) {30 if (err) return console.error(err);31 console.log('Test results: ' + data.data.average.firstView.loadTime);32 });
Using AI Code Generation
1function test() {2 var x = {};3 var y = {};4 var z = x;5 var a = {};6 var b = {};7 var c = a;8 var d = {};9 var e = {};10 var f = d;11 var g = {};12 var h = {};13 var i = g;14 var j = {};15 var k = {};16 var l = j;17 var m = {};18 var n = {};19 var o = m;20 var p = {};21 var q = {};22 var r = p;23 var s = {};24 var t = {};25 var u = s;26 var v = {};27 var w = {};28 var xx = v;29 var y2 = {};30 var z2 = {};31 var a2 = y2;32 var b2 = {};33 var c2 = {};34 var d2 = b2;35 var e2 = {};36 var f2 = {};37 var g2 = e2;38 var h2 = {};39 var i2 = {};40 var j2 = h2;41 var k2 = {};42 var l2 = {};43 var m2 = k2;44 var n2 = {};45 var o2 = {};46 var p2 = n2;47 var q2 = {};48 var r2 = {};49 var s2 = q2;50 var t2 = {};51 var u2 = {};52 var v2 = t2;53 var w2 = {};54 var x2 = {};55 var y3 = w2;56 var z3 = {};57 var a3 = {};58 var b3 = z3;59 var c3 = {};60 var d3 = {};61 var e3 = c3;62 var f3 = {};63 var g3 = {};64 var h3 = f3;65 var i3 = {};66 var j3 = {};67 var k3 = i3;68 var l3 = {};69 var m3 = {};70 var n3 = l3;71 var o3 = {};72 var p3 = {};73 var q3 = o3;74 var r3 = {};75 var s3 = {};76 var t3 = r3;77 var u3 = {};78 var v3 = {};79 var w3 = u3;80 var x3 = {};
Using AI Code Generation
1function assert_equals(a, b, msg) {2 if (a !== b) {3 throw new Error(msg);4 }5}6function assert_true(a, msg) {7 if (!a) {8 throw new Error(msg);9 }10}11function assert_false(a, msg) {12 if (a) {13 throw new Error(msg);14 }15}16function assert_throws(code, func, msg) {17 try {18 func();19 } catch (e) {20 if (e instanceof code) {21 return;22 } else {23 throw new Error(msg);24 }25 }26 throw new Error(msg);27}28function assert_array_equals(a, b, msg) {29 if (a.length !== b.length) {30 throw new Error(msg);31 }32 for (var i = 0; i < a.length; i++) {33 if (a[i] !== b[i]) {34 throw new Error(msg);35 }36 }37}38function assert_regexp_match(s, re, msg) {39 if (!re.test(s)) {40 throw new Error(msg);41 }42}43function assert_class_string(obj, string, msg) {44 if (Object.prototype.toString.call(obj) !== '[object ' + string + ']') {45 throw new Error(msg);46 }47}48function assert_own_property(obj, prop, msg) {49 if (!obj.hasOwnProperty(prop)) {50 throw new Error(msg);51 }52}53function assert_in_array(value, array, msg) {54 if (array.indexOf(value) === -1) {55 throw new Error(msg);56 }57}58function assert_not_equals(a, b, msg) {59 if (a === b) {60 throw new Error(msg);61 }62}63function assert_readonly(obj, prop, msg) {64 try {65 obj[prop] = "FAIL";66 } catch (e) {67 if (obj[prop] !== "FAIL") {68 throw new Error(msg);69 }70 return;71 }72 throw new Error(msg);73}74function assert_unreached(msg) {75 throw new Error(msg);76}77function done() {78}79function assert_approx_equals(a, b, epsilon, msg) {80 if (Math.abs(a - b) > epsilon) {
Using AI Code Generation
1var wpt = require('webpagetest');2var util = require('util');3var wpt = new WebPageTest('www.webpagetest.org');4var testId = null;5var testResults = null;6var testResultsStr = null;7wpt.runTest(url, function(err, data) {8 if (err) return console.error(err);9 testId = data.data.testId;10 console.log('Test ID: ' + testId);11});12setTimeout(function() {13 wpt.getTestResults(testId, function(err, data) {14 if (err) return console.error(err);15 testResults = data.data;16 console.log('Test Results: ');17 console.log(testResults);18 });19}, 30000);20setTimeout(function() {21 wpt.getTestResults(testId, function(err, data) {22 if (err) return console.error(err);23 testResultsStr = data;24 console.log('Test Results: ');25 console.log(testResultsStr);26 });27}, 60000);
Using AI Code Generation
1var same_value = require('./same_value.js');2var same_value_zero = require('./same_value_zero.js');3var same_value_non_number = require('./same_value_non_number.js');4var same_value_undefined = require('./same_value_undefined.js');5var same_value_null = require('./same_value_null.js');6var same_value_true = require('./same_value_true.js');7var same_value_false = require('./same_value_false.js');8var same_value_string = require('./same_value_string.js');9var same_value_number = require('./same_value_number.js');10var same_value_object = require('./same_value_object.js');11var same_value_symbol = require('./same_value_symbol.js');12var same_value_bigint = require('./same_value_bigint.js');13var same_value_negative_zero = require('./same_value_negative_zero.js');14var same_value_positive_zero = require('./same_value_positive_zero.js');15var same_value_negative_zero_positive_zero = require('./same_value_negative_zero_positive_zero.js');16var same_value_negative_zero_negative_zero = require('./same_value_negative_zero_negative_zero.js');17var same_value_positive_zero_positive_zero = require('./same_value_positive_zero_positive_zero.js');18var same_value_positive_zero_negative_zero = require('./same_value_positive_zero_negative_zero.js');19var same_value_nan = require('./same_value_nan.js');20var same_value_nan_nan = require('./same_value_nan_nan.js');21var same_value_nan_positive_zero = require('./same_value_nan_positive_zero.js');22var same_value_nan_negative_zero = require('./same_value_nan_negative_zero.js');23var same_value_nan_positive_infinity = require('./same_value_nan_positive_infinity.js');24var same_value_nan_negative_infinity = require('./same_value_nan_negative_infinity.js');25var same_value_nan_positive_infinity_negative_infinity = require('./same_value_nan_positive_infinity_negative_infinity.js');26var same_value_nan_positive_infinity_positive_infinity = require('./same_value_nan_positive_infinity_positive_infinity.js');27var same_value_nan_negative_infinity_negative_infinity = require('./same_value_nan_negative_infinity_negative_infinity.js');28var same_value_nan_negative_infinity_positive_infinity = require('./same_value_nan_negative_infinity_positive_infinity.js');29var same_value_nan_positive_infinity_positive_zero = require('./same_value_nan_positive_infinity_positive_zero.js');30var same_value_nan_negative_infinity_negative_zero = require('./same_value_nan_negative
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!!