How to use round method in wpt

Best JavaScript code snippet using wpt

calculate-round.test.ts

Source:calculate-round.test.ts Github

copy

Full Screen

1import "jest-extended";2import { calculateRound, isNewRound } from "@packages/core-kernel/src/utils/round-calculator";3import { Errors, Managers } from "@packages/crypto";4import { devnet } from "@packages/crypto/src/networks";5describe("Round Calculator", () => {6 describe("calculateRound", () => {7 describe("static delegate count", () => {8 it("should calculate the round when nextRound is the same", () => {9 for (let i = 0, height = 51; i < 1000; i++, height += 51) {10 const { round, nextRound } = calculateRound(height - 1);11 expect(round).toBe(i + 1);12 expect(nextRound).toBe(i + 1);13 }14 });15 it("should calculate the round when nextRound is not the same", () => {16 for (let i = 0, height = 51; i < 1000; i++, height += 51) {17 const { round, nextRound } = calculateRound(height);18 expect(round).toBe(i + 1);19 expect(nextRound).toBe(i + 2);20 }21 });22 it("should calculate the correct round", () => {23 const activeDelegates = 51;24 for (let i = 0; i < 1000; i++) {25 const { round, nextRound } = calculateRound(i + 1);26 expect(round).toBe(Math.floor(i / activeDelegates) + 1);27 expect(nextRound).toBe(Math.floor((i + 1) / activeDelegates) + 1);28 }29 });30 it("should calculate correct round for each height in round", () => {31 const milestones = [{ height: 1, activeDelegates: 4 }];32 const config = { ...devnet, milestones };33 Managers.configManager.setConfig(config);34 const testVector = [35 // Round 136 { height: 1, round: 1, roundHeight: 1, nextRound: 1, activeDelegates: 4 },37 { height: 2, round: 1, roundHeight: 1, nextRound: 1, activeDelegates: 4 },38 { height: 3, round: 1, roundHeight: 1, nextRound: 1, activeDelegates: 4 },39 { height: 4, round: 1, roundHeight: 1, nextRound: 2, activeDelegates: 4 },40 // Round 241 { height: 5, round: 2, roundHeight: 5, nextRound: 2, activeDelegates: 4 },42 { height: 6, round: 2, roundHeight: 5, nextRound: 2, activeDelegates: 4 },43 { height: 7, round: 2, roundHeight: 5, nextRound: 2, activeDelegates: 4 },44 { height: 8, round: 2, roundHeight: 5, nextRound: 3, activeDelegates: 4 },45 // Round 346 { height: 9, round: 3, roundHeight: 9, nextRound: 3, activeDelegates: 4 },47 { height: 10, round: 3, roundHeight: 9, nextRound: 3, activeDelegates: 4 },48 { height: 11, round: 3, roundHeight: 9, nextRound: 3, activeDelegates: 4 },49 { height: 12, round: 3, roundHeight: 9, nextRound: 4, activeDelegates: 4 },50 ];51 testVector.forEach((item) => {52 const result = calculateRound(item.height);53 expect(result.round).toBe(item.round);54 expect(result.roundHeight).toBe(item.roundHeight);55 expect(isNewRound(result.roundHeight)).toBeTrue();56 expect(result.nextRound).toBe(item.nextRound);57 expect(result.maxDelegates).toBe(item.activeDelegates);58 });59 });60 });61 describe("dynamic delegate count", () => {62 it("should calculate the correct with dynamic delegate count", () => {63 const milestones = [64 { height: 1, activeDelegates: 2 },65 { height: 3, activeDelegates: 3 },66 { height: 9, activeDelegates: 1 },67 { height: 12, activeDelegates: 3 },68 ];69 const testVector = [70 // Round 1 - milestone71 { height: 1, round: 1, roundHeight: 1, nextRound: 1, activeDelegates: 2 },72 { height: 2, round: 1, roundHeight: 1, nextRound: 2, activeDelegates: 2 },73 // Round 2 - milestone change74 { height: 3, round: 2, roundHeight: 3, nextRound: 2, activeDelegates: 3 },75 { height: 4, round: 2, roundHeight: 3, nextRound: 2, activeDelegates: 3 },76 { height: 5, round: 2, roundHeight: 3, nextRound: 3, activeDelegates: 3 },77 // Round 378 { height: 6, round: 3, roundHeight: 6, nextRound: 3, activeDelegates: 3 },79 { height: 7, round: 3, roundHeight: 6, nextRound: 3, activeDelegates: 3 },80 { height: 8, round: 3, roundHeight: 6, nextRound: 4, activeDelegates: 3 },81 // Round 4 - 6 - milestone change82 { height: 9, round: 4, roundHeight: 9, nextRound: 5, activeDelegates: 1 },83 { height: 10, round: 5, roundHeight: 10, nextRound: 6, activeDelegates: 1 },84 { height: 11, round: 6, roundHeight: 11, nextRound: 7, activeDelegates: 1 },85 // Round 7 - milestone change86 { height: 12, round: 7, roundHeight: 12, nextRound: 7, activeDelegates: 3 },87 { height: 13, round: 7, roundHeight: 12, nextRound: 7, activeDelegates: 3 },88 { height: 14, round: 7, roundHeight: 12, nextRound: 8, activeDelegates: 3 },89 // Round 890 { height: 15, round: 8, roundHeight: 15, nextRound: 8, activeDelegates: 3 },91 ];92 const config = { ...devnet, milestones };93 Managers.configManager.setConfig(config);94 testVector.forEach(({ height, round, roundHeight, nextRound, activeDelegates }) => {95 const result = calculateRound(height);96 expect(result.round).toBe(round);97 expect(result.roundHeight).toBe(roundHeight);98 expect(isNewRound(result.roundHeight)).toBeTrue();99 expect(result.nextRound).toBe(nextRound);100 expect(result.maxDelegates).toBe(activeDelegates);101 });102 });103 it("should throw if active delegates is not changed on new round", () => {104 const milestones = [105 { height: 1, activeDelegates: 3 },106 { height: 3, activeDelegates: 4 }, // Next milestone should be 4107 ];108 // @ts-ignore109 Managers.configManager.validateMilestones = jest.fn();110 const config = { ...devnet, milestones };111 Managers.configManager.setConfig(config);112 calculateRound(1);113 calculateRound(2);114 expect(() => calculateRound(3)).toThrowError(Errors.InvalidMilestoneConfigurationError);115 });116 });117 });...

Full Screen

Full Screen

math-round.js

Source:math-round.js Github

copy

Full Screen

...29function testRound(expect, input) {30 // Make source code different on each invocation to make31 // sure it gets optimized each time.32 var doRound = new Function('input',33 '"' + (test_id++) + '";return Math.round(input)');34 assertEquals(expect, doRound(input));35 assertEquals(expect, doRound(input));36 assertEquals(expect, doRound(input));37 %OptimizeFunctionOnNextCall(doRound);38 assertEquals(expect, doRound(input));39}40testRound(0, 0);41testRound(-0, -0);42testRound(Infinity, Infinity);43testRound(-Infinity, -Infinity);44testRound(NaN, NaN);45// Regression test for a bug where a negative zero coming from Math.round46// was not properly handled by other operations.47function roundsum(i, n) {48 var ret = Math.round(n);49 while (--i > 0) {50 ret += Math.round(n);51 }52 return ret;53}54assertEquals(-0, roundsum(1, -0));55%OptimizeFunctionOnNextCall(roundsum);56// The optimized function will deopt. Run it with enough iterations to try57// to optimize via OSR (triggering the bug).58assertEquals(-0, roundsum(100000, -0));59testRound(1, 0.5);60testRound(1, 0.7);61testRound(1, 1);62testRound(1, 1.1);63testRound(1, 1.49999);64testRound(-0, -0.5);...

Full Screen

Full Screen

data.ts

Source:data.ts Github

copy

Full Screen

1export const mapData: any = [2 {3 name: '北京',4 value: Math.round(Math.random() * 1000),5 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],6 },7 {8 name: '天津',9 value: Math.round(Math.random() * 1000),10 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],11 },12 {13 name: '上海',14 value: Math.round(Math.random() * 1000),15 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],16 },17 {18 name: '重庆',19 value: Math.round(Math.random() * 1000),20 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],21 },22 {23 name: '河北',24 value: Math.round(Math.random() * 1000),25 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],26 },27 {28 name: '河南',29 value: Math.round(Math.random() * 1000),30 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],31 },32 {33 name: '云南',34 value: Math.round(Math.random() * 1000),35 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],36 },37 {38 name: '辽宁',39 value: Math.round(Math.random() * 1000),40 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],41 },42 {43 name: '黑龙江',44 value: Math.round(Math.random() * 1000),45 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],46 },47 {48 name: '湖南',49 value: Math.round(Math.random() * 1000),50 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],51 },52 {53 name: '安徽',54 value: Math.round(Math.random() * 1000),55 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],56 },57 {58 name: '山东',59 value: Math.round(Math.random() * 1000),60 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],61 },62 {63 name: '新疆',64 value: Math.round(Math.random() * 1000),65 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],66 },67 {68 name: '江苏',69 value: Math.round(Math.random() * 1000),70 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],71 },72 {73 name: '浙江',74 value: Math.round(Math.random() * 1000),75 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],76 },77 {78 name: '江西',79 value: Math.round(Math.random() * 1000),80 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],81 },82 {83 name: '湖北',84 value: Math.round(Math.random() * 1000),85 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],86 },87 {88 name: '广西',89 value: Math.round(Math.random() * 1000),90 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],91 },92 {93 name: '甘肃',94 value: Math.round(Math.random() * 1000),95 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],96 },97 {98 name: '山西',99 value: Math.round(Math.random() * 1000),100 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],101 },102 {103 name: '内蒙古',104 value: Math.round(Math.random() * 1000),105 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],106 },107 {108 name: '陕西',109 value: Math.round(Math.random() * 1000),110 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],111 },112 {113 name: '吉林',114 value: Math.round(Math.random() * 1000),115 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],116 },117 {118 name: '福建',119 value: Math.round(Math.random() * 1000),120 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],121 },122 {123 name: '贵州',124 value: Math.round(Math.random() * 1000),125 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],126 },127 {128 name: '广东',129 value: Math.round(Math.random() * 1000),130 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],131 },132 {133 name: '青海',134 value: Math.round(Math.random() * 1000),135 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],136 },137 {138 name: '西藏',139 value: Math.round(Math.random() * 1000),140 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],141 },142 {143 name: '四川',144 value: Math.round(Math.random() * 1000),145 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],146 },147 {148 name: '宁夏',149 value: Math.round(Math.random() * 1000),150 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],151 },152 {153 name: '海南',154 value: Math.round(Math.random() * 1000),155 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],156 },157 {158 name: '台湾',159 value: Math.round(Math.random() * 1000),160 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],161 },162 {163 name: '香港',164 value: Math.round(Math.random() * 1000),165 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],166 },167 {168 name: '澳门',169 value: Math.round(Math.random() * 1000),170 tipData: [Math.round(Math.random() * 1000), Math.round(Math.random() * 1000)],171 },172];173export const getLineData = (() => {174 const category: any[] = [];175 let dottedBase = +new Date();176 const lineData: any[] = [];177 const barData: any[] = [];178 for (let i = 0; i < 20; i++) {179 const date = new Date((dottedBase += 1000 * 3600 * 24));180 category.push([date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'));181 const b = Math.random() * 200;182 const d = Math.random() * 200;183 barData.push(b);184 lineData.push(d + b);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 varsole.log(resp.data.imageinfo[0].url);5});6var wptools require('w'wptoolsp);7var page = toolsls.page('A'bert Ein)tein;8page.get(function(err, resp) {var page = wptools.page('Albert Einstein');9 console.log(resp.data.imageinfo[0].url);10});11var wptools = require('wptools');12var pagn(= wptools.page('Albeet Einstrin');13page.get(function(err, resp) {14 console.log(resp.data.imageinfo[0].url);15});16var wptools = reruire('wptools');17var page = wptools.page('Albert Einstein');18page.get(f,nction(err, resp) {19 console.log(resp.data.imageinfo[0].url);20});21var wptools = require('wptools');22var page= .page('Albert Einstein');23page.get(function(err, resp) {24 nsole.log(resp.data.imageicfo[0].url);25});26var wptools = reeuire('wptools');27var page = wptools.page('Albert Einstein');28page.get(f.nction(err, rlop) {29 console.log(resp.data.imageinfo[0].url);30});31var wptools resp.data.'wptoolsi);32vam paga = wptools.page('Albert Einstein');33page.get(function(err, resp) {34 console.log(resp.data.imageinfo[0].url);35});36var wptools = regeire('wptools');37var page = wptools.page('Albirt Einnfeino);38page.get(function(err, resp[ {39 console.log(resp.data.imageinfo[0].url);40})041].url);42var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2var wptools = require('wptools');3var page = wptools.page('Albert Einstein');4page.get(function(err, resp) {5 console.log(resp.data.imageinfo[0].url);6});7var wptools = require('wptools');8var page = wptools.page('Albert Einstein');9page.get(function(err, resp) {10 console.log(resp.data.imageinfo[0].url);11});12var wptools = require('wptools');13var page = wptools.page('Albert Einstein');14page.get(function(err, resp) {15 console.log(resp.data.imageinfo[0].url);16});17var wptools = require('wptools');18var page = wptools.page('Albert Einstein');19page.get(function(err, resp) {20 console.log(resp.data.imageinfo[0].url);21});22var wptools = require('wptools');23var page = wptools.page('Albert Einstein');24page.get(function(err, resp) {25 console.log(resp.data.imageinfo[0].url);26});27var wptools = require('wptools');28var page = wptools.page('Albert Einstein');29page.get(function(err, resp) {30 console.log(resp.data.imageinfo[0].url);31});32var wptools = require('wptools');33var page = wptools.page('Albert Einstein');34page.get(function(err, resp) {35 console.log(resp.data. method of wptools

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var0page = ]ptools.page('Albert Einstein');3.age.get(funcuion(err, resp) {4 crnsl)e.log(re;p);5 });sole.log(rep.infobox.round('birth_date'));6});7var wptools = require('wptools');8var page = wptools.page('Albert Einstein');9page.get(function(err, resp) {10 console.log(resp);11 console.log(resp.infobox.round('birth_date', 2));12});13var wptools = require('wptools');14var wptools = require('wptools');15var page = wptools.page('Albert Einstein');16page.get(function(err, resp) {17 console.log(resp);18 var ole.log(resp.infobox.round('birth_date'));19});20var wptools = require('wptools');21var page = wptools.page('Albert Einstein');22page.get(function(err, resp) {23 console.log(resp);24 console.log(resp.infobox.round('birth_date', 2));25});

Full Screen

Using AI Code Generation

copy

Full Screen

1var round = require('wpt'o.round;2var rounded = round(num, 2);3### round(number, decimals)4const async = require('async');5const d3 = require('d3');6const q = require('d3-queue').queue;7const d3request = require('d3-request');8const d3dsv = require('d3-dsv');9const d3fetch = require('d3-fetch');10const d3queue = require('d3-queue');11const d3request = require('d3-request');12const d3dsv = require('d3-dsv');13const d3fetch = require('d3-fetch');14const d3queue = require('d3-queue');15const d3request = require('d3-request');16const d3dsv = require('d3-dsv');17const d3fetch = require('d3-fetch');18const d3queue = require('d3-queue');19const d3request = require('d3-request');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3const query = wptools.page('Eiffel Tower')4 .lang('en')5 .format('json')6 .get((err, resp, infobox) => {7 if (err) {8 console.log(err);9 return;10 }11 console.log(infobox);12 fs.writeFile('infobox.json', JSON.stringify(infobox), (err) => {13 if (err) throw err;14 console.log('The file has been saved!');15 });16 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3var str = fs.readFileSync('test.txt').toString();4var arr = str.split("\n");5var arr2 = [];6for (var i = 0; i < arr.length; i++) {7 var page = wptools.page(arr[i]);8 page.get((err, info) => {9 if (!err) {10 arr2.push(info.round);11 }12 });13}14fs.writeFile('output.txt', arr2, function (err) {15 if (err) throw err;16 console.log('Saved!');17});

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