Best JavaScript code snippet using playwright-internal
xstep_with_interp_tests.js
Source:xstep_with_interp_tests.js
1QUnit.module("X step with interpolation tests");2QUnit.test("Linear XY axes", function(assert) {3 // Given linearly aligned axes4 let calib = new wpd.Calibration(2);5 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px6 calib.addPoint(99, 99, "100", "0"); // X2 = 100 at (99, 99)px7 calib.addPoint(0, 99, "0", "0"); // Y1 = 0 at (0, 99)px8 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px9 let xyaxes = new wpd.XYAxes();10 xyaxes.calibrate(calib, false, false);11 // Given autodetection object with some pre-defined data using a function12 let dataFn = function(x) {13 return Math.sin(x) + 2;14 };15 let autodetection = new wpd.AutoDetectionData();16 autodetection.imageHeight = 100;17 autodetection.imageWidth = 100;18 autodetection.binaryData = new Set();19 for (let x = 0; x <= 100; x += 1) { // jump pixels as this algo can interpolate20 let y = dataFn(x);21 let pix = xyaxes.dataToPixel(x, y);22 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);23 autodetection.binaryData.add(img_index);24 }25 // X step w/ Interpolation26 let algo = new wpd.XStepWithInterpolationAlgo();27 algo.setParams({28 xmin: 0,29 delx: 1,30 xmax: 100,31 ymin: 0,32 ymax: 10,33 smoothing: 034 });35 let ds = new wpd.Dataset();36 algo.run(autodetection, ds, xyaxes);37 assert.equal(ds.getCount(), 101, "Simple Linear XY");38 // Apply on just a small window 39 algo.setParams({40 xmin: 10,41 delx: 2,42 xmax: 40,43 ymin: 0,44 ymax: 10,45 smoothing: 046 });47 algo.run(autodetection, ds, xyaxes);48 assert.equal(ds.getCount(), 16, "Simple Linear XY - Bounded with step size");49 // discontinuous sin(x) in a window with custom step size50 autodetection.binaryData = new Set();51 for (let x = 9; x <= 41; x += 2) { // jump pixels as this algo can interpolate, also make sure end point have data52 let y = dataFn(x);53 let pix = xyaxes.dataToPixel(x, y);54 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);55 autodetection.binaryData.add(img_index);56 }57 algo.setParams({58 xmin: 10,59 delx: 2,60 xmax: 40,61 ymin: 0,62 ymax: 10,63 smoothing: 064 });65 algo.run(autodetection, ds, xyaxes);66 assert.equal(ds.getCount(), 16, "Simple Linear XY - Discontinuous sin(x)");67});68QUnit.test("Linear negative XY axes", function(assert) {69 // Given linearly aligned axes70 let calib = new wpd.Calibration(2);71 calib.addPoint(99, 0, "0", "0"); // X1 = 0 at (99,0)px72 calib.addPoint(0, 0, "-100", "0"); // X2 = -100 at (0, 0)px73 calib.addPoint(99, 0, "0", "0"); // Y1 = 0 at (99,0)px74 calib.addPoint(99, 99, "0", "-10"); // Y2 = -10 at (99, 99)px75 let xyaxes = new wpd.XYAxes();76 xyaxes.calibrate(calib, false, false);77 // Given autodetection object with some pre-defined data using a function78 let dataFn = function(x) {79 return Math.sin(x) - 3;80 };81 let autodetection = new wpd.AutoDetectionData();82 autodetection.imageHeight = 100;83 autodetection.imageWidth = 100;84 autodetection.binaryData = new Set();85 for (let x = -100; x <= 0; x += 1) { // jump pixels as this algo can interpolate86 let y = dataFn(x);87 let pix = xyaxes.dataToPixel(x, y);88 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);89 autodetection.binaryData.add(img_index);90 }91 // X step w/ Interpolation92 let algo = new wpd.XStepWithInterpolationAlgo();93 algo.setParams({94 xmin: -100,95 delx: 1,96 xmax: 0,97 ymin: -10,98 ymax: 0,99 smoothing: 0100 });101 let ds = new wpd.Dataset();102 algo.run(autodetection, ds, xyaxes);103 assert.equal(ds.getCount(), 101, "Simple Linear XY");104 // Apply on just a small window 105 algo.setParams({106 xmin: -40,107 delx: 2,108 xmax: -10,109 ymin: -10,110 ymax: 0,111 smoothing: 0112 });113 algo.run(autodetection, ds, xyaxes);114 assert.equal(ds.getCount(), 16, "Simple Linear XY - Bounded with step size");115 // discontinuous sin(x) in a window with custom step size116 autodetection.binaryData = new Set();117 for (let x = -41; x <= -9; x += 2) { // jump pixels as this algo can interpolate, also make sure end point have data118 let y = dataFn(x);119 let pix = xyaxes.dataToPixel(x, y);120 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);121 autodetection.binaryData.add(img_index);122 }123 algo.setParams({124 xmin: -40,125 delx: 2,126 xmax: -10,127 ymin: -10,128 ymax: 0,129 smoothing: 0130 });131 algo.run(autodetection, ds, xyaxes);132 assert.equal(ds.getCount(), 16, "Simple Linear XY - Discontinuous sin(x)");133});134// log scale135QUnit.test("Log scale in X direction", function(assert) {136 // Given linearly aligned axes137 let calib = new wpd.Calibration(2);138 calib.addPoint(0, 99, "1e-5", "0"); // X1 = 1e-5 at (0, 99)px139 calib.addPoint(99, 99, "10", "0"); // X2 = 10 at (99, 99)px140 calib.addPoint(0, 99, "0", "0"); // Y1 = 0 at (0, 99)px141 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px142 let xyaxes = new wpd.XYAxes();143 xyaxes.calibrate(calib, true, false);144 // Given autodetection object with some pre-defined data using a function145 let dataFn = function(x) {146 return 5;147 };148 let autodetection = new wpd.AutoDetectionData();149 autodetection.imageHeight = 100;150 autodetection.imageWidth = 100;151 autodetection.binaryData = new Set();152 for (let x = 1e-5; x <= 10; x *= 10) { // jump pixels as this algo can interpolate153 let y = dataFn(x);154 let pix = xyaxes.dataToPixel(x, y);155 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);156 autodetection.binaryData.add(img_index);157 }158 // X step w/ Interpolation159 let algo = new wpd.XStepWithInterpolationAlgo();160 algo.setParams({161 xmin: 1e-5,162 delx: 10,163 xmax: 10,164 ymin: 0,165 ymax: 10,166 smoothing: 0167 });168 let ds = new wpd.Dataset();169 algo.run(autodetection, ds, xyaxes);170 assert.equal(ds.getCount(), 7, "Simple log scale in X direction");171});172// log scale173QUnit.test("Log scale in negative X direction", function(assert) {174 // Given linearly aligned axes175 let calib = new wpd.Calibration(2);176 calib.addPoint(0, 99, "-1e-5", "0"); // X1 = 1e-5 at (0, 99)px177 calib.addPoint(99, 99, "-10", "0"); // X2 = 10 at (99, 99)px178 calib.addPoint(0, 99, "0", "0"); // Y1 = 0 at (0, 99)px179 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px180 let xyaxes = new wpd.XYAxes();181 xyaxes.calibrate(calib, true, false);182 // Given autodetection object with some pre-defined data using a function183 let dataFn = function(x) {184 return 5;185 };186 let autodetection = new wpd.AutoDetectionData();187 autodetection.imageHeight = 100;188 autodetection.imageWidth = 100;189 autodetection.binaryData = new Set();190 for (let x = -1e-5; x >= -10; x *= 10) { // jump pixels as this algo can interpolate191 let y = dataFn(x);192 let pix = xyaxes.dataToPixel(x, y);193 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);194 autodetection.binaryData.add(img_index);195 }196 // X step w/ Interpolation197 let algo = new wpd.XStepWithInterpolationAlgo();198 algo.setParams({199 xmin: -10,200 delx: -10,201 xmax: -1e-5,202 ymin: 0,203 ymax: 10,204 smoothing: 0205 });206 let ds = new wpd.Dataset();207 algo.run(autodetection, ds, xyaxes);208 assert.equal(ds.getCount(), 4, "Simple log scale in negative X direction");209});210QUnit.test("Log scale in Y direction", function(assert) {211 // Given linearly aligned axes212 let calib = new wpd.Calibration(2);213 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px214 calib.addPoint(99, 99, "100", "0"); // X2 = 100 at (99, 99)px215 calib.addPoint(0, 99, "0", "1e-5"); // Y1 = 1e-5 at (0, 99)px216 calib.addPoint(0, 0, "0", "1000"); // Y2 = 1000 at (0, 0)px217 let xyaxes = new wpd.XYAxes();218 xyaxes.calibrate(calib, false, true);219 // Given autodetection object with some pre-defined data using a function220 let dataFn = function(x) {221 return Math.pow(10, 2 * Math.sin(x));222 };223 let autodetection = new wpd.AutoDetectionData();224 autodetection.imageHeight = 100;225 autodetection.imageWidth = 100;226 autodetection.binaryData = new Set();227 for (let x = 0; x <= 100; x += 1) { // jump pixels as this algo can interpolate228 let y = dataFn(x);229 let pix = xyaxes.dataToPixel(x, y);230 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);231 autodetection.binaryData.add(img_index);232 }233 // X step w/ Interpolation234 let algo = new wpd.XStepWithInterpolationAlgo();235 algo.setParams({236 xmin: 0,237 delx: 1,238 xmax: 100,239 ymin: 1e-5,240 ymax: 1000,241 smoothing: 0242 });243 let ds = new wpd.Dataset();244 algo.run(autodetection, ds, xyaxes);245 assert.equal(ds.getCount(), 101, "Simple log scale in Y direction");246});247QUnit.test("Log scale in negative Y direction", function(assert) {248 // Given linearly aligned axes249 let calib = new wpd.Calibration(2);250 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px251 calib.addPoint(99, 99, "100", "0"); // X2 = 100 at (99, 99)px252 calib.addPoint(0, 99, "0", "-1e-5"); // Y1 = -1e-5 at (0, 99)px253 calib.addPoint(0, 0, "0", "-1000"); // Y2 = -1000 at (0, 0)px254 let xyaxes = new wpd.XYAxes();255 xyaxes.calibrate(calib, false, true);256 // Given autodetection object with some pre-defined data using a function257 let dataFn = function(x) {258 return -Math.pow(10, 2 * Math.sin(x));259 };260 let autodetection = new wpd.AutoDetectionData();261 autodetection.imageHeight = 100;262 autodetection.imageWidth = 100;263 autodetection.binaryData = new Set();264 for (let x = 0; x <= 100; x += 1) { // jump pixels as this algo can interpolate265 let y = dataFn(x);266 let pix = xyaxes.dataToPixel(x, y);267 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);268 autodetection.binaryData.add(img_index);269 }270 // X step w/ Interpolation271 let algo = new wpd.XStepWithInterpolationAlgo();272 algo.setParams({273 xmin: 0,274 delx: 1,275 xmax: 100,276 ymin: -1000,277 ymax: -1e-5,278 smoothing: 0279 });280 let ds = new wpd.Dataset();281 algo.run(autodetection, ds, xyaxes);282 assert.equal(ds.getCount(), 101, "Simple log scale in negative Y direction");283});284QUnit.test("Log scale in Y direction, base 2", function(assert) {285 // Given linearly aligned axes286 let calib = new wpd.Calibration(2);287 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px288 calib.addPoint(99, 99, "100", "0"); // X2 = 100 at (99, 99)px289 calib.addPoint(0, 99, "0", Math.pow(2, -5).toString()); // Y1 = 2^-5 at (0, 99)px290 calib.addPoint(0, 0, "0", Math.pow(2, 3).toString()); // Y2 = 2^3 at (0, 0)px291 let xyaxes = new wpd.XYAxes();292 xyaxes.calibrate(calib, false, true);293 // Given autodetection object with some pre-defined data using a function294 let dataFn = function(x) {295 return Math.pow(2, 2 * Math.sin(x));296 };297 let autodetection = new wpd.AutoDetectionData();298 autodetection.imageHeight = 100;299 autodetection.imageWidth = 100;300 autodetection.binaryData = new Set();301 for (let x = 0; x <= 100; x += 1) { // jump pixels as this algo can interpolate302 let y = dataFn(x);303 let pix = xyaxes.dataToPixel(x, y);304 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);305 autodetection.binaryData.add(img_index);306 }307 // X step w/ Interpolation308 let algo = new wpd.XStepWithInterpolationAlgo();309 algo.setParams({310 xmin: 0,311 delx: 1,312 xmax: 100,313 ymin: Math.pow(2, -5),314 ymax: Math.pow(2, 3),315 smoothing: 0316 });317 let ds = new wpd.Dataset();318 algo.run(autodetection, ds, xyaxes);319 assert.equal(ds.getCount(), 101, "Simple log scale in Y direction");320 let totError = 0;321 for (let pi = 0; pi < ds.getCount(); pi++) {322 let px = ds.getPixel(pi);323 let data = xyaxes.pixelToData(px.x, px.y);324 totError += Math.abs(dataFn(data[0]) - data[1]);325 }326 totError /= ds.getCount();327 assert.ok(totError < 1, "total error less than 1")...
custom_independents_tests.js
Source:custom_independents_tests.js
1QUnit.module("Custom independents tests");2QUnit.test("Linear XY axes", function(assert) {3 // Given linearly aligned axes4 let calib = new wpd.Calibration(2);5 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px6 calib.addPoint(99, 99, "100", "0"); // X2 = 100 at (99, 99)px7 calib.addPoint(0, 99, "0", "0"); // Y1 = 0 at (0, 99)px8 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px9 let xyaxes = new wpd.XYAxes();10 xyaxes.calibrate(calib, false, false);11 // Given autodetection object with some pre-defined data using a function12 let dataFn = function(x) {13 return Math.sin(x) + 2;14 };15 let autodetection = new wpd.AutoDetectionData();16 autodetection.imageHeight = 100;17 autodetection.imageWidth = 100;18 autodetection.binaryData = new Set();19 for (let x = 0; x <= 100; x += 1) { // jump pixels as this algo can interpolate20 let y = dataFn(x);21 let pix = xyaxes.dataToPixel(x, y);22 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);23 autodetection.binaryData.add(img_index);24 }25 let algo = new wpd.CustomIndependents();26 algo.setParams({27 xvals: "[1, 10, 20]",28 ymin: 0,29 ymax: 10,30 curveWidth: 2,31 smoothing: 0,32 });33 let ds = new wpd.Dataset();34 algo.run(autodetection, ds, xyaxes);35 assert.equal(ds.getCount(), 3, "Simple linear XY");36 let totError = 0;37 for (let pi = 0; pi < ds.getCount(); pi++) {38 let px = ds.getPixel(pi);39 let data = xyaxes.pixelToData(px.x, px.y);40 totError += Math.abs(dataFn(data[0]) - data[1]);41 }42 totError /= ds.getCount();43 assert.ok(totError < 0.3, "Total error");44});45QUnit.test("Linear negative axes", function(assert) {46 // Given linearly aligned axes47 let calib = new wpd.Calibration(2);48 calib.addPoint(99, 0, "0", "0"); // X1 = 0 at (99,0)px49 calib.addPoint(0, 0, "-100", "0"); // X2 = -100 at (0, 0)px50 calib.addPoint(99, 0, "0", "0"); // Y1 = 0 at (99,0)px51 calib.addPoint(99, 99, "0", "-10"); // Y2 = -10 at (99, 99)px52 let xyaxes = new wpd.XYAxes();53 xyaxes.calibrate(calib, false, false);54 // Given autodetection object with some pre-defined data using a function55 let dataFn = function(x) {56 return Math.sin(x) - 3;57 };58 let autodetection = new wpd.AutoDetectionData();59 autodetection.imageHeight = 100;60 autodetection.imageWidth = 100;61 autodetection.binaryData = new Set();62 for (let x = -100; x <= 0; x += 1) { // jump pixels as this algo can interpolate63 let y = dataFn(x);64 let pix = xyaxes.dataToPixel(x, y);65 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);66 autodetection.binaryData.add(img_index);67 }68 let algo = new wpd.CustomIndependents();69 algo.setParams({70 xvals: "[-1, -10, -20]",71 ymin: -10,72 ymax: 0,73 curveWidth: 2,74 smoothing: 0,75 });76 let ds = new wpd.Dataset();77 algo.run(autodetection, ds, xyaxes);78 assert.equal(ds.getCount(), 3, "Negative linear XY");79 let totError = 0;80 for (let pi = 0; pi < ds.getCount(); pi++) {81 let px = ds.getPixel(pi);82 let data = xyaxes.pixelToData(px.x, px.y);83 totError += Math.abs(dataFn(data[0]) - data[1]);84 }85 totError /= ds.getCount();86 assert.ok(totError < 0.3, "Total error less than 0.3");87});88QUnit.test("Log scale X axes", function(assert) {89 // Given linearly aligned axes90 let calib = new wpd.Calibration(2);91 calib.addPoint(0, 99, "1e-5", "0"); // X1 = 1e-5 at (0, 99)px92 calib.addPoint(99, 99, "10", "0"); // X2 = 10 at (99, 99)px93 calib.addPoint(0, 99, "0", "0"); // Y1 = 0 at (0, 99)px94 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px95 let xyaxes = new wpd.XYAxes();96 xyaxes.calibrate(calib, true, false);97 // Given autodetection object with some pre-defined data using a function98 let dataFn = function(x) {99 return 5;100 };101 let autodetection = new wpd.AutoDetectionData();102 autodetection.imageHeight = 100;103 autodetection.imageWidth = 100;104 autodetection.binaryData = new Set();105 for (let x = 1e-5; x <= 10; x *= 10) { // jump pixels as this algo can interpolate106 let y = dataFn(x);107 let pix = xyaxes.dataToPixel(x, y);108 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);109 autodetection.binaryData.add(img_index);110 }111 let algo = new wpd.CustomIndependents();112 algo.setParams({113 xvals: "[1e-5, 1e-4, 1e-2]",114 ymin: 0,115 ymax: 10,116 curveWidth: 2,117 smoothing: 0,118 });119 let ds = new wpd.Dataset();120 algo.run(autodetection, ds, xyaxes);121 assert.equal(ds.getCount(), 3, "log scale X axes");122 let totError = 0;123 for (let pi = 0; pi < ds.getCount(); pi++) {124 let px = ds.getPixel(pi);125 let data = xyaxes.pixelToData(px.x, px.y);126 totError += Math.abs(dataFn(data[0]) - data[1]);127 }128 totError /= ds.getCount();129 assert.ok(totError < 0.1, "Total error less than 0.1");130});131QUnit.test("Log scale X axes negative", function(assert) {132 // Given linearly aligned axes133 let calib = new wpd.Calibration(2);134 calib.addPoint(0, 99, "-1e-5", "0"); // X1 = 1e-5 at (0, 99)px135 calib.addPoint(99, 99, "-10", "0"); // X2 = 10 at (99, 99)px136 calib.addPoint(0, 99, "0", "0"); // Y1 = 0 at (0, 99)px137 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px138 let xyaxes = new wpd.XYAxes();139 xyaxes.calibrate(calib, true, false);140 // Given autodetection object with some pre-defined data using a function141 let dataFn = function(x) {142 return 5;143 };144 let autodetection = new wpd.AutoDetectionData();145 autodetection.imageHeight = 100;146 autodetection.imageWidth = 100;147 autodetection.binaryData = new Set();148 for (let x = -1e-5; x >= -10; x *= 10) { // jump pixels as this algo can interpolate149 let y = dataFn(x);150 let pix = xyaxes.dataToPixel(x, y);151 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);152 autodetection.binaryData.add(img_index);153 }154 let algo = new wpd.CustomIndependents();155 algo.setParams({156 xvals: "[-1e-5, -1e-4, -1e-2]",157 ymin: 0,158 ymax: 10,159 curveWidth: 2,160 smoothing: 0,161 });162 let ds = new wpd.Dataset();163 algo.run(autodetection, ds, xyaxes);164 assert.equal(ds.getCount(), 3, "log scale X axes negative");165 let totError = 0;166 for (let pi = 0; pi < ds.getCount(); pi++) {167 let px = ds.getPixel(pi);168 let data = xyaxes.pixelToData(px.x, px.y);169 totError += Math.abs(dataFn(data[0]) - data[1]);170 }171 totError /= ds.getCount();172 assert.ok(totError < 0.1, "Total error less than 0.1");173});174QUnit.test("Log scale Y axes", function(assert) {175 // Given linearly aligned axes176 let calib = new wpd.Calibration(2);177 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px178 calib.addPoint(99, 99, "10", "0"); // X2 = 10 at (99, 99)px179 calib.addPoint(0, 99, "0", "1e-5"); // Y1 = 1e-5 at (0, 99)px180 calib.addPoint(0, 0, "0", "10"); // Y2 = 10 at (0, 0)px181 let xyaxes = new wpd.XYAxes();182 xyaxes.calibrate(calib, false, true);183 // Given autodetection object with some pre-defined data using a function184 let dataFn = function(x) {185 return 5;186 };187 let autodetection = new wpd.AutoDetectionData();188 autodetection.imageHeight = 100;189 autodetection.imageWidth = 100;190 autodetection.binaryData = new Set();191 for (let x = 0; x <= 10; x += 0.01) {192 let y = dataFn(x);193 let pix = xyaxes.dataToPixel(x, y);194 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);195 autodetection.binaryData.add(img_index);196 }197 let algo = new wpd.CustomIndependents();198 algo.setParams({199 xvals: "[1, 5, 8]",200 ymin: 1e-5,201 ymax: 10,202 curveWidth: 2,203 smoothing: 0,204 });205 let ds = new wpd.Dataset();206 algo.run(autodetection, ds, xyaxes);207 assert.equal(ds.getCount(), 3, "log scale Y axes");208 let totError = 0;209 for (let pi = 0; pi < ds.getCount(); pi++) {210 let px = ds.getPixel(pi);211 let data = xyaxes.pixelToData(px.x, px.y);212 totError += Math.abs(dataFn(data[0]) - data[1]);213 }214 totError /= ds.getCount();215 assert.ok(totError < 1, "Total error less than 1");216});217QUnit.test("Log scale Y axes negative", function(assert) {218 // Given linearly aligned axes219 let calib = new wpd.Calibration(2);220 calib.addPoint(0, 99, "0", "0"); // X1 = 0 at (0, 99)px221 calib.addPoint(99, 99, "10", "0"); // X2 = 10 at (99, 99)px222 calib.addPoint(0, 99, "0", "-1e-5"); // Y1 = -1e-5 at (0, 99)px223 calib.addPoint(0, 0, "0", "-10"); // Y2 = -10 at (0, 0)px224 let xyaxes = new wpd.XYAxes();225 xyaxes.calibrate(calib, false, true);226 // Given autodetection object with some pre-defined data using a function227 let dataFn = function(x) {228 return -5;229 };230 let autodetection = new wpd.AutoDetectionData();231 autodetection.imageHeight = 100;232 autodetection.imageWidth = 100;233 autodetection.binaryData = new Set();234 for (let x = 0; x <= 10; x += 0.01) {235 let y = dataFn(x);236 let pix = xyaxes.dataToPixel(x, y);237 let img_index = parseInt(pix.y, 10) * 100 + parseInt(pix.x, 10);238 autodetection.binaryData.add(img_index);239 }240 let algo = new wpd.CustomIndependents();241 algo.setParams({242 xvals: "[1, 5, 8]",243 ymin: -10,244 ymax: -1e-5,245 curveWidth: 2,246 smoothing: 0,247 });248 let ds = new wpd.Dataset();249 algo.run(autodetection, ds, xyaxes);250 assert.equal(ds.getCount(), 3, "log scale Y axes");251 let totError = 0;252 for (let pi = 0; pi < ds.getCount(); pi++) {253 let px = ds.getPixel(pi);254 let data = xyaxes.pixelToData(px.x, px.y);255 totError += Math.abs(dataFn(data[0]) - data[1]);256 }257 totError /= ds.getCount();258 assert.ok(totError < 1, "Total error less than 1");259});260QUnit.test("Dates axes", function(assert) {261 // dates are not supported right now!262 assert.ok(true);...
ManageAutodetection.jsx
Source:ManageAutodetection.jsx
1import React, { Fragment, useState } from "react";2import APIManager from "../Managers/APIManager";3import { useDispatch, useSelector } from "react-redux";4import { makeStyles } from "@material-ui/core";5import { Delete as DeleteIcon } from "@material-ui/icons";6import { Formik, Form, Field } from "formik";7import { TextField, SimpleFileUpload } from "formik-material-ui";8import {9 Dialog,10 DialogTitle,11 DialogContent,12 DialogActions,13 Button,14 LinearProgress,15 Divider,16 Table,17 TableHead,18 TableRow,19 TableCell,20 TableBody,21 IconButton,22 Typography,23 Paper,24} from "@material-ui/core";25import settings from "../settings";26import addHotFile from "../redux/actionCreators/addHotFile";27import Link from "./Link";28import { autodetectionMessagesSelector } from "../redux/autodetection/autodetection.selector";29import {30 deleteAutodetection,31 fetchAutodetections,32} from "../redux/autodetection/autodetection.thunk";33import { addAutodetection } from "../redux/autodetection/autodetection.actions";34import { enqueueSnackbar } from "../redux/actionCreators/notify";35const useStyles = makeStyles({36 btnGroup: {},37 filesContainer: {38 // display: 'flex',39 // flexDirection: 'column',40 // justifyContent: 'center'41 },42 dropzone: {43 padding: 20,44 marginTop: 10,45 minHeight: 75,46 backgroundColor: "#fefefe",47 cursor: "pointer",48 },49 uploadedFiles: {50 backgroundColor: "#fefefe",51 padding: 20,52 },53 form: {54 padding: 20,55 backgroundColor: "#fefefe",56 textAlign: "center",57 },58});59export const ManageAutodetection = () => {60 const dispatch = useDispatch();61 const classes = useStyles();62 const [open, setOpen] = useState(false);63 const autodetectionMessages = useSelector(autodetectionMessagesSelector);64 const handleDelete = (id) => {65 dispatch(deleteAutodetection(id));66 };67 const handleValidate = (values) => {68 const errors = {};69 if (!values.keywords) {70 errors.keywords = "Keywords are required";71 }72 if (!values.shortname) {73 errors.shortname = "Name is required";74 } else if (values.shortname.length > 25) {75 errors.shortname = "Name should be less than 25 characters";76 }77 if (!values.text && !values.file) {78 errors.text = "Either select a file or enter a message.";79 errors.file = "Either select a file or enter a message.";80 }81 return errors;82 };83 const handleSubmit = (values, { setSubmitting }) => {84 console.log(values);85 APIManager.createAutodetection(values).then((response) => {86 setSubmitting(false);87 console.log(response);88 if (response && response.status == "success") {89 dispatch(fetchAutodetections());90 dispatch(91 enqueueSnackbar({92 message: "Saved",93 options: {94 key: new Date().getTime() + Math.random(),95 variant: "success",96 },97 })98 );99 }100 });101 };102 return (103 <Fragment>104 <Button105 variant="contained"106 onClick={() => {107 setOpen(true);108 }}109 >110 Autodetection Messages111 </Button>112 <Dialog113 fullWidth={true}114 maxWidth="md"115 onClose={() => {116 setOpen(false);117 }}118 open={open}119 >120 <DialogTitle>Add/Remove Autodetection Messages</DialogTitle>121 <DialogContent>122 <Typography varaint="body1">123 Send Files and Messages when the caller speaks the keywords124 </Typography>125 <If condition={autodetectionMessages.length}>126 <Divider />127 <Paper className={classes.uploadedFiles}>128 <Typography variant="h6">Autodetection Messages</Typography>129 <Table size="small" className="filesContainer">130 <TableHead>131 <TableRow>132 <TableCell>Name</TableCell>133 <TableCell>Keywords</TableCell>134 <TableCell>File</TableCell>135 <TableCell>Message</TableCell>136 <TableCell>Actions</TableCell>137 </TableRow>138 </TableHead>139 <TableBody>140 {autodetectionMessages.map((message, index) => (141 <TableRow key={index}>142 <TableCell>{message.shortname}</TableCell>143 <TableCell>{message.keywords}</TableCell>144 <TableCell>145 <Link146 href={147 message.filename148 ? `${settings.base_url}/uploads/mms/${encodeURI(149 message.filename150 )}`151 : ""152 }153 >154 {message.filename}155 </Link>156 </TableCell>157 <TableCell>{message.text}</TableCell>158 <TableCell>159 <IconButton160 onClick={() => {161 handleDelete(message.id, index);162 }}163 variant="contained"164 color="primary"165 size="small"166 >167 <DeleteIcon />168 </IconButton>169 </TableCell>170 </TableRow>171 ))}172 </TableBody>173 </Table>174 </Paper>175 </If>176 <br />177 <Divider />178 <br />179 <Paper className={classes.form}>180 <Typography variant="h6">Add Autodetection Message</Typography>181 <Formik182 initialValues={{183 text: "",184 shortname: "",185 }}186 validate={handleValidate}187 onSubmit={handleSubmit}188 >189 {({ submitForm, isSubmitting }) => (190 <Form>191 <Field192 component={TextField}193 name="shortname"194 fullWidth195 type="text"196 label="Name"197 />198 <br />199 <Field200 component={TextField}201 name="keywords"202 fullWidth203 type="text"204 label="Keywords"205 />206 <Typography variant="caption">207 Seperate keywords by comma <b>,</b>208 </Typography>209 <br />210 <Field211 component={TextField}212 type="text"213 multiline214 fullWidth215 rows={3}216 label="Message"217 name="text"218 />219 <Field220 component={SimpleFileUpload}221 label="File"222 name="file"223 fullWidth224 />225 {isSubmitting && <LinearProgress />}226 <br />227 <Button228 variant="contained"229 color="primary"230 disabled={isSubmitting}231 onClick={submitForm}232 >233 Save234 </Button>235 </Form>236 )}237 </Formik>238 </Paper>239 </DialogContent>240 <DialogActions>241 <Button242 onClick={() => {243 setOpen(false);244 }}245 >246 Close247 </Button>248 </DialogActions>249 </Dialog>250 </Fragment>251 );...
bar_extraction_tests.js
Source:bar_extraction_tests.js
1QUnit.module("Bar extraction algorithm tests");2QUnit.test("Linear axis, vertical", function(assert) {3 // calibrate bar axes4 let calib = new wpd.Calibration(2);5 calib.addPoint(0, 89, "0", "0"); // P16 calib.addPoint(0, 0, "0", "20"); // P27 let barAxes = new wpd.BarAxes();8 barAxes.calibrate(calib, false, false);9 let orientation = barAxes.getOrientation();10 assert.equal(orientation.axes, "Y", "Orientation axes");11 assert.equal(orientation.direction, "increasing", "Orientation direction");12 assert.equal(orientation.angle, 90, "Orientation angle");13 // create dummy data14 let autodetection = new wpd.AutoDetectionData();15 autodetection.imageHeight = 100;16 autodetection.imageWidth = 100;17 autodetection.binaryData = new Set();18 // three bars, two positive, one negative19 for (let x = 10; x < 20; x++) {20 for (let y = 89; y >= 12; y--) {21 let index = y * 100 + x;22 autodetection.binaryData.add(index);23 }24 }25 for (let x = 30; x < 50; x++) {26 for (let y = 97; y >= 88; y--) {27 let index = y * 100 + x;28 autodetection.binaryData.add(index);29 }30 }31 for (let x = 60; x < 80; x++) {32 for (let y = 79; y >= 20; y--) {33 let index = y * 100 + x;34 autodetection.binaryData.add(index);35 }36 }37 let algo = new wpd.BarExtractionAlgo();38 algo.setParams({39 delX: 20,40 delVal: 141 });42 let ds = new wpd.Dataset();43 algo.run(autodetection, ds, barAxes);44 assert.equal(ds.getCount(), 3, "Dataset size");45 let pt1 = ds.getPixel(0);46 assert.equal(pt1.metadata["label"], "Bar0", "pt1 label");47 assert.equal(pt1.x, 15, "pt1 x");48 assert.equal(pt1.y, 12.5, "pt1 y");49 let pt2 = ds.getPixel(1);50 assert.equal(pt2.metadata["label"], "Bar1", "pt2 label");51 assert.equal(pt2.x, 40, "pt2 x");52 assert.equal(pt2.y, 97.5, "pt2 y");53 let pt3 = ds.getPixel(2);54 assert.equal(pt3.metadata["label"], "Bar2", "pt3 label");55 assert.equal(pt3.x, 70, "pt3 x");56 assert.equal(pt3.y, 20.5, "pt3 y");57});58QUnit.test("Linear axis, horizontal", function(assert) {59 // calibrate bar axes60 let calib = new wpd.Calibration(2);61 calib.addPoint(10, 5, "0", "0"); // P162 calib.addPoint(99, 5, "0", "20"); // P263 let barAxes = new wpd.BarAxes();64 barAxes.calibrate(calib, false, false);65 let orientation = barAxes.getOrientation();66 assert.equal(orientation.axes, "X", "Orientation axes");67 assert.equal(orientation.direction, "increasing", "Orientation direction");68 assert.equal(orientation.angle, 0, "Orientation angle");69 // create dummy data70 let autodetection = new wpd.AutoDetectionData();71 autodetection.imageHeight = 100;72 autodetection.imageWidth = 100;73 autodetection.binaryData = new Set();74 // two bars, one positive, one negative75 for (let y = 10; y < 20; y++) {76 for (let x = 5; x <= 12; x++) {77 let index = y * 100 + x;78 autodetection.binaryData.add(index);79 }80 }81 for (let y = 30; y < 50; y++) {82 for (let x = 11; x <= 56; x++) {83 let index = y * 100 + x;84 autodetection.binaryData.add(index);85 }86 }87 let algo = new wpd.BarExtractionAlgo();88 algo.setParams({89 delX: 20,90 delVal: 191 });92 let ds = new wpd.Dataset();93 algo.run(autodetection, ds, barAxes);94 assert.equal(ds.getCount(), 2, "Dataset size");95 let pt1 = ds.getPixel(0);96 assert.equal(pt1.metadata["label"], "Bar0", "pt1 label");97 assert.equal(pt1.x, 5.5, "pt1 x");98 assert.equal(pt1.y, 15, "pt1 y");99 let pt2 = ds.getPixel(1);100 assert.equal(pt2.metadata["label"], "Bar1", "pt2 label");101 assert.equal(pt2.x, 56.5, "pt2 x");102 assert.equal(pt2.y, 40, "pt2 y");...
autoDetection.js
Source:autoDetection.js
1'use strict';2let hljs = require('../../build');3let should = require('should');4describe('.autoDetection()', function() {5 it('should get an existing language', function() {6 const result = hljs.autoDetection('python');7 result.should.be.instanceOf(Object);8 });9 it('should get an existing language by alias', function() {10 const result = hljs.autoDetection('py');11 result.should.be.instanceOf(Object);12 });13 it('should be case insensitive', function() {14 const result = hljs.autoDetection('pYTHOn');15 result.should.be.instanceOf(Object);16 });17 it('should return undefined', function() {18 const result = hljs.autoDetection('-impossible-');19 should.strictEqual(result, undefined);20 });21 it('should not break on undefined', function() {22 const result = hljs.autoDetection(undefined);23 should.strictEqual(result, undefined);24 });...
90autoDetection.js
Source:90autoDetection.js
1'use strict';2let hljs = require('../../build');3let should = require('should');4describe('.autoDetection()', function() {5 it('should get an existing language', function() {6 const result = hljs.autoDetection('python');7 result.should.be.instanceOf(Object);8 });9 it('should get an existing language by alias', function() {10 const result = hljs.autoDetection('py');11 result.should.be.instanceOf(Object);12 });13 it('should be case insensitive', function() {14 const result = hljs.autoDetection('pYTHOn');15 result.should.be.instanceOf(Object);16 });17 it('should return undefined', function() {18 const result = hljs.autoDetection('-impossible-');19 should.strictEqual(result, undefined);20 });21 it('should not break on undefined', function() {22 const result = hljs.autoDetection(undefined);23 should.strictEqual(result, undefined);24 });...
autodetection.actions.js
Source:autodetection.actions.js
1export const ADD_AUTODETECTION = "ADD_AUTODETECTION";2export const REMOVE_AUTODETECTION = "REMOVE_AUTODETECTION";3export const addAutodetection = (payload) => {4 return { type: ADD_AUTODETECTION, payload };5};6window.addAutodetection = addAutodetection;7export const removeAutodetection = () => {8 return { type: REMOVE_AUTODETECTION, payload: {} };9};...
Using AI Code Generation
1const { autoDetect } = require('playwright-internal');2(async () => {3 const browser = await autoDetect();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();9const { autoDetect } = require('playwright');10(async () => {11 const browser = await autoDetect();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: 'example.png' });15 await browser.close();16})();17const { autoDetect } = require('playwright');18(async () => {19 const browser = await autoDetect();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: 'example.png' });23 await browser.close();24})();25const { autoDetect } = require('playwright');26(async () => {27 const browser = await autoDetect();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: 'example.png' });31 await browser.close();32})();33const { autoDetect } = require('playwright');34(async () => {35 const browser = await autoDetect();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: 'example.png' });39 await browser.close();40})();41const { autoDetect } = require('playwright');42(async () => {43 const browser = await autoDetect();44 const context = await browser.newContext();45 const page = await context.newPage();
Using AI Code Generation
1import { autoDetect } from 'playwright-internal';2const browser = await autoDetect();3const context = await browser.newContext();4const page = await context.newPage();5await page.screenshot({ path: 'google.png' });6await browser.close();7import { autoDetect } from 'playwright';8const browser = await autoDetect();9const context = await browser.newContext();10const page = await context.newPage();11await page.screenshot({ path: 'google.png' });12await browser.close();13import { autoDetect } from 'playwright';14const browser = await autoDetect();15const context = await browser.newContext();16const page = await context.newPage();17await page.screenshot({ path: 'google.png' });18await browser.close();19import { autoDetect } from 'playwright';20const browser = await autoDetect();21const context = await browser.newContext();22const page = await context.newPage();23await page.screenshot({ path: 'google.png' });24await browser.close();25import { autoDetect } from 'playwright';26const browser = await autoDetect();27const context = await browser.newContext();28const page = await context.newPage();29await page.screenshot({ path: 'google.png' });30await browser.close();31import { autoDetect } from 'playwright';32const browser = await autoDetect();33const context = await browser.newContext();34const page = await context.newPage();35await page.screenshot({ path: 'google.png' });36await browser.close();37import { autoDetect } from 'playwright';38const browser = await autoDetect();
Using AI Code Generation
1const { autoDetect } = require('playwright-core/lib/server/browserType');2const browser = await autoDetect();3const context = await browser.newContext();4const page = await context.newPage();5await page.screenshot({ path: `example.png` });6await browser.close();
Using AI Code Generation
1const autoDetect = require('playwright/lib/server/browserType');2const { chromium } = autoDetect();3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await browser.close();7})();8module.exports = {9 autoDetect: require('./browserType').autoDetect,10};11const autoDetect = require('playwright/lib/server/browserType').autoDetect;12const { chromium } = autoDetect();13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 await browser.close();17})();
Using AI Code Generation
1const { chromium } = require('playwright');2const { autoDetect } = require('@playwright/test/lib/server/installServer');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const server = await autoDetect();8 await page.goto(server.PREFIX + '/grid.html');9 await page.screenshot({ path: `example.png` });10 await browser.close();11})();12const { chromium } = require('playwright');13const { autoDetect } = require('@playwright/test/lib/server/installServer');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const server = await autoDetect();19 await page.goto(server.PREFIX + '/grid.html');20 await page.screenshot({ path: `example.png` });21 await browser.close();22})();23const { chromium } = require('playwright');24const { autoDetect } = require('@playwright/test/lib/server/installServer');25(async () => {26 const browser = await chromium.launch();27 const context = await browser.newContext();28 const page = await context.newPage();29 const server = await autoDetect();30 await page.goto(server.PREFIX + '/grid.html');31 await page.screenshot({ path: `example.png` });32 await browser.close();33})();34const { chromium } = require('playwright');35const { autoDetect } = require('@playwright/test/lib/server/installServer');36(async () => {37 const browser = await chromium.launch();38 const context = await browser.newContext();39 const page = await context.newPage();40 const server = await autoDetect();41 await page.goto(server.PREFIX + '/grid.html');42 await page.screenshot({ path: `example.png` });43 await browser.close();44})();45const { chromium } = require('playwright');46const { autoDetect } = require('@playwright/test/lib/server/installServer');47(async () => {48 const browser = await chromium.launch();49 const context = await browser.newContext();50 const page = await context.newPage();51 const server = await autoDetect();52 await page.goto(server.P
Using AI Code Generation
1const { Playwright } = require('playwright');2const playwright = Playwright.create();3const browser = await playwright.chromium.launch();4const page = await browser.newPage();5await page.screenshot({ path: 'example.png' });6await browser.close();7const { Playwright } = require('playwright');8const playwright = Playwright.create();9const config = {10 use: {11 viewport: {12 },13 },14 browserName: playwright.chromium.name(),15};16module.exports = config;17import { Playwright } from 'playwright';18const playwright = Playwright.create();19const config: PlaywrightTestConfig = {20 use: {21 viewport: {22 },23 },24 browserName: playwright.chromium.name(),25};26export default config;27import { Playwright } from 'playwright';28const playwright = Playwright.create();29const config: PlaywrightTestConfig = {30 use: {31 viewport: {32 },33 },34 browserName: playwright.chromium.name(),35};36export default config;37import { Playwright } from 'playwright';38const playwright = Playwright.create();39const config: PlaywrightTestConfig = {40 use: {41 viewport: {42 },
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();9const playwright = require('playwright');10(async () => {11 const browser = await playwright.firefox.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: 'example.png' });15 await browser.close();16})();17const playwright = require('playwright');18(async () => {19 const browser = await playwright.webkit.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: 'example.png' });23 await browser.close();24})();25const playwright = require('playwright');26(async () => {27 const browser = await playwright.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: 'example.png' });31 await browser.close();32})();33const playwright = require('playwright');34(async () => {35 const browser = await playwright.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: 'example.png' });39 await browser.close();40})();41const playwright = require('playwright');
Using AI Code Generation
1const autoDetect = require('playwright-internal').autoDetect;2(async () => {3 const browserType = autoDetect();4 const browser = await browserType.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 console.log(await page.textContent('body'));8 await browser.close();9})();10{11 "scripts": {12 },13 "devDependencies": {14 }15}16const autoDetect = require('playwright-internal').autoDetect;17(async () => {18 const browserType = autoDetect();19 const browser = await browserType.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 console.log(await page.textContent('body'));23 await browser.close();24})();25{26 "scripts": {27 },28 "devDependencies": {29 }30}31const autoDetect = require('playwright-internal').autoDetect;32(async () => {33 const browserType = autoDetect();34 const browser = await browserType.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 console.log(await page.textContent('body'));38 await browser.close();39})();
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright['chromium'].launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const playwright = require('playwright');10(async () => {11 const browser = await playwright.chromium.launch({ headless: false });12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();17const playwright = require('playwright');18(async () => {19 const browser = await playwright['chromium'].launch({ headless: false });20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: `example.png` });23 await browser.close();24})();25const playwright = require('playwright');26(async () => {27 const browser = await playwright.chromium.launch({ headless: false });28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: `example.png` });31 await browser.close();32})();33const playwright = require('playwright');34(async () => {35 const browser = await playwright['chromium'].launch({ headless: false });36 const context = await browser.newContext();37 const page = await context.newPage();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!