Best JavaScript code snippet using wpt
helpers.js
Source:helpers.js
1import {ResourceTypes} from './settlersConstants.js';2const canvas = document.getElementById('table');3const ctx = canvas.getContext('2d');4// a hexagon edge is `r` pixels5const r = 58;6const h = r * Math.sqrt(3)/2;7const canvasHeight = 600;8const instructionsHeight = 50;9const waterBackground = new Image();10waterBackground.src = 'images/water-bg-top-half.jpg';11// pts are relative to this position12const boardWaterWidth = 600;13const boardWaterHeight = canvasHeight - instructionsHeight;14const boardX = (boardWaterWidth - 8*h) / 2; // pixels from left15const boardY = canvasHeight - (boardWaterHeight - 6*r) / 2; // pixels from top16const xFactor = h;17const yFactor = -r;18const ResourceColors = {19 wheat: "#f1e999",20 ore: "lightgray",21 sheep: "lightgreen",22 wood: "forestgreen",23 brick: "#dd7d7d",24 desert: "sandybrown",25}26// these images are all 120 px wide, 177 tall27const cardHeightRatio = 177 / 120;28const cardImages = {29 brick: new Image(),30 wood: new Image(),31 sheep: new Image(),32 wheat: new Image(),33 ore: new Image(),34}35cardImages.brick.src = 'images/brick.jpg';36cardImages.wood.src = 'images/wood.jpg';37cardImages.sheep.src = 'images/sheep.jpg';38cardImages.wheat.src = 'images/wheat.jpg';39cardImages.ore.src = 'images/ore.jpg';40class XyCoord {41 constructor(x, y) {42 // default values assume falseCoords43 this.x = x;44 this.y = y;45 this.trueX = x * xFactor + boardX;46 this.trueY = y * yFactor + boardY;47 }48 static fromTrueCoords(trueX, trueY) {49 const x = (trueX - boardX) / xFactor;50 const y = (trueY - boardY) / yFactor;51 return new XyCoord(x, y);52 }53 snappedToGrid() {54 return new XyCoord(55 Math.round(this.x),56 Math.round(this.y * 2) / 2);57 }58 snappedToMidpointGrid() {59 // nearest multiple of .7560 const y = Math.round(this.y * 4/3) * 3/4;61 // x offsets vary depending on y62 const x = y%1.5 == 0 ? Math.round(this.x) : Math.round(this.x+.5) - .5;63 return new XyCoord(x, y);64 }65 hash() {66 return Math.round(this.trueX)*10000 + Math.round(this.trueY);67 }68 equals(that) {69 return this.x==that.x && this.y==that.y;70 }71 addXY(x, y) {72 return new XyCoord(this.x + x, this.y + y);73 }74 addTrueXY(trueX, trueY) {75 return XyCoord.fromTrueCoords(this.trueX + trueX, this.trueY + trueY);76 }77 isVeryCloseTo(that) {78 const thresholdPx = 15;79 return (this.trueX - that.trueX) ** 280 + (this.trueY - that.trueY) ** 281 <= thresholdPx ** 2;82 }83 static averageCoords(coordList) {84 const n = coordList.length;85 const sumX = coordList.reduce((total, coord) => total+coord.x, 0);86 const sumY = coordList.reduce((total, coord) => total+coord.y, 0);87 return new XyCoord(sumX/n, sumY/n);88 }89}90function getHexVertexes(centerCoord) {91 return [92 centerCoord.addXY(-1, .5),93 centerCoord.addXY( 0, 1),94 centerCoord.addXY( 1, .5),95 centerCoord.addXY( 1, -.5),96 centerCoord.addXY( 0, -1),97 centerCoord.addXY(-1, -.5),98 ];99}100class DrawUtils {101 static drawBackground() {102 ctx.drawImage(waterBackground, 0, instructionsHeight, boardWaterWidth, boardWaterHeight);103 }104 static drawPoint(coord, optRadius, optColor) {105 ctx.beginPath();106 ctx.arc(coord.trueX, coord.trueY, optRadius || r/20, 0, 2*Math.PI, false);107 ctx.strokeStyle = optColor || "black";108 ctx.fillStyle = optColor || "black";109 ctx.fill();110 ctx.stroke();111 }112 // assumes vertexes are not trueCoords113 static drawPolygon(vertexes, color, omitStroke) {114 ctx.beginPath();115 const lastVertext = vertexes[vertexes.length - 1];116 ctx.moveTo(lastVertext.trueX, lastVertext.trueY);117 for (const vertex of vertexes) {118 ctx.lineTo(vertex.trueX, vertex.trueY);119 }120 ctx.strokeStyle = omitStroke ? color : "black";121 ctx.fillStyle = color;122 ctx.fill();123 ctx.stroke();124 }125 static drawHex(centerCoord, resourceType) {126 this.drawPolygon(getHexVertexes(centerCoord), ResourceColors[resourceType]);127 }128 // too annoying?129 static drawCurrentPlayerColorIcon(color) {130 const x = 24;131 const y = 26;132 const s = Date.now()%1000 / 1000;133 const angle = Math.abs(.5 - s) * 2 - .5;134 ctx.save();135 ctx.translate(x, y);136 ctx.rotate(angle);137 this.drawSettlement(XyCoord.fromTrueCoords(0, 0), color);138 ctx.restore();139 }140 static drawSettlement(centerCoord, color) {141 const vertexes = [142 centerCoord.addXY(-.2, -.15),143 centerCoord.addXY(-.2, .1),144 centerCoord.addXY( 0, .25),145 centerCoord.addXY( .2, .1),146 centerCoord.addXY( .2, -.15)147 ];148 this.drawPolygon(vertexes, color);149 }150 static drawCity(centerCoord, color) {151 const vertexes = [152 centerCoord.addXY(-.3, -.15),153 centerCoord.addXY(-.3, .1),154 centerCoord.addXY(-.1, .1),155 centerCoord.addXY( .05, .25),156 centerCoord.addXY( .2, .1),157 centerCoord.addXY( .2, -.15)158 ];159 this.drawPolygon(vertexes, color);160 }161 static drawRoad(coord1, coord2, color) {162 const diffX = coord2.x - coord1.x;163 const diffY = coord2.y - coord1.y;164 const start = coord1.addXY(diffX / 6, diffY / 6);165 const end = coord2.addXY(-diffX / 6, -diffY / 6);166 ctx.beginPath();167 ctx.moveTo(start.trueX, start.trueY);168 ctx.lineTo(end.trueX, end.trueY);169 ctx.lineWidth = 10;170 ctx.strokeStyle = color;171 ctx.stroke();172 // reset so future lines aren't messed up173 ctx.lineWidth = 1;174 }175 static drawNumberTile(centerCoord, number) {176 // white circle for background/contrast177 ctx.beginPath();178 ctx.arc(centerCoord.trueX, centerCoord.trueY, 20, 0, 2*Math.PI, false);179 ctx.strokeStyle = "white";180 ctx.fillStyle = "white";181 ctx.fill();182 ctx.stroke();183 // the number184 ctx.font = "30px Arial";185 ctx.fillStyle = "black";186 ctx.textAlign = "center";187 const numberOffset = [10,12].includes(number) ? 2 : 0; // e.g. "12" has a wider 2 than 1188 ctx.fillText(number, centerCoord.trueX - numberOffset, centerCoord.trueY + 5);189 // the probability dots190 const dotCount = 6 - Math.abs(7-number);191 const radius = 2;192 const distBetween = 3 * radius;193 const maxOffset = (dotCount - 1) * distBetween / 2;194 for (let i=0; i<dotCount; i++) {195 const xOffset = maxOffset - i * distBetween;196 this.drawPoint(centerCoord.addTrueXY(xOffset, 12), radius);197 }198 }199 static drawInstructions(text) {200 ctx.font = "30px Arial";201 if (text.length > 55) ctx.font = "24px Arial";202 if (text.length > 70) ctx.font = "18px Arial";203 ctx.fillStyle = "black";204 ctx.textAlign = "left";205 ctx.fillText(text, 48, 35);206 }207 // takes resources object of {type: count}208 static drawResourceCardImages(resources) {209 if (resources.brick < 0210 || resources.wood < 0211 || resources.sheep < 0212 || resources.wheat < 0213 || resources.ore < 0) {214 console.error('Negative resource counts!!!');215 console.error(resources);216 }217 const list = [];218 for (let i=0; i<resources.brick; i++) {219 list.push(cardImages.brick);220 }221 for (let i=0; i<resources.wood; i++) {222 list.push(cardImages.wood);223 }224 for (let i=0; i<resources.sheep; i++) {225 list.push(cardImages.sheep);226 }227 for (let i=0; i<resources.wheat; i++) {228 list.push(cardImages.wheat);229 }230 for (let i=0; i<resources.ore; i++) {231 list.push(cardImages.ore);232 }233 const startX = 620;234 const startY = 50;235 let cardWidth = 120;236 let dx = 35;237 let dy = 14;238 if (list.length >= 8) {239 cardWidth = 90;240 dx = 25;241 }242 if (list.length >= 14) {243 cardWidth = 60;244 dx = 15;245 }246 for (let i=0; i<list.length; i++) {247 const x = startX + i*dx;248 const y = startY + (i%2)*dy;249 ctx.drawImage(list[i], x, y, cardWidth, cardWidth * cardHeightRatio);250 }251 }252 static drawDevCardImages(unused, used) {253 // unused ones first254 let startX = 620;255 let startY = 250;256 let cardWidth = 120;257 let dx = 124;258 let dy = 0;259 if (unused.length >= 4) {260 dx = 62;261 dy = 30;262 }263 if (unused.length >= 6) {264 cardWidth = 90;265 dx = 90;266 dy = 24;267 }268 for (let i=0; i<unused.length; i++) {269 const x = startX + i*dx;270 const y = startY + (i%2)*dy;271 ctx.drawImage(unused[i].getImage(), x, y, cardWidth, cardWidth * cardHeightRatio);272 }273 // used ones274 startX = 720;275 startY = 450;276 cardWidth = 60;277 dx = cardWidth + 5;278 for (let i=0; i<used.length; i++) {279 const x = startX + i*dx;280 ctx.drawImage(used[i].getImage(), x, startY, cardWidth, cardWidth * cardHeightRatio);281 }282 }283 static drawCardImages(list, startX, startY) {284 let cardWidth = 120;285 let dx = 35;286 let dy = 14;287 if (list.length >= 8) {288 cardWidth = 90;289 dx = 25;290 // dy = 10;291 }292 if (list.length >= 14) {293 cardWidth = 60;294 dx = 15;295 // dy = 6;296 }297 for (let i=0; i<list.length; i++) {298 const x = startX + i*dx;299 const y = startY + (i%2)*dy;300 ctx.drawImage(list[i], x, y, cardWidth, cardWidth * cardHeightRatio);301 }302 }303 static drawVictoryPoints(number) {304 const vertexes = [305 XyCoord.fromTrueCoords(655, 460),306 XyCoord.fromTrueCoords(685, 550),307 XyCoord.fromTrueCoords(610, 490),308 XyCoord.fromTrueCoords(700, 490),309 XyCoord.fromTrueCoords(625, 550),310 ];311 this.drawPolygon(vertexes, "yellow", true);312 // the number313 ctx.font = "30px Arial";314 ctx.fillStyle = "black";315 ctx.textAlign = "center";316 ctx.fillText(number, 655, 518);317 }318}...
actionTrackingMiddleware-flow.test.ts
Source:actionTrackingMiddleware-flow.test.ts
1import {2 actionTrackingMiddleware,3 ActionTrackingResult,4 getSnapshot,5 Model,6 modelAction,7 modelFlow,8 prop,9 SimpleActionContext,10 _async,11 _await,12} from "../../src"13import { autoDispose, delay, testModel } from "../utils"14@testModel("P2")15export class P2 extends Model({16 y: prop(() => 0),17}) {18 private *_addY(n: number) {19 this.y += n / 220 yield* _await(delay(50))21 this.y += n / 222 return this.y23 }24 @modelFlow25 addY = _async(this._addY)26 private *_addY2(n: number) {27 this.y += n / 228 yield* _await(delay(50))29 this.y += n / 230 return this.y31 }32 @modelFlow33 addY2 = _async(this._addY2)34}35@testModel("P")36export class P extends Model({37 p2: prop(() => new P2({})),38 x: prop(() => 0),39}) {40 private *_addX(n: number) {41 this.x += n / 242 const r = yield* _await(delay(50))43 expect(r).toBe(50) // just to see yields return the right result44 this.addXSync(n / 4)45 const r2 = yield* _await(delay(40))46 expect(r2).toBe(40) // just to see yields return the right result47 this.x += n / 448 return this.x49 }50 @modelFlow51 addX = _async(this._addX)52 @modelAction53 addXSync(n: number) {54 this.x += n55 return n56 }57 private *_addXY(n1: number, n2: number) {58 const r = yield* _await(this.addX(n1))59 expect(typeof r).toBe("number")60 yield* _await(delay(50))61 yield* _await(this.p2.addY(n2))62 return n1 + n263 }64 @modelFlow65 addXY = _async(this._addXY)66 private *_throwFlow(n: number) {67 this.x += n68 yield* _await(delay(50))69 throw new Error("flow failed")70 }71 @modelFlow72 throwFlow = _async(this._throwFlow)73}74test("actionTrackingMiddleware - flow", async () => {75 const p = new P({})76 interface Event {77 type: "filter" | "start" | "finish" | "resume" | "suspend"78 result?: ActionTrackingResult79 value?: any80 context: SimpleActionContext81 }82 function eventToString(ev: Event) {83 let str = `${ev.context.actionName} (${ev.type}${ev.result ? " - " + ev.result : ""})`84 let current = ev.context.parentContext85 while (current) {86 str = `${current.actionName} > ${str}`87 current = current.parentContext88 }89 return str90 }91 const events: Event[] = []92 function reset() {93 events.length = 094 }95 const disposer = actionTrackingMiddleware(p, {96 filter(ctx) {97 events.push({98 type: "filter",99 context: ctx,100 })101 return true102 },103 onStart(ctx) {104 events.push({105 type: "start",106 context: ctx,107 })108 if (ctx.actionName === "addY2") {109 return {110 result: ActionTrackingResult.Return,111 value: -1000,112 }113 }114 return undefined115 },116 onResume(ctx) {117 events.push({118 type: "resume",119 context: ctx,120 })121 },122 onSuspend(ctx) {123 events.push({124 type: "suspend",125 context: ctx,126 })127 },128 onFinish(ctx, ret) {129 events.push({130 type: "finish",131 result: ret.result,132 value: ret.value,133 context: ctx,134 })135 if (ctx.actionName === "addXY") {136 return {137 result: ActionTrackingResult.Return,138 value: ret.value + 1000,139 }140 }141 return undefined142 },143 })144 autoDispose(disposer)145 reset()146 const ret = await p.addX(2)147 expect(ret).toBe(2)148 expect(p.x).toBe(2)149 expect(getSnapshot(p).x).toBe(2)150 expect(events.map(eventToString)).toMatchInlineSnapshot(`151 [152 "addX (filter)",153 "addX (start)",154 "addX (resume)",155 "addX (suspend)",156 "addX (resume)",157 "addX (suspend)",158 "addX (resume)",159 "addX > addXSync (filter)",160 "addX > addXSync (start)",161 "addX > addXSync (resume)",162 "addX > addXSync (suspend)",163 "addX > addXSync (finish - return)",164 "addX (suspend)",165 "addX (resume)",166 "addX (suspend)",167 "addX (resume)",168 "addX (suspend)",169 "addX (finish - return)",170 ]171 `)172 expect(events).toMatchSnapshot("addX")173 reset()174 const ret2 = await p.addXY(4, 4)175 expect(ret2).toBe(8 + 1000) // +1000 because of the return value override176 expect(p.x).toBe(6)177 expect(p.p2.y).toBe(4)178 expect(events.map(eventToString)).toMatchInlineSnapshot(`179 [180 "addXY (filter)",181 "addXY (start)",182 "addXY (resume)",183 "addXY (suspend)",184 "addXY (resume)",185 "addXY > addX (filter)",186 "addXY > addX (start)",187 "addXY > addX (resume)",188 "addXY > addX (suspend)",189 "addXY > addX (resume)",190 "addXY > addX (suspend)",191 "addXY (suspend)",192 "addXY (resume)",193 "addXY > addX (resume)",194 "addXY > addX > addXSync (filter)",195 "addXY > addX > addXSync (start)",196 "addXY > addX > addXSync (resume)",197 "addXY > addX > addXSync (suspend)",198 "addXY > addX > addXSync (finish - return)",199 "addXY > addX (suspend)",200 "addXY (suspend)",201 "addXY (resume)",202 "addXY > addX (resume)",203 "addXY > addX (suspend)",204 "addXY (suspend)",205 "addXY (resume)",206 "addXY > addX (resume)",207 "addXY > addX (suspend)",208 "addXY (suspend)",209 "addXY (resume)",210 "addXY > addX (finish - return)",211 "addXY (suspend)",212 "addXY (resume)",213 "addXY (suspend)",214 "addXY (resume)",215 "addXY > addY (filter)",216 "addXY > addY (start)",217 "addXY > addY (resume)",218 "addXY > addY (suspend)",219 "addXY > addY (resume)",220 "addXY > addY (suspend)",221 "addXY (suspend)",222 "addXY (resume)",223 "addXY > addY (resume)",224 "addXY > addY (suspend)",225 "addXY (suspend)",226 "addXY (resume)",227 "addXY > addY (resume)",228 "addXY > addY (suspend)",229 "addXY (suspend)",230 "addXY (resume)",231 "addXY > addY (finish - return)",232 "addXY (suspend)",233 "addXY (resume)",234 "addXY (suspend)",235 "addXY (resume)",236 "addXY (suspend)",237 "addXY (finish - return)",238 ]239 `)240 expect(events).toMatchSnapshot("addXY")241 // check rejection242 reset()243 const oldX = p.x244 try {245 await p.throwFlow(10)246 fail("flow must throw")247 } catch (err: any) {248 expect(err.message).toBe("flow failed")249 } finally {250 expect(p.x).toBe(oldX + 10)251 }252 expect(events.map(eventToString)).toMatchInlineSnapshot(`253 [254 "throwFlow (filter)",255 "throwFlow (start)",256 "throwFlow (resume)",257 "throwFlow (suspend)",258 "throwFlow (resume)",259 "throwFlow (suspend)",260 "throwFlow (resume)",261 "throwFlow (suspend)",262 "throwFlow (resume)",263 "throwFlow (suspend)",264 "throwFlow (finish - throw)",265 ]266 `)267 expect(events).toMatchSnapshot("throwFlow")268 // overriding flow start269 reset()270 const oldY = p.p2.y271 const retOverrideStart = await p.p2.addY2(10)272 await delay(100) // just to make sure the promise didn't change data on its own273 expect(p.p2.y).toBe(oldY)274 expect(retOverrideStart).toBe(-1000)275 expect(events.map(eventToString)).toMatchInlineSnapshot(`276 [277 "addY2 (filter)",278 "addY2 (start)",279 "addY2 (resume)",280 "addY2 (suspend)",281 "addY2 (finish - return)",282 ]283 `)284 expect(events).toMatchSnapshot("overriding flow start")285 // disposing286 reset()287 disposer()288 const ret3 = await p.addXY(5, 6)289 expect(ret3 < 1000).toBeTruthy() // the return value override should be gone by now290 expect(events.map(eventToString)).toMatchInlineSnapshot(`[]`)291 expect(events).toMatchSnapshot("disposing")...
actionTrackingMiddleware-sync.test.ts
Source:actionTrackingMiddleware-sync.test.ts
1import {2 actionTrackingMiddleware,3 ActionTrackingResult,4 idProp,5 Model,6 modelAction,7 modelIdKey,8 prop,9 SimpleActionContext,10} from "../../src"11import { autoDispose, testModel } from "../utils"12@testModel("P2")13export class P2 extends Model({14 [modelIdKey]: idProp,15 y: prop(() => 0),16}) {17 @modelAction18 addY = (n: number) => {19 this.y += n20 return this.y21 }22}23@testModel("P")24export class P extends Model({25 [modelIdKey]: idProp,26 p2: prop(() => new P2({})),27 x: prop(() => 0),28}) {29 @modelAction30 addX(n: number, _unserializable?: any) {31 this.x += n32 return this.x33 }34 @modelAction35 other(..._any: any[]) {}36 @modelAction37 addXY(n1: number, n2: number) {38 this.addX(n1)39 this.p2.addY(n2)40 return n1 + n241 }42 @modelAction43 addXY2(n1: number, n2: number) {44 this.addX(n1)45 this.p2.addY(n2)46 return n1 + n247 }48 @modelAction49 throw(msg: string) {50 throw new Error(msg)51 }52}53test("actionTrackingMiddleware - sync", () => {54 const p1 = new P({})55 const p2 = new P({})56 interface Event {57 type: "filter" | "start" | "finish" | "resume" | "suspend"58 result?: ActionTrackingResult59 value?: any60 context: SimpleActionContext61 }62 function eventToString(ev: Event) {63 let str = `${ev.context.actionName} (${ev.type}${ev.result ? " - " + ev.result : ""})`64 let current = ev.context.parentContext65 while (current) {66 str = `${current.actionName} > ${str}`67 current = current.parentContext68 }69 return str70 }71 const events: Event[] = []72 function reset() {73 events.length = 074 }75 const disposer = actionTrackingMiddleware(p1, {76 filter(ctx) {77 events.push({78 type: "filter",79 context: ctx,80 })81 return true82 },83 onStart(ctx) {84 events.push({85 type: "start",86 context: ctx,87 })88 if (ctx.actionName === "addXY2") {89 return {90 result: ActionTrackingResult.Return,91 value: -1000,92 }93 }94 return undefined95 },96 onResume(ctx) {97 events.push({98 type: "resume",99 context: ctx,100 })101 },102 onSuspend(ctx) {103 events.push({104 type: "suspend",105 context: ctx,106 })107 },108 onFinish(ctx, ret) {109 events.push({110 type: "finish",111 result: ret.result,112 value: ret.value,113 context: ctx,114 })115 if (ctx.actionName === "addXY") {116 return {117 result: ActionTrackingResult.Return,118 value: ret.value + 1000,119 }120 }121 return undefined122 },123 })124 autoDispose(disposer)125 // action on the root126 p1.addX(1)127 p2.addX(1)128 expect(events.map(eventToString)).toMatchInlineSnapshot(`129 [130 "addX (filter)",131 "addX (start)",132 "addX (resume)",133 "addX (suspend)",134 "addX (finish - return)",135 ]136 `)137 expect(events).toMatchSnapshot("action on the root")138 // action on the child139 reset()140 p1.p2.addY(2)141 p2.p2.addY(2)142 expect(events.map(eventToString)).toMatchInlineSnapshot(`143 [144 "addY (filter)",145 "addY (start)",146 "addY (resume)",147 "addY (suspend)",148 "addY (finish - return)",149 ]150 `)151 expect(events).toMatchSnapshot("action on the child")152 // action on the root with sub-action on the child153 reset()154 expect(p1.addXY(3, 4) > 1000).toBeTruthy() // because of the return value override155 expect(p2.addXY(3, 4) < 1000).toBeTruthy()156 expect(events.map(eventToString)).toMatchInlineSnapshot(`157 [158 "addXY (filter)",159 "addXY (start)",160 "addXY (resume)",161 "addXY > addX (filter)",162 "addXY > addX (start)",163 "addXY > addX (resume)",164 "addXY > addX (suspend)",165 "addXY > addX (finish - return)",166 "addXY > addY (filter)",167 "addXY > addY (start)",168 "addXY > addY (resume)",169 "addXY > addY (suspend)",170 "addXY > addY (finish - return)",171 "addXY (suspend)",172 "addXY (finish - return)",173 ]174 `)175 expect(events).toMatchSnapshot("action on the root with sub-action on the child")176 // throwing177 reset()178 expect(() => p1.throw("some error")).toThrow("some error")179 expect(events.map(eventToString)).toMatchInlineSnapshot(`180 [181 "throw (filter)",182 "throw (start)",183 "throw (resume)",184 "throw (suspend)",185 "throw (finish - throw)",186 ]187 `)188 expect(events).toMatchSnapshot("throwing")189 // override action on start190 reset()191 const oldX = p1.x192 expect(p1.addXY2(3, 4) === -1000).toBeTruthy() // because of the override on start193 expect(p2.addXY2(3, 4) > 0).toBeTruthy()194 expect(p1.x).toBe(oldX)195 expect(events.map(eventToString)).toMatchInlineSnapshot(`196 [197 "addXY2 (filter)",198 "addXY2 (start)",199 "addXY2 (resume)",200 "addXY2 (suspend)",201 "addXY2 (finish - return)",202 ]203 `)204 expect(events).toMatchSnapshot("override action on start")205 // disposing206 reset()207 disposer()208 expect(p1.addXY(5, 6) < 1000).toBeTruthy() // the value override should be gone by now209 expect(p2.addXY(5, 6) < 1000).toBeTruthy()210 expect(events.map(eventToString)).toMatchInlineSnapshot(`[]`)211 expect(events).toMatchSnapshot("disposing")...
Using AI Code Generation
1var wpt = require('./wpt');2console.log(wpt.addxy(10,20));3var wpt1 = require('./wpt1');4console.log(wpt1.addxy(10,20));5exports.addxy = function(x,y){6return x+y;7}8module.exports.addxy = function(x,y){9return x+y;10}11var wpt = require('./wpt');12console.log(wpt.addxy(10,20));13module.exports = {14addxy:function(x,y){15return x+y;16}17}
Using AI Code Generation
1var wpt = require('wpt');2wpt.addxy(5, 6);3var wpt = require('wpt');4var result = wpt.addxy(5, 6);5console.log('Result: ' + result);6var wpt = require('wpt');7var result = wpt.addxy(5, 6);8console.log('Result: ' + result);9console.log('Result: ' + result);10var wpt = require('wpt');11var result = wpt.addxy(5, 6);12console.log('Result: ' + result);13console.log('Result: ' + result);14console.log('Result: ' + result);15var wpt = require('wpt');16var result = wpt.addxy(5, 6);17console.log('Result: ' + result);18console.log('Result: ' + result);19console.log('Result: ' + result);20console.log('Result: ' + result);21var wpt = require('wpt');22var result = wpt.addxy(5, 6);23console.log('Result: ' + result);
Using AI Code Generation
1var wpt = require('./wpt');2var result = wpt.addxy(10, 20);3console.log(result);4exports.addxy = function (x, y) {5 return x + y;6};7module.exports = {8 addxy: function (x, y) {9 return x + y;10 }11};12var addxy = function (x, y) {13 return x + y;14};15module.exports = addxy;16module.exports.addxy = function (x, y) {17 return x + y;18};19var addxy = function (x, y) {20 return x + y;21};22module.exports.addxy = addxy;23var addxy = function (x, y) {24 return x + y;25};26module.exports = {27};28var addxy = function (x, y) {29 return x + y;30};31module.exports = {32};33var addxy = function (x, y) {34 return x + y;35};36module.exports = {37};38var addxy = function (x, y) {39 return x + y;40};41module.exports = {42};43var addxy = function (x, y) {44 return x + y;45};46module.exports = {47};48var addxy = function (x, y) {49 return x + y;50};51module.exports = {52};
Using AI Code Generation
1var wpt = require('wpt');2var x = 10;3var y = 20;4var sum = wpt.addxy(x,y);5console.log(sum);6var addxy = function(x,y){7return x+y;8}9module.exports.addxy = addxy;10{11"scripts": {12},13}
Using AI Code Generation
1var wpt = require('wpt');2var x = 10;3var y = 20;4var z = wpt.addxy(x, y);5console.log(z);6var wpt = require('wpt');7var x = 10;8var y = 20;9var z = wpt.addxy(x, y);10console.log(z);11var wpt = require('wpt');12var x = 10;13var y = 20;14var z = wpt.addxy(x, y);15console.log(z);16var wpt = require('wpt');17var x = 10;18var y = 20;19var z = wpt.addxy(x, y);20console.log(z);21var wpt = require('wpt');22var x = 10;23var y = 20;24var z = wpt.addxy(x, y);25console.log(z);26var wpt = require('wpt');27var x = 10;28var y = 20;29var z = wpt.addxy(x, y);30console.log(z);
Using AI Code Generation
1var wpt = require('wpt');2var wptObj = new wpt();3wptObj.addxy(1,2);4var wpt = require('wpt');5var wptObj = new wpt();6wptObj.addxy(1,2);
Using AI Code Generation
1var wptobj = require('./wptobj');2var res = wptobj.addxy(5,6);3console.log(res);4module.exports.addxy = function(x, y) {5 return x + y;6};7exports.addxy = function(x, y) {8 return x + y;9};10exports.addxy = function(x, y) {11 return x + y;12};13var wptobj = require('./wptobj');14console.log(wptobj.addxy(5,6));15var wptobj = require('./wptobj');16var addxy = wptobj.addxy;17console.log(addxy(5,6));18var wptobj = require('./wptobj');19var addxy = wptobj.addxy;20console.log(addxy(5,6));21var wptobj = require('./wptobj');22var addxy = wptobj.addxy;23console.log(addxy(5,6));24var wptobj = require('./wptobj');25var addxy = wptobj.addxy;26console.log(addxy(5,6));27var wptobj = require('./wptobj');28var addxy = wptobj.addxy;29console.log(addxy(5,6));30var wptobj = require('./wptobj');31var addxy = wptobj.addxy;32console.log(addxy(5,6));33var wptobj = require('./wptobj');34var addxy = wptobj.addxy;
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!!