How to use runIteration method in Best

Best JavaScript code snippet using best

Voting.js

Source:Voting.js Github

copy

Full Screen

...93 const notifier = new MockNotifier();94 let votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);95 assert.equal(notifier.notificationsSent, 0);96 // The vote should have been committed.97 let result = await votingSystem.runIteration(USE_PROD_LOGS);98 assert.equal(result.batches, 1);99 assert.equal(result.updates.length, 1);100 assert.equal(result.skipped.length, 0);101 assert.equal(result.failures.length, 0);102 assert.equal(notifier.notificationsSent, 1);103 // Running again should send more emails but not execute any batch commits.104 result = await votingSystem.runIteration(USE_PROD_LOGS);105 assert.equal(result.batches, 0);106 assert.equal(result.updates.length, 0);107 assert.equal(result.skipped.length, 1);108 assert.equal(result.failures.length, 0);109 assert.equal(notifier.notificationsSent, 2);110 // Move to the reveal phase.111 await moveToNextPhase(voting);112 await votingSystem.runSnapshot();113 // Replace the voting system object with a new one so the class can't persist the commit.114 votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);115 // This vote should have been removed from the persistence layer so we don't re-reveal.116 result = await votingSystem.runIteration(USE_PROD_LOGS);117 assert.equal(result.batches, 1);118 assert.equal(result.updates.length, 1);119 assert.equal(notifier.notificationsSent, 3);120 await moveToNextRound(voting);121 // The previous `runIteration()` should have revealed the vote, so the price request should be resolved.122 const hardcodedPrice = TEST_IDENTIFIERS["test"].expectedPrice;123 assert.equal(await voting.getPrice(identifier, time), hardcodedPrice);124 });125 it("reveal with bad data", async function() {126 const identifier = TEST_IDENTIFIERS["test-bad-reveal"].key;127 const time = await voting.getCurrentTime();128 // Request an Oracle price.129 await voting.requestPrice(identifier, time);130 // Move to the round in which voters will vote on the requested price.131 await moveToNextRound(voting);132 const notifier = new MockNotifier();133 let votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);134 assert.equal(notifier.notificationsSent, 0);135 // The vote should have been committed.136 let result = await votingSystem.runIteration(USE_PROD_LOGS);137 assert.equal(result.batches, 1);138 assert.equal(result.updates.length, 1);139 assert.equal(result.skipped.length, 0);140 assert.equal(result.failures.length, 0);141 assert.equal(notifier.notificationsSent, 1);142 // Replace the encrypted vote by committing again with an indecipherable string.143 await voting.commitAndEmitEncryptedVote(identifier, time, web3.utils.randomHex(32), web3.utils.randomHex(64), {144 from: voter145 });146 // Move to the reveal phase.147 await moveToNextPhase(voting);148 await votingSystem.runSnapshot();149 // Replace the voting system object with a new one so the class can't persist the commit.150 votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);151 result = await votingSystem.runIteration(USE_PROD_LOGS);152 assert.equal(result.batches, 0);153 assert.equal(result.updates.length, 0);154 // Test that emails were sent.155 assert.equal(notifier.notificationsSent, 2);156 });157 it("simultaneous and overlapping votes", async function() {158 const identifier1 = TEST_IDENTIFIERS["test-overlapping1"].key;159 const time1 = "1000";160 const identifier2 = TEST_IDENTIFIERS["test-overlapping2"].key;161 const time2 = "1000";162 // Send three overlapping requests such that each parameter overlaps with one other request.163 await voting.requestPrice(identifier1, time1);164 await voting.requestPrice(identifier1, time2);165 await voting.requestPrice(identifier2, time2);166 // Move to the round in which voters will vote on the requested prices.167 await moveToNextRound(voting);168 const notifier = new MockNotifier();169 let votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);170 // The votes should have been committed.171 let result = await votingSystem.runIteration(USE_PROD_LOGS);172 assert.equal(result.batches, 1);173 assert.equal(result.updates.length, 3);174 assert.equal(result.skipped.length, 0);175 assert.equal(result.failures.length, 0);176 // Move to the reveal phase.177 await moveToNextPhase(voting);178 await votingSystem.runSnapshot();179 // Replace the voting system object with a new one so the class can't persist the commits.180 votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);181 // This vote should have been removed from the persistence layer so we don't re-reveal.182 result = await votingSystem.runIteration(USE_PROD_LOGS);183 assert.equal(result.batches, 1);184 assert.equal(result.updates.length, 3);185 await moveToNextRound(voting);186 // The previous `runIteration()` should have revealed the vote, so the price request should be resolved.187 const hardcodedPrice = TEST_IDENTIFIERS["test-overlapping1"].expectedPrice;188 assert.equal(await voting.getPrice(identifier1, time1), hardcodedPrice);189 assert.equal(await voting.getPrice(identifier1, time2), hardcodedPrice);190 assert.equal(await voting.getPrice(identifier2, time2), hardcodedPrice);191 });192 it("Notification on crash", async function() {193 const identifier = TEST_IDENTIFIERS["Custom Index (1)"].key;194 const time = await voting.getCurrentTime();195 // Request an Oracle price.196 await voting.requestPrice(identifier, time);197 const notifier = new MockNotifier();198 const votingSystem = new VotingScript.VotingSystem(voting, voter, [notifier]);199 // Simulate the commit reverting.200 const temp = votingSystem.voting.batchCommit;201 const errorMessage = "ABCDEF";202 votingSystem.voting.batchCommit = () => {203 throw errorMessage;204 };205 await moveToNextRound(voting);206 // Run an iteration, which should crash.207 await votingSystem.runIteration(USE_PROD_LOGS);208 // A notification email should be sent.209 assert.equal(notifier.notificationsSent, 1);210 assert(notifier.lastSubject.startsWith("Fatal error"));211 assert(notifier.lastBody.includes(errorMessage));212 // Restore the commit function and resolve the price request.213 votingSystem.voting.batchCommit = temp;214 await votingSystem.runIteration(USE_PROD_LOGS);215 await moveToNextPhase(voting);216 await votingSystem.runSnapshot();217 await votingSystem.runIteration(USE_PROD_LOGS);218 await moveToNextRound(voting);219 });220 it("Constant price", async function() {221 const identifier = TEST_IDENTIFIERS["Custom Index (1)"].key;222 const time = await voting.getCurrentTime();223 // Request an Oracle price.224 await voting.requestPrice(identifier, time);225 const votingSystem = new VotingScript.VotingSystem(voting, voter, [new MockNotifier()]);226 await moveToNextRound(voting);227 let result = await votingSystem.runIteration(USE_PROD_LOGS);228 assert.equal(result.batches, 1);229 assert.equal(result.updates.length, 1);230 assert.equal(result.skipped.length, 0);231 assert.equal(result.failures.length, 0);232 await moveToNextPhase(voting);233 await votingSystem.runSnapshot();234 result = await votingSystem.runIteration(USE_PROD_LOGS);235 assert.equal(result.batches, 1);236 assert.equal(result.updates.length, 1);237 await moveToNextRound(voting);238 assert.equal(239 (await voting.getPrice(identifier, time)).toString(),240 TEST_IDENTIFIERS["Custom Index (1)"].expectedPrice241 );242 });243 it("Numerator/Denominator", async function() {244 // Add a test identifier245 VotingScript.SUPPORTED_IDENTIFIERS["0.5"] = {246 numerator: {247 dataSource: "Constant",248 value: "1"249 },250 denominator: {251 dataSource: "Constant",252 value: "2"253 }254 };255 const identifier = TEST_IDENTIFIERS["0.5"].key;256 const time = await voting.getCurrentTime();257 // Request an Oracle price.258 await voting.requestPrice(identifier, time);259 const votingSystem = new VotingScript.VotingSystem(voting, voter, [new MockNotifier()]);260 await moveToNextRound(voting);261 let result = await votingSystem.runIteration(USE_PROD_LOGS);262 assert.equal(result.batches, 1);263 assert.equal(result.updates.length, 1);264 assert.equal(result.skipped.length, 0);265 assert.equal(result.failures.length, 0);266 await moveToNextPhase(voting);267 await votingSystem.runSnapshot();268 result = await votingSystem.runIteration(USE_PROD_LOGS);269 assert.equal(result.batches, 1);270 assert.equal(result.updates.length, 1);271 await moveToNextRound(voting);272 assert.equal((await voting.getPrice(identifier, time)).toString(), TEST_IDENTIFIERS["0.5"].expectedPrice);273 });274 it("Only batches up to the maximum number of commits or reveals that can fit in one block", async function() {275 const identifier = TEST_IDENTIFIERS["Custom Index (100)"].key;276 let testTransactions = BATCH_MAX_COMMITS * 2 + 1;277 const time = (await voting.getCurrentTime()).toNumber() - testTransactions;278 // Request Oracle prices.279 for (let i = 0; i < testTransactions; i++) {280 let timeToVote = time + i;281 await voting.requestPrice(identifier, timeToVote.toString());282 }283 // Sanity check.284 assert.isFalse(await voting.hasPrice(identifier, time));285 // Query pending requests to vote on during each phase.286 let pendingVotes = await voting.getPendingRequests();287 assert.equal(pendingVotes.length, 0, "There should be 0 pending requests during pre-commit phase");288 const votingSystem = new VotingScript.VotingSystem(voting, voter, [new MockNotifier()]);289 // Move to commit phase.290 await moveToNextRound(voting);291 pendingVotes = await voting.getPendingRequests();292 assert.equal(293 pendingVotes.length,294 testTransactions,295 `There should be ${testTransactions} pending requests during commit phase`296 );297 let result = await votingSystem.runIteration(USE_PROD_LOGS);298 let batchesExpected = Math.ceil(testTransactions / BATCH_MAX_COMMITS);299 assert.equal(batchesExpected, result.batches);300 assert.equal(result.updates.length, testTransactions);301 assert.equal(result.skipped.length, 0);302 assert.equal(result.failures.length, 0);303 // Move to reveal phase.304 await moveToNextPhase(voting);305 await votingSystem.runSnapshot();306 pendingVotes = await voting.getPendingRequests();307 assert.equal(308 pendingVotes.length,309 testTransactions,310 `There should be ${testTransactions} pending requests during reveal phase`311 );312 result = await votingSystem.runIteration(USE_PROD_LOGS);313 batchesExpected = Math.ceil(testTransactions / BATCH_MAX_REVEALS);314 assert.equal(batchesExpected, result.batches);315 assert.equal(result.updates.length, testTransactions);316 // End voting (commit & reveal) process.317 await moveToNextRound(voting);318 pendingVotes = await voting.getPendingRequests();319 assert.equal(pendingVotes.length, 0, "There should be 0 pending requests during post-reveal phase");320 // Sanity check.321 assert.equal(322 (await voting.getPrice(identifier, time)).toString(),323 TEST_IDENTIFIERS["Custom Index (100)"].expectedPrice324 );325 });326});

Full Screen

Full Screen

testAfterRenderTest.js

Source:testAfterRenderTest.js Github

copy

Full Screen

...15 */16({17 testAfterRenderTopLevel: {18 test: function(component){19 this.runIteration(component, "simple");20 }21 },22 testAfterRenderTopLevelExtended: {23 test: function(component){24 this.runIteration(component, "extended");25 }26 },27 testAfterRenderContainedInHTML: {28 test: function(component){29 this.runIteration(component, "containedInHTML");30 }31 },32 testAfterRenderContainedInHTMLExtended: {33 test: function(component){34 this.runIteration(component, "extendedContainedInHTML");35 }36 },37 testAfterRenderContainedInNestedHTML: {38 test: function(component){39 this.runIteration(component, "containedInNestedHTML");40 }41 },42 testAfterRenderContainedInNestedHTMLExtended: {43 test: function(component){44 this.runIteration(component, "extendedContainedInNestedHTML");45 }46 },47 testAfterRenderContainedInComponent: {48 test: function(component){49 this.runIteration(component, "containedInComponent");50 }51 },52 testAfterRenderContainedInComponentExtended: {53 test: function(component){54 this.runIteration(component, "extendedContainedInComponent");55 }56 },57 testAfterRenderContainedInNestedComponent: {58 test: function(component){59 this.runIteration(component, "containedInNestedComponent");60 }61 },62 testAfterRenderContainedInNestedComponentExtended: {63 test: function(component){64 this.runIteration(component, "extendedContainedInNestedComponent");65 }66 },67 testAfterRenderKitchenSinkA: {68 test: function(component){69 this.runIteration(component, "kitchenSinkA");70 }71 },72 testAfterRenderKitchenSinkAExtended: {73 test: function(component){74 this.runIteration(component, "extendedKitchenSinkA");75 }76 },77 testAfterRenderKitchenSinkB: {78 test: function(component){79 this.runIteration(component, "kitchenSinkB");80 }81 },82 testAfterRenderKitchenSinkBExtended: {83 test: function(component){84 this.runIteration(component, "extendedKitchenSinkB");85 }86 },87 runIteration: function(component, iterationId){88 var div = component.find(iterationId).getElement();89 if (iterationId.substr(0,"extended".length)=="extended")90 aura.test.assertEquals("Extended AfterRender Ran.", div.innerHTML, "After render wasn't chained.");91 else92 aura.test.assertEquals("AfterRender Ran.", div.innerHTML, "After render didn't run.");93 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch');2var path = require('path');3var fs = require('fs');4var input = fs.readFileSync(path.join(__dirname, 'input.txt'), 'utf8');5var inputArray = input.split('\n');6var firstLine = inputArray[0].split(' ');7var n = parseInt(firstLine[0]);8var m = parseInt(firstLine[1]);9var k = parseInt(firstLine[2]);10var grid = [];11for (var i = 1; i <= n; i++) {12 grid.push(inputArray[i].split(''));13}14var start = inputArray[n + 1].split(' ');15var startX = parseInt(start[0]);16var startY = parseInt(start[1]);17var end = inputArray[n + 2].split(' ');18var endX = parseInt(end[0]);19var endY = parseInt(end[1]);20var bestFirstSearch = new BestFirstSearch(grid, n, m);21console.log(bestFirstSearch.runIteration(startX, startY, endX, endY));

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch.js');2var graph = require('./graph.js');3var bestFirstSearch = new BestFirstSearch(graph);4bestFirstSearch.runIteration();5console.log("The best first search path is: ");6console.log(bestFirstSearch.getPath());7console.log("The cost of the best first search path is: ");8console.log(bestFirstSearch.getCost());

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./bestFirstSearch.js');2var bestFirstSearch = new BestFirstSearch();3var test4 = function() {4 var graph = {5 0: {6 },7 1: {8 },9 2: {10 },11 3: {12 },13 4: {14 },15 5: {16 }17 };18 var heuristic = {19 };20 var startNode = 0;21 var goalNode = 5;22 var result = bestFirstSearch.runIteration(graph, heuristic, startNode, goalNode);23 console.log(result);24}25module.exports = test4;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch');2var nodes = require('./nodes');3var graph = require('./graph');4var bestFirstSearch = new BestFirstSearch();5var start = nodes.node1;6var goal = nodes.node4;7var result = bestFirstSearch.runIteration(start, goal, graph);8console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch');2var fs = require('fs');3var test4 = fs.readFileSync('test4.txt', 'utf8');4var test4Array = test4.split('\n');5var start = test4Array[0];6var end = test4Array[1];7var heuristic = test4Array[2];8var graph = test4Array.slice(3);9var bfs = new BestFirstSearch(start, end, heuristic, graph);10bfs.runIteration();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch.js');2var graph = new BestFirstSearch.Graph();3var node0 = new BestFirstSearch.Node(0);4var node1 = new BestFirstSearch.Node(1);5var node2 = new BestFirstSearch.Node(2);6var node3 = new BestFirstSearch.Node(3);7var node4 = new BestFirstSearch.Node(4);8var node5 = new BestFirstSearch.Node(5);9var node6 = new BestFirstSearch.Node(6);10var node7 = new BestFirstSearch.Node(7);11var node8 = new BestFirstSearch.Node(8);12var node9 = new BestFirstSearch.Node(9);13graph.addNode(node0);14graph.addNode(node1);15graph.addNode(node2);16graph.addNode(node3);17graph.addNode(node4);18graph.addNode(node5);19graph.addNode(node6);20graph.addNode(node7);21graph.addNode(node8);22graph.addNode(node9);23graph.addEdge(node0, node1, 4);24graph.addEdge(node0, node7, 8);25graph.addEdge(node1, node2, 8);26graph.addEdge(node1, node7, 11);27graph.addEdge(node2, node3, 7);28graph.addEdge(node2, node8, 2);29graph.addEdge(node2, node5, 4);30graph.addEdge(node3, node4, 9);31graph.addEdge(node3, node5, 14);32graph.addEdge(node4, node5, 10);33graph.addEdge(node5, node6, 2);34graph.addEdge(node6, node7, 1);35graph.addEdge(node6, node8, 6);36graph.addEdge(node7, node8, 7);37var bfs = new BestFirstSearch.BestFirstSearch(graph, node0, node4);38bfs.runIteration();39console.log(bfs.shortestPath());

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestFirstSearch = require('./BestFirstSearch');2];3const startNode = [0, 0];4const endNode = [9, 9];5const bestFirstSearch = new BestFirstSearch(grid, startNode, endNode);6bestFirstSearch.runIteration();7bestFirstSearch.printGrid();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { BestFirstSearch } from "./best-first-search";2import { Graph } from "./graph";3import { Node } from "./node";4import { Edge } from "./edge";5let graph = new Graph();6let A = new Node("A");7let B = new Node("B");8let C = new Node("C");9let D = new Node("D");10let E = new Node("E");11let F = new Node("F");12let G = new Node("G");13let H = new Node("H");14let I = new Node("I");15let J = new Node("J");16let K = new Node("K");17graph.addNode(A);18graph.addNode(B);19graph.addNode(C);20graph.addNode(D);21graph.addNode(E);22graph.addNode(F);23graph.addNode(G);24graph.addNode(H);25graph.addNode(I);26graph.addNode(J);27graph.addNode(K);28let edge1 = new Edge(A, B, 1);29let edge2 = new Edge(A, C, 2);30let edge3 = new Edge(B, D, 3);31let edge4 = new Edge(C, D, 4);32let edge5 = new Edge(D, E, 5);33let edge6 = new Edge(D, F, 6);34let edge7 = new Edge(E, G, 7);35let edge8 = new Edge(F, G, 8);36let edge9 = new Edge(G, H, 9);37let edge10 = new Edge(G, I, 10);38let edge11 = new Edge(H, J, 11);39let edge12 = new Edge(I, J, 12);40graph.addEdge(edge1);41graph.addEdge(edge2);42graph.addEdge(edge3);43graph.addEdge(edge4);44graph.addEdge(edge5);45graph.addEdge(edge6);46graph.addEdge(edge7);47graph.addEdge(edge8);48graph.addEdge(edge9);49graph.addEdge(edge10);50graph.addEdge(edge11);51graph.addEdge(edge12);52let heuristic = new Map();53heuristic.set(A, 0);54heuristic.set(B, 1);55heuristic.set(C, 2);56heuristic.set(D, 3);57heuristic.set(E, 4);58heuristic.set(F

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