Best JavaScript code snippet using wpt
dv_insert.js
Source:dv_insert.js
1if ( typeof(tests) != "object" ) {2 tests = [];3}4/*5* Setup:6* Test: Insert documents with random numbers in an integer field7* Notes: This case is used for comparison against the similarly named8* Insert.DocValidation.OneInt to characterize the overhead of doc9* validation. 10*/11tests.push( { name: "Insert.DocValidation.OneInt.Compare", 12 tags: ['insert', 'DocValidation', 'compare'], 13 pre: function( collection) {14 collection.drop();15 },16 ops: [ {17 op: "insert",18 doc: {19 a: {"#RAND_INT": [0, 10000]} 20 } }21]});22/*23* Setup: Set up document validator to check for the existence and type 24* (integer) of a field.25* Test: Insert documents with random numbers in the integer field that26* is checked by the validator.27* Notes: This case tests the overhead for doc validation when only one28* field is validated.29*/30tests.push( { name: "Insert.DocValidation.OneInt", 31 tags: ['insert', 'DocValidation', 'regression'], 32 pre: function( collection) {33 collection.drop();34 collection.runCommand("create", {"validator": {35 $and: [36 {a: {$exists: true}},37 {a: {$type: 16}}38 ] }});39 },40 ops: [ {41 op: "insert",42 doc: {43 a: {"#RAND_INT": [0, 10000]} 44 } }45]});46/*47* Setup:48* Test: Insert documents with random numbers in ten integer fields.49* Notes: This case is used for comparison against the similarly named50* Insert.DocValidation.TenInt to characterize the overhead of doc51* validation. 52*/53tests.push( { name: "Insert.DocValidation.TenInt.Compare", 54 tags: ['insert', 'DocValidation', 'compare'], 55 pre: function( collection) {56 collection.drop();57 },58 ops: [ {59 op: "insert",60 doc: {61 a: {"#RAND_INT": [0, 10000]},62 b: {"#RAND_INT": [0, 10000]},63 c: {"#RAND_INT": [0, 10000]},64 d: {"#RAND_INT": [0, 10000]},65 e: {"#RAND_INT": [0, 10000]},66 f: {"#RAND_INT": [0, 10000]},67 g: {"#RAND_INT": [0, 10000]},68 h: {"#RAND_INT": [0, 10000]},69 i: {"#RAND_INT": [0, 10000]},70 j: {"#RAND_INT": [0, 10000]}71 } }72]});73/*74* Setup: Set up document validator to check for the existence and type 75* (integer) of ten fields.76* Test: Insert documents with random numbers in the ten integer fields77* that are checked by the validator.78* Notes: This case tests the overhead for doc validation when ten 79* fields are validated.80*/81tests.push( { name: "Insert.DocValidation.TenInt", 82 tags: ['insert', 'DocValidation', 'regression'], 83 pre: function( collection) {84 collection.drop();85 collection.runCommand("create", {"validator": {86 $and: [87 {a: {$exists: true}},88 {a: {$type: 16}},89 {b: {$exists: true}},90 {b: {$type: 16}},91 {c: {$exists: true}},92 {c: {$type: 16}},93 {d: {$exists: true}},94 {d: {$type: 16}},95 {e: {$exists: true}},96 {e: {$type: 16}},97 {f: {$exists: true}},98 {f: {$type: 16}},99 {g: {$exists: true}},100 {g: {$type: 16}},101 {h: {$exists: true}},102 {h: {$type: 16}},103 {a: {$exists: true}},104 {a: {$type: 16}},105 {i: {$exists: true}},106 {i: {$type: 16}},107 {j: {$exists: true}},108 {j: {$type: 16}}109 ] }});110 },111 ops: [ {112 op: "insert",113 doc: {114 a: {"#RAND_INT": [0, 10000]},115 b: {"#RAND_INT": [0, 10000]},116 c: {"#RAND_INT": [0, 10000]},117 d: {"#RAND_INT": [0, 10000]},118 e: {"#RAND_INT": [0, 10000]},119 f: {"#RAND_INT": [0, 10000]},120 g: {"#RAND_INT": [0, 10000]},121 h: {"#RAND_INT": [0, 10000]},122 i: {"#RAND_INT": [0, 10000]},123 j: {"#RAND_INT": [0, 10000]}124 } }125]});126/*127* Setup:128* Test: Insert documents with random numbers in twenty integer fields.129* Notes: This case is used for comparison against the similarly named130* Insert.DocValidation.TwentyInt to characterize the overhead of doc131* validation. 132*/133tests.push( { name: "Insert.DocValidation.TwentyInt.Compare", 134 tags: ['insert', 'DocValidation', 'compare'], 135 pre: function( collection) {136 collection.drop();137 },138 ops: [ {139 op: "insert",140 doc: {141 a: {"#RAND_INT": [0, 10000]},142 b: {"#RAND_INT": [0, 10000]},143 c: {"#RAND_INT": [0, 10000]},144 d: {"#RAND_INT": [0, 10000]},145 e: {"#RAND_INT": [0, 10000]},146 f: {"#RAND_INT": [0, 10000]},147 g: {"#RAND_INT": [0, 10000]},148 h: {"#RAND_INT": [0, 10000]},149 i: {"#RAND_INT": [0, 10000]},150 j: {"#RAND_INT": [0, 10000]},151 k: {"#RAND_INT": [0, 10000]},152 l: {"#RAND_INT": [0, 10000]},153 m: {"#RAND_INT": [0, 10000]},154 n: {"#RAND_INT": [0, 10000]},155 o: {"#RAND_INT": [0, 10000]},156 p: {"#RAND_INT": [0, 10000]},157 q: {"#RAND_INT": [0, 10000]},158 r: {"#RAND_INT": [0, 10000]},159 s: {"#RAND_INT": [0, 10000]},160 t: {"#RAND_INT": [0, 10000]}161 } }162]});163/*164* Setup: Set up document validator to check for the existence and type 165* (integer) of twenty fields.166* Test: Insert documents with random numbers in the twenty integer fields167* that are checked by the validator.168* Notes: This case tests the overhead for doc validation when twenty 169* fields are validated.170*/171tests.push( { name: "Insert.DocValidation.TwentyInt", 172 tags: ['insert', 'DocValidation', 'regression'], 173 pre: function( collection) {174 collection.drop();175 collection.runCommand("create", {"validator": {176 $and: [177 {a: {$exists: true}},178 {a: {$type: 16}},179 {b: {$exists: true}},180 {b: {$type: 16}},181 {c: {$exists: true}},182 {c: {$type: 16}},183 {d: {$exists: true}},184 {d: {$type: 16}},185 {e: {$exists: true}},186 {e: {$type: 16}},187 {f: {$exists: true}},188 {f: {$type: 16}},189 {g: {$exists: true}},190 {g: {$type: 16}},191 {h: {$exists: true}},192 {h: {$type: 16}},193 {a: {$exists: true}},194 {a: {$type: 16}},195 {i: {$exists: true}},196 {i: {$type: 16}},197 {j: {$exists: true}},198 {j: {$type: 16}},199 {k: {$exists: true}},200 {k: {$type: 16}},201 {l: {$exists: true}},202 {l: {$type: 16}},203 {m: {$exists: true}},204 {m: {$type: 16}},205 {n: {$exists: true}},206 {n: {$type: 16}},207 {o: {$exists: true}},208 {o: {$type: 16}},209 {p: {$exists: true}},210 {p: {$type: 16}},211 {q: {$exists: true}},212 {q: {$type: 16}},213 {r: {$exists: true}},214 {r: {$type: 16}},215 {s: {$exists: true}},216 {s: {$type: 16}},217 {t: {$exists: true}},218 {t: {$type: 16}},219 ] }});220 },221 ops: [ {222 op: "insert",223 doc: {224 a: {"#RAND_INT": [0, 10000]},225 b: {"#RAND_INT": [0, 10000]},226 c: {"#RAND_INT": [0, 10000]},227 d: {"#RAND_INT": [0, 10000]},228 e: {"#RAND_INT": [0, 10000]},229 f: {"#RAND_INT": [0, 10000]},230 g: {"#RAND_INT": [0, 10000]},231 h: {"#RAND_INT": [0, 10000]},232 i: {"#RAND_INT": [0, 10000]},233 j: {"#RAND_INT": [0, 10000]},234 k: {"#RAND_INT": [0, 10000]},235 l: {"#RAND_INT": [0, 10000]},236 m: {"#RAND_INT": [0, 10000]},237 n: {"#RAND_INT": [0, 10000]},238 o: {"#RAND_INT": [0, 10000]},239 p: {"#RAND_INT": [0, 10000]},240 q: {"#RAND_INT": [0, 10000]},241 r: {"#RAND_INT": [0, 10000]},242 s: {"#RAND_INT": [0, 10000]},243 t: {"#RAND_INT": [0, 10000]}244 } }...
backgrounds.js
Source:backgrounds.js
1"use strict";2function rand_int(min, max) {3 min = Math.ceil(min);4 max = Math.floor(max);5 return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive6}7function choose(arr) {8 return arr[rand_int(0, arr.length - 1)];9}10/** Generate a div that has image as it's background */11function image_div(image_href, top, left, size) {12 var el = document.createElement('DIV');13 el.style.backgroundImage = 'url(' + image_href + ')';14 el.style.backgroundSize = 'contain';15 el.style.backgroundRepeat = 'no-repeat';16 el.style.position = 'absolute';17 el.style.width = size + '%';18 el.style.height = size + '%';19 el.style.top = top + '%';20 el.style.left = left + '%';21 return el;22}23function set_transform(el, values) {24 el.style.transform = values.join(' ');25 el.style.WebkitTransform = values.join(' ');26}27function set_transition(el, values) {28 el.style.WebkitTransition = values.map(function (v) {29 if (v.indexOf('transform') === 0) {30 return '-webkit-' + v;31 } else {32 return v;33 }34 }).join(',');35 el.style.transition = values.join(',');36}37function particle_trigger(background_el, action) {38 var i, el, particle_els = background_el.querySelectorAll('.particles');39 for (i = 0; i < particle_els.length; i++) {40 el = particle_els[i];41 if (!action) {42 el.style.opacity = i === 0 ? 1 : 0;43 set_transform(el, [44 'scale(1.3)',45 'translateX(0)',46 'translateY(0)',47 ]);48 } else if (action === "zoomout" || action === "fly-out") {49 el.style.opacity = i === 0 ? 1 : 0.2 * (particle_els.length - i);50 set_transform(el, [51 'scale(' + (1.3 - (i * 0.05)) + ')',52 'translateX(0)',53 'translateY(0)',54 ]);55 } else if (action === "zoomin" || action === "fly-in") {56 el.style.opacity = i === 0 ? 1 : 0.2 * (particle_els.length - i);57 set_transform(el, [58 'scale(' + (1.3 + (i * 0.05)) + ')',59 'translateX(0)',60 'translateY(0)',61 ]);62 } else if (action.indexOf("pan-") === 0) {63 el.style.opacity = i === 0 ? 1 : 0.2 * (particle_els.length - i);64 set_transform(el, [65 'scale(1.3)',66 'translateX(' + (0 + (i-1) * (action.indexOf('left') > -1 ? 5 : action.indexOf('right') > -1 ? -5 : 0)) + 'px)',67 'translateY(' + (0 + (i-1) * (action.indexOf('up') > -1 ? 5 : action.indexOf('down') > -1 ? -5 : 0)) + 'px)',68 ]);69 }70 }71}72function particles(background_el) {73 var particle_els;74 background_el.innerHTML = '<div class="particles"><div class="particles-inner"></div></div>' +75 '<div class="particles"><div class="particles-inner"></div></div>' +76 '<div class="particles"><div class="particles-inner"></div></div>';77 particle_els = background_el.querySelectorAll('.particles');78 window.setTimeout(function () {79 var i;80 for (i = 0; i < particle_els.length; i++) {81 set_transform(particle_els[i], [82 'scale(1.3)',83 ]);84 particle_els[i].style.opacity = i === 0 ? 1 : 0;85 }86 }, 1000);87 // Poll until we can attach our hook88 window.setTimeout(function set_action_hook() {89 if (window.onezoom) {90 window.onezoom.add_hook('set_action', particle_trigger.bind(this, background_el));91 } else {92 window.setTimeout(set_action_hook, 100);93 }94 }, 100);95}96function floating(background_el, urls, start_horiz, initial_spacing) {97 var url = choose(urls),98 css_class = 'floating_' + url.replace(/\W/g, '_'),99 el;100 if (!el) {101 el = image_div(url, 0, start_horiz > 0 ? rand_int(0, 40) : rand_int(-10, 20), rand_int(40, 70));102 el.style.opacity = 0;103 set_transform(el, [104 'translateZ(0)', // NB: Prod browser into using GPU105 'translate(' + start_horiz + '%, ' + rand_int(initial_spacing * 120, initial_spacing * 130) + '%)',106 ]);107 set_transition(el, [108 'transform ' + initial_spacing * 400 + 's linear',109 'opacity 15s',110 ]);111 el.classList.add('floating');112 el.classList.add(css_class);113 background_el.appendChild(el);114 }115 window.setTimeout(function () {116 el.style.opacity = 0.3;117 set_transform(el, [118 'translateZ(0)', // NB: Prod browser into using GPU119 'translate(' + (start_horiz + rand_int(-20,20)) + '%, -100%)',120 'rotate(' + rand_int(-90, 90) + 'deg)',121 ]);122 }, 50);123 window.setTimeout(floating.bind(this, background_el, urls, start_horiz, 1), initial_spacing * 120000 * 2);124 window.setTimeout(function () {125 el.style.opacity = 0;126 }, initial_spacing * 360000);127 window.setTimeout(function () {128 background_el.removeChild(el);129 }, 600000);130}131function haze(parent_el) {132 var el,133 color = window.last_location_color || '#34ca00';134 if (parent_el.childElementCount === 0 || parent_el.lastChild.getAttribute('data-color') !== color) {135 el = document.createElement('DIV');136 el.setAttribute('data-color', color);137 el.style.width = "100%";138 el.style.height = "100%";139 el.style.background = 'radial-gradient(ellipse at ' + rand_int(10, 90) + '% ' + rand_int(10, 90) + '%, ' + color + ', transparent)';140 el.style.opacity = 0;141 el.style.transition = [142 'opacity 5s ease-in-out',143 ].join(',');144 parent_el.appendChild(el);145 window.setTimeout(function () {146 var i,147 reversed_nodes = Array.prototype.slice.call(parent_el.childNodes).reverse();148 for (i = 0; i < reversed_nodes.length; i++) {149 if (i === 0) {150 // Display newest node151 reversed_nodes[i].style.opacity = 0.25;152 } else if (i === 1) {153 // Hide second-newest node...
faker.js
Source:faker.js
1/* eslint-disable */2function rand(min=0, max=100, precision=2) {3 return (Math.random() * (max - min) + min).toFixed(precision);4}5function rand_int(min, max) {6 return Math.round(rand(min, max));7}8function rand_date(min_year=2015, max_year, min_month=1, max_month=12, min_day=1, max_day=28) {9 max_year = max_year || (new Date).getFullYear();10 let year = rand_int(min_year, max_year);11 let month = rand_int(min_month, max_month);12 let day = rand_int(min_day, max_day);13 return `${year}-${month}-${day}`;14}15function rand_deadline() {16 let D = new Date;17 let year = D.getFullYear();18 let month = D.getMonth();19 let day = D.getDate();20 return rand_date(21 year, year,22 month, month + rand_int(0, 1),23 day, day + rand_int(1, 20),24 )25}26function rand_bool() {27 return Math.random() >= .5;28}29function consumed() {30 return rand_int(0, 50);31}32function reason() {33 let list = ['æ°å¹´æ¢æ°è½¦', 'æ¥éèµéå¨è½¬', 'æ¥éè·è·¯è´¹', '车太å¤æ¾ä¸ä¸'];34 return list[rand_int(0,list.length - 1)];35}36function price() {37 return rand(1, 500, 1);38}39function title(brand, model) {40 let list = ['é£å°å', 'ç»æµå', 'åå¡å', 'è¿å¨å','奢åå'];41 let int = rand_int(5, 10);42 let year = rand_int(2014, 2018);43 let type = list[rand_int(0,list.length - 1)];44 return `${brand || ''} ${model} ${int} æå¿ ${year} ${type}`;45}46export default {47 title, price, reason, rand_date, rand_deadline, rand_bool, consumed, rand_int...
Using AI Code Generation
1var wpt = require('wpt');2var rand_int = wpt.rand_int(0, 100);3console.log(rand_int);4var wpt = require('wpt');5var rand_int = wpt.rand_int(0, 100);6console.log(rand_int);7var wpt = require('wpt');8var rand_int = wpt.rand_int(0, 100);9console.log(rand_int);10var wpt = require('wpt');11var rand_int = wpt.rand_int(0, 100);12console.log(rand_int);13var wpt = require('wpt');14var rand_int = wpt.rand_int(0, 100);15console.log(rand_int);16var wpt = require('wpt');17var rand_int = wpt.rand_int(0, 100);18console.log(rand_int);19var wpt = require('wpt');20var rand_int = wpt.rand_int(0, 100);21console.log(rand_int);22var wpt = require('wpt');23var rand_int = wpt.rand_int(0, 100);24console.log(rand_int);25var wpt = require('wpt');26var rand_int = wpt.rand_int(0, 100);27console.log(rand_int);28var wpt = require('wpt');29var rand_int = wpt.rand_int(0, 100);30console.log(rand_int);31var wpt = require('wpt');32var rand_int = wpt.rand_int(0, 100);33console.log(rand_int);
Using AI Code Generation
1var wpt = require('wpt');2var rand = wpt.rand_int(1, 10);3console.log(rand);4var wpt = require('wpt');5var rand = wpt.rand_int(1, 10);6console.log(rand);7var wpt = require('wpt');8var rand_str = wpt.rand_str(10);9console.log(rand_str);10{11 "dependencies": {12 }13}14var wpt = require('wpt');15var rand_str = wpt.rand_str(10);16console.log(rand_str);17{
Using AI Code Generation
1var wpt = require('./wpt.js');2var num = wpt.rand_int(0, 10);3console.log(num);4exports.rand_int = function(min, max) {5 return Math.floor(Math.random() * (max - min + 1)) + min;6};
Using AI Code Generation
1var wpt = require('wpt');2var rand_int = wpt.rand_int;3var x = rand_int(1, 100);4console.log(x);5var wpt = require('wpt');6var x = wpt.rand_int(1, 100);7console.log(x);8var wpt = require('wpt');9var x = wpt.rand_int(1, 100);10console.log(x);11var wpt = require('wpt');12var x = wpt.rand_int(1, 100);13console.log(x);14var wpt = require('wpt');15var x = wpt.rand_int(1, 100);16console.log(x);17var wpt = require('wpt');18var x = wpt.rand_int(1, 100);19console.log(x);20var wpt = require('wpt');21var x = wpt.rand_int(1, 100);22console.log(x);23var wpt = require('wpt');24var x = wpt.rand_int(1, 100);25console.log(x);26var wpt = require('wpt');27var x = wpt.rand_int(1, 100);28console.log(x);29var wpt = require('wpt');30var x = wpt.rand_int(1, 100);31console.log(x);32var wpt = require('wpt');33var x = wpt.rand_int(1, 100);34console.log(x);35var wpt = require('
Using AI Code Generation
1var rand_int = require('wptools').rand_int;2var i = rand_int(0, 10);3console.log(i);4var rand_int = require('wptools').rand_int;5var i = rand_int(0, 10);6console.log(i);7var rand_int = require('wptools').rand_int;8var i = rand_int(0, 10);9console.log(i);10var rand_int = require('wptools').rand_int;11var i = rand_int(0, 10);12console.log(i);13var rand_int = require('wptools').rand_int;14var i = rand_int(0, 10);15console.log(i);16var rand_int = require('wptools').rand_int;17var i = rand_int(0, 10);18console.log(i);19var rand_int = require('wptools').rand_int;20var i = rand_int(0, 10);21console.log(i);22var rand_int = require('wptools').rand_int;23var i = rand_int(0, 10);24console.log(i);25var rand_int = require('wptools').rand_int;26var i = rand_int(0, 10);27console.log(i);28var rand_int = require('wptools').rand_int;29var i = rand_int(0, 10);30console.log(i);31var rand_int = require('wptools').rand_int;32var i = rand_int(0, 10);33console.log(i
Using AI Code Generation
1var wpt = require('wpt');2var test = wpt.rand_int(1, 10);3console.log(test);4var wpt = require('wpt');5var test = wpt.rand_int(1, 10);6console.log(test);7var wpt = require('wpt');8var test = wpt.rand_int(1, 10);9console.log(test);10var wpt = require('wpt');11var test = wpt.rand_int(1, 10);12console.log(test);13var wpt = require('wpt');14var test = wpt.rand_int(1, 10);15console.log(test);16var wpt = require('wpt');17var test = wpt.rand_int(1, 10);18console.log(test);19var wpt = require('wpt');20var test = wpt.rand_int(1, 10);21console.log(test);22var wpt = require('wpt');23var test = wpt.rand_int(1, 10);24console.log(test);25var wpt = require('wpt');26var test = wpt.rand_int(1, 10);27console.log(test);28var wpt = require('wpt');29var test = wpt.rand_int(1, 10);30console.log(test);31var wpt = require('wpt');32var test = wpt.rand_int(1, 10);33console.log(test);34var wpt = require('wpt');35var test = wpt.rand_int(1, 10);36console.log(test);37var wpt = require('wpt');38var test = wpt.rand_int(1, 10);39console.log(test);
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!!