How to use shrinks method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

dynamic-output.js

Source:dynamic-output.js Github

copy

Full Screen

1const { assert, skip, test, module: describe, only } = require('qunit');2const { GPU } = require('../../src');3describe('features: dynamic output');4function dynamicOutput1DGrows(mode) {5 const gpu = new GPU({ mode });6 const kernel = gpu.createKernel(function() {7 return this.output.x + this.thread.x;8 }, { dynamicOutput: true });9 kernel.setOutput([5]);10 let result = kernel();11 assert.equal(result.length, 5);12 assert.deepEqual(Array.from(result), [5,6,7,8,9]);13 assert.deepEqual(Array.from(kernel.output), [5]);14 kernel.setOutput([10]);15 result = kernel();16 assert.equal(result.length, 10);17 assert.deepEqual(Array.from(result), [10,11,12,13,14,15,16,17,18,19]);18 assert.deepEqual(Array.from(kernel.output), [10]);19 gpu.destroy();20}21test('dynamic output 1d grows auto', () => {22 dynamicOutput1DGrows();23});24test('dynamic output 1d grows gpu', () => {25 dynamicOutput1DGrows('gpu');26});27(GPU.isWebGLSupported ? test : skip)('dynamic output 1d grows webgl', () => {28 dynamicOutput1DGrows('webgl');29});30(GPU.isWebGL2Supported ? test : skip)('dynamic output 1d grows webgl2', () => {31 dynamicOutput1DGrows('webgl2');32});33(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 1d grows headlessgl', () => {34 dynamicOutput1DGrows('headlessgl');35});36test('dynamic output 1d grows cpu', () => {37 dynamicOutput1DGrows('cpu');38});39function dynamicOutput1DShrinks(mode) {40 const gpu = new GPU({ mode });41 const kernel = gpu.createKernel(function() {42 return this.output.x + this.thread.x;43 }, { dynamicOutput: true });44 kernel.setOutput([10]);45 let result = kernel();46 assert.equal(result.length, 10);47 assert.deepEqual(Array.from(result), [10,11,12,13,14,15,16,17,18,19]);48 assert.deepEqual(Array.from(kernel.output), [10]);49 kernel.setOutput([5]);50 result = kernel();51 assert.equal(result.length, 5);52 assert.deepEqual(Array.from(result), [5,6,7,8,9]);53 assert.deepEqual(Array.from(kernel.output), [5]);54 gpu.destroy();55}56test('dynamic output 1d shrinks auto', () => {57 dynamicOutput1DShrinks();58});59test('dynamic output 1d shrinks gpu', () => {60 dynamicOutput1DShrinks('gpu');61});62(GPU.isWebGLSupported ? test : skip)('dynamic output 1d shrinks webgl', () => {63 dynamicOutput1DShrinks('webgl');64});65(GPU.isWebGL2Supported ? test : skip)('dynamic output 1d shrinks webgl2', () => {66 dynamicOutput1DShrinks('webgl2');67});68(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 1d shrinks headlessgl', () => {69 dynamicOutput1DShrinks('headlessgl');70});71test('dynamic output 1d shrinks cpu', () => {72 dynamicOutput1DShrinks('cpu');73});74function dynamicOutput1DKernelMapGrows(mode) {75 const gpu = new GPU({ mode });76 const kernel = gpu.createKernelMap({77 result2: function map(v) {78 return v;79 }80 }, function() {81 return map(this.output.x + this.thread.x);82 }, { dynamicOutput: true });83 kernel.setOutput([5]);84 let result = kernel();85 assert.equal(result.result.length, 5);86 assert.equal(result.result2.length, 5);87 assert.deepEqual(Array.from(result.result), [5,6,7,8,9]);88 assert.deepEqual(Array.from(result.result2), [5,6,7,8,9]);89 assert.deepEqual(Array.from(kernel.output), [5]);90 kernel.setOutput([10]);91 result = kernel();92 assert.equal(result.result.length, 10);93 assert.equal(result.result2.length, 10);94 assert.deepEqual(Array.from(result.result), [10,11,12,13,14,15,16,17,18,19]);95 assert.deepEqual(Array.from(result.result2), [10,11,12,13,14,15,16,17,18,19]);96 assert.deepEqual(Array.from(kernel.output), [10]);97 gpu.destroy();98}99test('dynamic output 1d kernel map grows auto', () => {100 dynamicOutput1DKernelMapGrows();101});102test('dynamic output 1d kernel map grows gpu', () => {103 dynamicOutput1DKernelMapGrows('gpu');104});105(GPU.isWebGLSupported ? test : skip)('dynamic output 1d kernel map grows webgl', () => {106 dynamicOutput1DKernelMapGrows('webgl');107});108(GPU.isWebGL2Supported ? test : skip)('dynamic output 1d kernel map grows webgl2', () => {109 dynamicOutput1DKernelMapGrows('webgl2');110});111(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 1d kernel map grows headlessgl', () => {112 dynamicOutput1DKernelMapGrows('headlessgl');113});114test('dynamic output 1d kernel map grows cpu', () => {115 dynamicOutput1DKernelMapGrows('cpu');116});117function dynamicOutput1DKernelMapShrinks(mode) {118 const gpu = new GPU({ mode });119 const kernel = gpu.createKernelMap({120 result2: function map(v) {121 return v;122 }123 }, function() {124 return map(this.output.x + this.thread.x);125 }, { dynamicOutput: true });126 kernel.setOutput([10]);127 let result = kernel();128 assert.equal(result.result.length, 10);129 assert.equal(result.result2.length, 10);130 assert.deepEqual(Array.from(result.result), [10,11,12,13,14,15,16,17,18,19]);131 assert.deepEqual(Array.from(result.result2), [10,11,12,13,14,15,16,17,18,19]);132 assert.deepEqual(Array.from(kernel.output), [10]);133 kernel.setOutput([5]);134 result = kernel();135 assert.equal(result.result.length, 5);136 assert.equal(result.result2.length, 5);137 assert.deepEqual(Array.from(result.result), [5,6,7,8,9]);138 assert.deepEqual(Array.from(result.result2), [5,6,7,8,9]);139 assert.deepEqual(Array.from(kernel.output), [5]);140 gpu.destroy();141}142test('dynamic output 1d kernel map shrinks auto', () => {143 dynamicOutput1DKernelMapShrinks();144});145test('dynamic output 1d kernel map shrinks gpu', () => {146 dynamicOutput1DKernelMapShrinks('gpu');147});148(GPU.isWebGLSupported ? test : skip)('dynamic output 1d kernel map shrinks webgl', () => {149 dynamicOutput1DKernelMapShrinks('webgl');150});151(GPU.isWebGL2Supported ? test : skip)('dynamic output 1d kernel map shrinks webgl2', () => {152 dynamicOutput1DKernelMapShrinks('webgl2');153});154(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 1d kernel map shrinks headlessgl', () => {155 dynamicOutput1DKernelMapShrinks('headlessgl');156});157test('dynamic output 1d kernel map shrinks cpu', () => {158 dynamicOutput1DKernelMapShrinks('cpu');159});160function dynamicOutput2DGrows(mode) {161 const gpu = new GPU({ mode });162 const kernel = gpu.createKernel(function() {163 return this.output.x + this.output.y + this.thread.x + this.thread.y;164 }, { dynamicOutput: true });165 kernel.setOutput([2,2]);166 let result = kernel();167 assert.equal(result.length, 2);168 assert.deepEqual(result.map(row => Array.from(row)), [[4,5],[5,6]]);169 assert.deepEqual(Array.from(kernel.output), [2,2]);170 kernel.setOutput([3,3]);171 result = kernel();172 assert.equal(result.length, 3);173 assert.deepEqual(result.map(row => Array.from(row)), [[6,7,8],[7,8,9],[8,9,10]]);174 assert.deepEqual(Array.from(kernel.output), [3,3]);175 gpu.destroy();176}177test('dynamic output 2d grows auto', () => {178 dynamicOutput2DGrows();179});180test('dynamic output 2d grows gpu', () => {181 dynamicOutput2DGrows('gpu');182});183(GPU.isWebGLSupported ? test : skip)('dynamic output 2d grows webgl', () => {184 dynamicOutput2DGrows('webgl');185});186(GPU.isWebGL2Supported ? test : skip)('dynamic output 2d grows webgl2', () => {187 dynamicOutput2DGrows('webgl2');188});189(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 2d grows headlessgl', () => {190 dynamicOutput2DGrows('headlessgl');191});192test('dynamic output 2d grows cpu', () => {193 dynamicOutput2DGrows('cpu');194});195function dynamicOutput2DShrinks(mode) {196 const gpu = new GPU({ mode });197 const kernel = gpu.createKernel(function() {198 return this.output.x + this.output.y + this.thread.x + this.thread.y;199 }, { dynamicOutput: true });200 kernel.setOutput([3,3]);201 let result = kernel();202 assert.equal(result.length, 3);203 assert.deepEqual(result.map(row => Array.from(row)), [[6,7,8],[7,8,9],[8,9,10]]);204 assert.deepEqual(Array.from(kernel.output), [3,3]);205 kernel.setOutput([2,2]);206 result = kernel();207 assert.equal(result.length, 2);208 assert.deepEqual(result.map(row => Array.from(row)), [[4,5],[5,6]]);209 assert.deepEqual(Array.from(kernel.output), [2,2]);210 gpu.destroy();211}212test('dynamic output 2d shrinks auto', () => {213 dynamicOutput2DShrinks();214});215test('dynamic output 2d shrinks gpu', () => {216 dynamicOutput2DShrinks('gpu');217});218(GPU.isWebGLSupported ? test : skip)('dynamic output 2d shrinks webgl', () => {219 dynamicOutput2DShrinks('webgl');220});221(GPU.isWebGL2Supported ? test : skip)('dynamic output 2d shrinks webgl2', () => {222 dynamicOutput2DShrinks('webgl2');223});224(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 2d shrinks headlessgl', () => {225 dynamicOutput2DShrinks('headlessgl');226});227test('dynamic output 2d shrinks cpu', () => {228 dynamicOutput2DShrinks('cpu');229});230function dynamicOutput2DKernelMapGrows(mode) {231 const gpu = new GPU({ mode });232 const kernel = gpu.createKernelMap({233 result1: function map(v) {234 return v;235 }236 }, function() {237 return map(this.output.x + this.output.y + this.thread.x + this.thread.y);238 }, { dynamicOutput: true });239 kernel.setOutput([2,2]);240 let result = kernel();241 assert.equal(result.result.length, 2);242 assert.equal(result.result1.length, 2);243 assert.deepEqual(result.result.map(row => Array.from(row)), [[4,5],[5,6]]);244 assert.deepEqual(result.result1.map(row => Array.from(row)), [[4,5],[5,6]]);245 assert.deepEqual(Array.from(kernel.output), [2,2]);246 kernel.setOutput([3,3]);247 result = kernel();248 assert.equal(result.result.length, 3);249 assert.equal(result.result1.length, 3);250 assert.deepEqual(result.result.map(row => Array.from(row)), [[6,7,8],[7,8,9],[8,9,10]]);251 assert.deepEqual(result.result1.map(row => Array.from(row)), [[6,7,8],[7,8,9],[8,9,10]]);252 assert.deepEqual(Array.from(kernel.output), [3,3]);253 gpu.destroy();254}255test('dynamic output 2d kernel map grows auto', () => {256 dynamicOutput2DKernelMapGrows();257});258test('dynamic output 2d kernel map grows gpu', () => {259 dynamicOutput2DKernelMapGrows('gpu');260});261(GPU.isWebGLSupported ? test : skip)('dynamic output 2d kernel map grows webgl', () => {262 dynamicOutput2DKernelMapGrows('webgl');263});264(GPU.isWebGL2Supported ? test : skip)('dynamic output 2d kernel map grows webgl2', () => {265 dynamicOutput2DKernelMapGrows('webgl2');266});267(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 2d kernel map grows headlessgl', () => {268 dynamicOutput2DKernelMapGrows('headlessgl');269});270test('dynamic output 2d kernel map grows cpu', () => {271 dynamicOutput2DKernelMapGrows('cpu');272});273function dynamicOutput2DKernelMapShrinks(mode) {274 const gpu = new GPU({ mode });275 const kernel = gpu.createKernelMap({276 result1: function map(v) {277 return v;278 }279 }, function() {280 return map(this.output.x + this.output.y + this.thread.x + this.thread.y);281 }, { dynamicOutput: true });282 kernel.setOutput([3,3]);283 let result = kernel();284 assert.equal(result.result.length, 3);285 assert.equal(result.result1.length, 3);286 assert.deepEqual(result.result.map(row => Array.from(row)), [[6,7,8],[7,8,9],[8,9,10]]);287 assert.deepEqual(result.result1.map(row => Array.from(row)), [[6,7,8],[7,8,9],[8,9,10]]);288 assert.deepEqual(Array.from(kernel.output), [3,3]);289 kernel.setOutput([2,2]);290 result = kernel();291 assert.equal(result.result.length, 2);292 assert.equal(result.result1.length, 2);293 assert.deepEqual(result.result.map(row => Array.from(row)), [[4,5],[5,6]]);294 assert.deepEqual(result.result1.map(row => Array.from(row)), [[4,5],[5,6]]);295 assert.deepEqual(Array.from(kernel.output), [2,2]);296 gpu.destroy();297}298test('dynamic output 2d shrinks auto', () => {299 dynamicOutput2DShrinks();300});301test('dynamic output 2d shrinks gpu', () => {302 dynamicOutput2DShrinks('gpu');303});304(GPU.isWebGLSupported ? test : skip)('dynamic output 2d shrinks webgl', () => {305 dynamicOutput2DShrinks('webgl');306});307(GPU.isWebGL2Supported ? test : skip)('dynamic output 2d shrinks webgl2', () => {308 dynamicOutput2DShrinks('webgl2');309});310(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 2d shrinks headlessgl', () => {311 dynamicOutput2DShrinks('headlessgl');312});313test('dynamic output 2d shrinks cpu', () => {314 dynamicOutput2DShrinks('cpu');315});316//TODO:317function dynamicOutput2DGraphicalGrows(mode) {318 const gpu = new GPU({ mode });319 const kernel = gpu.createKernel(function() {320 this.color(1,1,1,1);321 }, { graphical: true, dynamicOutput: true });322 kernel.setOutput([2,2]);323 kernel();324 let result = kernel.getPixels();325 assert.equal(result.length, 2 * 2 * 4);326 assert.deepEqual(Array.from(result), [327 255, 255, 255, 255,328 255, 255, 255, 255,329 255, 255, 255, 255,330 255, 255, 255, 255331 ]);332 assert.deepEqual(Array.from(kernel.output), [2,2]);333 kernel.setOutput([3,3]);334 kernel();335 result = kernel.getPixels();336 assert.equal(result.length, 3 * 3 * 4);337 assert.deepEqual(Array.from(result), [338 255, 255, 255, 255,339 255, 255, 255, 255,340 255, 255, 255, 255,341 255, 255, 255, 255,342 255, 255, 255, 255,343 255, 255, 255, 255,344 255, 255, 255, 255,345 255, 255, 255, 255,346 255, 255, 255, 255,347 ]);348 assert.deepEqual(Array.from(kernel.output), [3,3]);349 gpu.destroy();350}351test('dynamic output 2d graphical grows auto', () => {352 dynamicOutput2DGraphicalGrows();353});354test('dynamic output 2d graphical grows gpu', () => {355 dynamicOutput2DGraphicalGrows('gpu');356});357(GPU.isWebGLSupported ? test : skip)('dynamic output 2d graphical grows webgl', () => {358 dynamicOutput2DGraphicalGrows('webgl');359});360(GPU.isWebGL2Supported ? test : skip)('dynamic output 2d graphical grows webgl2', () => {361 dynamicOutput2DGraphicalGrows('webgl2');362});363(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 2d graphical grows headlessgl', () => {364 dynamicOutput2DGraphicalGrows('headlessgl');365});366(GPU.isCanvasSupported ? test : skip)('dynamic output 2d graphical grows cpu', () => {367 dynamicOutput2DGraphicalGrows('cpu');368});369function dynamicOutput2DGraphicalShrinks(mode) {370 const gpu = new GPU({ mode });371 const kernel = gpu.createKernel(function() {372 this.color(1,1,1,1);373 }, { graphical: true, dynamicOutput: true });374 kernel.setOutput([3,3]);375 kernel();376 let result = kernel.getPixels();377 assert.equal(result.length, 3 * 3 * 4);378 assert.deepEqual(Array.from(result), [379 255, 255, 255, 255,380 255, 255, 255, 255,381 255, 255, 255, 255,382 255, 255, 255, 255,383 255, 255, 255, 255,384 255, 255, 255, 255,385 255, 255, 255, 255,386 255, 255, 255, 255,387 255, 255, 255, 255,388 ]);389 assert.deepEqual(Array.from(kernel.output), [3,3]);390 kernel.setOutput([2,2]);391 kernel();392 result = kernel.getPixels();393 assert.equal(result.length, 2 * 2 * 4);394 assert.deepEqual(Array.from(result), [395 255, 255, 255, 255,396 255, 255, 255, 255,397 255, 255, 255, 255,398 255, 255, 255, 255399 ]);400 assert.deepEqual(Array.from(kernel.output), [2,2]);401 gpu.destroy();402}403test('dynamic output 2d graphical shrinks auto', () => {404 dynamicOutput2DGraphicalShrinks();405});406test('dynamic output 2d graphical shrinks gpu', () => {407 dynamicOutput2DGraphicalShrinks('gpu');408});409(GPU.isWebGLSupported ? test : skip)('dynamic output 2d graphical shrinks webgl', () => {410 dynamicOutput2DGraphicalShrinks('webgl');411});412(GPU.isWebGL2Supported ? test : skip)('dynamic output 2d graphical shrinks webgl2', () => {413 dynamicOutput2DGraphicalShrinks('webgl2');414});415(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 2d graphical shrinks headlessgl', () => {416 dynamicOutput2DGraphicalShrinks('headlessgl');417});418(GPU.isCanvasSupported ? test : skip)('dynamic output 2d graphical shrinks cpu', () => {419 dynamicOutput2DGraphicalShrinks('cpu');420});421function dynamicOutput3DGrows(mode) {422 const gpu = new GPU({ mode });423 const kernel = gpu.createKernel(function() {424 return this.output.x + this.output.y + this.thread.z + this.thread.x + this.thread.y + this.thread.z;425 }, { dynamicOutput: true });426 kernel.setOutput([2,2,2]);427 let result = kernel();428 assert.equal(result.length, 2);429 assert.deepEqual(result.map(matrix => matrix.map(row => Array.from(row))), [[[4,5],[5,6]],[[6,7],[7,8]]]);430 assert.deepEqual(Array.from(kernel.output), [2,2,2]);431 kernel.setOutput([3,3,3]);432 result = kernel();433 assert.equal(result.length, 3);434 assert.deepEqual(result.map(matrix => matrix.map(row => Array.from(row))), [435 [436 [6,7,8],437 [7,8,9],438 [8,9,10]439 ],440 [441 [8,9,10],442 [9,10,11],443 [10,11,12]444 ],445 [446 [10,11,12],447 [11,12,13],448 [12,13,14]449 ]450 ]);451 assert.deepEqual(Array.from(kernel.output), [3,3,3]);452 gpu.destroy();453}454test('dynamic output 3d grows auto', () => {455 dynamicOutput3DGrows();456});457test('dynamic output 3d grows gpu', () => {458 dynamicOutput3DGrows('gpu');459});460(GPU.isWebGLSupported ? test : skip)('dynamic output 3d grows webgl', () => {461 dynamicOutput3DGrows('webgl');462});463(GPU.isWebGL2Supported ? test : skip)('dynamic output 3d grows webgl2', () => {464 dynamicOutput3DGrows('webgl2');465});466(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 3d grows headlessgl', () => {467 dynamicOutput3DGrows('headlessgl');468});469test('dynamic output 3d grows cpu', () => {470 dynamicOutput3DGrows('cpu');471});472function dynamicOutput3DShrinks(mode) {473 const gpu = new GPU({ mode });474 const kernel = gpu.createKernel(function() {475 return this.output.x + this.output.y + this.thread.z + this.thread.x + this.thread.y + this.thread.z;476 }, { dynamicOutput: true });477 kernel.setOutput([3,3,3]);478 let result = kernel();479 assert.equal(result.length, 3);480 assert.deepEqual(result.map(matrix => matrix.map(row => Array.from(row))), [481 [482 [6,7,8],483 [7,8,9],484 [8,9,10]485 ],486 [487 [8,9,10],488 [9,10,11],489 [10,11,12]490 ],491 [492 [10,11,12],493 [11,12,13],494 [12,13,14]495 ]496 ]);497 assert.deepEqual(Array.from(kernel.output), [3,3,3]);498 kernel.setOutput([2,2,2]);499 result = kernel();500 assert.equal(result.length, 2);501 assert.deepEqual(result.map(matrix => matrix.map(row => Array.from(row))), [[[4,5],[5,6]],[[6,7],[7,8]]]);502 assert.deepEqual(Array.from(kernel.output), [2,2,2]);503 gpu.destroy();504}505test('dynamic output 3d shrinks auto', () => {506 dynamicOutput3DShrinks();507});508test('dynamic output 3d shrinks gpu', () => {509 dynamicOutput3DShrinks('gpu');510});511(GPU.isWebGLSupported ? test : skip)('dynamic output 3d shrinks webgl', () => {512 dynamicOutput3DShrinks('webgl');513});514(GPU.isWebGL2Supported ? test : skip)('dynamic output 3d shrinks webgl2', () => {515 dynamicOutput3DShrinks('webgl2');516});517(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 3d shrinks headlessgl', () => {518 dynamicOutput3DShrinks('headlessgl');519});520test('dynamic output 3d shrinks cpu', () => {521 dynamicOutput3DShrinks('cpu');522});523function dynamicOutput3DKernelMapGrows(mode) {524 const gpu = new GPU({ mode });525 const kernel = gpu.createKernelMap({526 result1: function map(v) {527 return v;528 }529 }, function() {530 return map(this.output.x + this.output.y + this.thread.z + this.thread.x + this.thread.y + this.thread.z);531 }, { dynamicOutput: true });532 kernel.setOutput([2,2,2]);533 let result = kernel();534 assert.equal(result.result.length, 2);535 assert.equal(result.result1.length, 2);536 assert.deepEqual(result.result.map(matrix => matrix.map(row => Array.from(row))), [[[4,5],[5,6]],[[6,7],[7,8]]]);537 assert.deepEqual(result.result1.map(matrix => matrix.map(row => Array.from(row))), [[[4,5],[5,6]],[[6,7],[7,8]]]);538 assert.deepEqual(Array.from(kernel.output), [2,2,2]);539 kernel.setOutput([3,3,3]);540 result = kernel();541 assert.equal(result.result.length, 3);542 assert.equal(result.result1.length, 3);543 assert.deepEqual(result.result.map(matrix => matrix.map(row => Array.from(row))), [544 [545 [6,7,8],546 [7,8,9],547 [8,9,10]548 ],549 [550 [8,9,10],551 [9,10,11],552 [10,11,12]553 ],554 [555 [10,11,12],556 [11,12,13],557 [12,13,14]558 ]559 ]);560 assert.deepEqual(result.result1.map(matrix => matrix.map(row => Array.from(row))), [561 [562 [6,7,8],563 [7,8,9],564 [8,9,10]565 ],566 [567 [8,9,10],568 [9,10,11],569 [10,11,12]570 ],571 [572 [10,11,12],573 [11,12,13],574 [12,13,14]575 ]576 ]);577 assert.deepEqual(Array.from(kernel.output), [3,3,3]);578 gpu.destroy();579}580test('dynamic output 3d kernel map grows auto', () => {581 dynamicOutput3DKernelMapGrows();582});583test('dynamic output 3d kernel map grows gpu', () => {584 dynamicOutput3DKernelMapGrows('gpu');585});586(GPU.isWebGLSupported ? test : skip)('dynamic output 3d kernel map grows webgl', () => {587 dynamicOutput3DKernelMapGrows('webgl');588});589(GPU.isWebGL2Supported ? test : skip)('dynamic output 3d kernel map grows webgl2', () => {590 dynamicOutput3DKernelMapGrows('webgl2');591});592(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 3d kernel map grows headlessgl', () => {593 dynamicOutput3DKernelMapGrows('headlessgl');594});595test('dynamic output 3d kernel map grows cpu', () => {596 dynamicOutput3DKernelMapGrows('cpu');597});598function dynamicOutput3DKernelMapShrinks(mode) {599 const gpu = new GPU({ mode });600 const kernel = gpu.createKernelMap({601 result1: function map(v) {602 return v;603 }604 }, function() {605 return map(this.output.x + this.output.y + this.thread.z + this.thread.x + this.thread.y + this.thread.z);606 }, { dynamicOutput: true });607 kernel.setOutput([3,3,3]);608 let result = kernel();609 assert.equal(result.result.length, 3);610 assert.equal(result.result1.length, 3);611 assert.deepEqual(result.result.map(matrix => matrix.map(row => Array.from(row))), [612 [613 [6,7,8],614 [7,8,9],615 [8,9,10]616 ],617 [618 [8,9,10],619 [9,10,11],620 [10,11,12]621 ],622 [623 [10,11,12],624 [11,12,13],625 [12,13,14]626 ]627 ]);628 assert.deepEqual(result.result1.map(matrix => matrix.map(row => Array.from(row))), [629 [630 [6,7,8],631 [7,8,9],632 [8,9,10]633 ],634 [635 [8,9,10],636 [9,10,11],637 [10,11,12]638 ],639 [640 [10,11,12],641 [11,12,13],642 [12,13,14]643 ]644 ]);645 assert.deepEqual(Array.from(kernel.output), [3,3,3]);646 kernel.setOutput([2,2,2]);647 result = kernel();648 assert.equal(result.result.length, 2);649 assert.equal(result.result1.length, 2);650 assert.deepEqual(result.result.map(matrix => matrix.map(row => Array.from(row))), [[[4,5],[5,6]],[[6,7],[7,8]]]);651 assert.deepEqual(result.result1.map(matrix => matrix.map(row => Array.from(row))), [[[4,5],[5,6]],[[6,7],[7,8]]]);652 assert.deepEqual(Array.from(kernel.output), [2,2,2]);653 gpu.destroy();654}655test('dynamic output 3d kernel map shrinks auto', () => {656 dynamicOutput3DKernelMapShrinks();657});658test('dynamic output 3d kernel map shrinks gpu', () => {659 dynamicOutput3DKernelMapShrinks('gpu');660});661(GPU.isWebGLSupported ? test : skip)('dynamic output 3d kernel map shrinks webgl', () => {662 dynamicOutput3DKernelMapShrinks('webgl');663});664(GPU.isWebGL2Supported ? test : skip)('dynamic output 3d kernel map shrinks webgl2', () => {665 dynamicOutput3DKernelMapShrinks('webgl2');666});667(GPU.isHeadlessGLSupported ? test : skip)('dynamic output 3d kernel map shrinks headlessgl', () => {668 dynamicOutput3DKernelMapShrinks('headlessgl');669});670test('dynamic output 3d kernel map shrinks cpu', () => {671 dynamicOutput3DKernelMapShrinks('cpu');...

Full Screen

Full Screen

Shrink.test.ts

Source:Shrink.test.ts Github

copy

Full Screen

1import * as dev from '../../src';2import { nativeCalculator } from '../../src/Number';3test.each([4 { value: 0, target: 0, expectedShrinks: [] },5 { value: 100, target: 0, expectedShrinks: [0, 50, 75, 87, 93, 96, 98, 99] },6 { value: 200, target: 0, expectedShrinks: [0, 100, 150, 175, 187, 193, 196, 198, 199] },7 { value: 100, target: 10, expectedShrinks: [10, 55, 77, 88, 94, 97, 98, 99] },8 { value: 100, target: -10, expectedShrinks: [-10, 45, 72, 86, 93, 96, 98, 99] },9 { value: -100, target: 0, expectedShrinks: [0, -50, -75, -87, -93, -96, -98, -99] },10 { value: 0, target: -10, expectedShrinks: [-10, -5, -3, -2, -1] },11])('towardsNumber', ({ value, target, expectedShrinks }) => {12 const shrinker = dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.loadIntegerUnchecked(target));13 const shrinks = Array.from(shrinker(nativeCalculator.loadIntegerUnchecked(value))).map(14 nativeCalculator.unloadInteger,15 );16 expect(shrinks).toEqual(expectedShrinks);17});18test.each([19 { value: [], size: 0, expectedShrinks: [] },20 { value: [], size: 1, expectedShrinks: [] },21 { value: ['a'], size: 0, expectedShrinks: [] },22 { value: ['a', 'b'], size: 0, expectedShrinks: [] },23 { value: ['a', 'b'], size: 1, expectedShrinks: [['a'], ['b']] },24 { value: ['a', 'b', 'c'], size: 1, expectedShrinks: [['a'], ['b'], ['c']] },25 {26 value: ['a', 'b', 'c'],27 size: 2,28 expectedShrinks: [29 ['a', 'b'],30 ['a', 'c'],31 ['b', 'c'],32 ],33 },34 {35 value: ['a', 'b', 'c', 'd'],36 size: 2,37 expectedShrinks: [38 ['a', 'b'],39 ['a', 'c'],40 ['a', 'd'],41 ['b', 'c'],42 ['b', 'd'],43 ['c', 'd'],44 ],45 },46 {47 value: ['a', 'b', 'c', 'd'],48 size: 3,49 expectedShrinks: [50 ['a', 'b', 'c'],51 ['a', 'b', 'd'],52 ['a', 'c', 'd'],53 ['b', 'c', 'd'],54 ],55 },56])('combinations', ({ value, size, expectedShrinks }) => {57 const shrinker = dev.Shrink.combinations(size);58 const shrinks = Array.from(shrinker(value));59 expect(shrinks).toEqual(expectedShrinks);60});61test.each([62 { value: [], targetLength: 0, expectedShrinks: [] },63 { value: ['a'], targetLength: 0, expectedShrinks: [[]] },64 { value: ['a', 'b'], targetLength: 0, expectedShrinks: [[], ['a'], ['b']] },65 { value: ['a', 'b'], targetLength: 1, expectedShrinks: [['a'], ['b']] },66 {67 value: ['a', 'b', 'c'],68 targetLength: 0,69 expectedShrinks: [[], ['a'], ['a', 'b'], ['b'], ['c'], ['a', 'c'], ['b', 'c']],70 },71 {72 value: ['a', 'b', 'c'],73 targetLength: 2,74 expectedShrinks: [75 ['a', 'b'],76 ['a', 'c'],77 ['b', 'c'],78 ],79 },80])('array', ({ value, targetLength, expectedShrinks }) => {81 const shrinker = dev.Shrink.array(targetLength);82 const shrinks = Array.from(shrinker(value));83 expect(shrinks).toEqual(expectedShrinks);84});85test.each([86 {87 value: ['c', 'b', 'a'],88 targetLength: 0,89 expectedShrinks: [90 ['a', 'b', 'c'],91 [],92 ['a'],93 ['a', 'b'],94 ['b'],95 ['c'],96 ['a', 'c'],97 ['b', 'c'],98 [],99 ['c'],100 ['c', 'b'],101 ['b'],102 ['a'],103 ['c', 'a'],104 ['b', 'a'],105 ],106 },107])('array (with ordering)', ({ value, targetLength, expectedShrinks }) => {108 const shrinker = dev.Shrink.array<string>(targetLength, (x) => x.charCodeAt(0));109 const shrinks = Array.from(shrinker(value));110 expect(shrinks).toEqual(expectedShrinks);111});112test.each([113 {114 value: [],115 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),116 expectedShrinks: [],117 },118 {119 value: [1],120 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),121 expectedShrinks: [[0]],122 },123 {124 value: [1, 2],125 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),126 expectedShrinks: [127 [0, 2],128 [1, 0],129 [1, 1],130 ],131 },132 {133 value: [1, 1, 0],134 elementShrinker: dev.Shrink.towardsNumber(nativeCalculator, nativeCalculator.zero),135 expectedShrinks: [136 [0, 1, 0],137 [1, 0, 0],138 ],139 },140])('elements', ({ value, elementShrinker, expectedShrinks }) => {141 const shrinker = dev.Shrink.elements(elementShrinker);142 const shrinks = Array.from(shrinker(value.map(nativeCalculator.loadIntegerUnchecked))).map((xs) =>143 xs.map(nativeCalculator.loadIntegerUnchecked),144 );145 expect(shrinks).toEqual(expectedShrinks);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shrinkString } = require('fast-check/lib/arbitrary/shrinkString.js');2const { shrinkNumber } = require('fast-check/lib/arbitrary/shrinkNumber.js');3const { shrinkArray } = require('fast-check/lib/arbitrary/shrinkArray.js');4const { shrinkObject } = require('fast-check/lib/arbitrary/shrinkObject.js');5const { shrinkTuple } = require('fast-check/lib/arbitrary/shrinkTuple.js');6const { shrinkSet } = require('fast-check/lib/arbitrary/shrinkSet.js');7const { shrinkMap } = require('fast-check/lib/arbitrary/shrinkMap.js');8const { shrinkDate } = require('fast-check/lib/arbitrary/shrinkDate.js');9const { shrinkBigInt } = require('fast-check/lib/arbitrary/shrinkBigInt.js');10const { string, number, array, record, tuple, set, map, date, bigInt } = require('fast-check');11const arb = string();12console.log('string', shrinkString(arb, 'abc'));13console.log('number', shrinkNumber(arb, 3));14console.log('array', shrinkArray(arb, [1, 2, 3]));15console.log('record', shrinkObject(arb, { a: 1, b: 2, c: 3 }));16console.log('tuple', shrinkTuple(arb, [1, 2, 3]));17console.log('set', shrinkSet(arb, new Set([1, 2, 3])));18console.log('map', shrinkMap(arb, new Map([[1, 2], [3, 4], [5, 6]])));19console.log('date', shrinkDate(arb, new Date()));20console.log('bigint', shrinkBigInt(arb, BigInt(123456789)));21const { string, number, array, record, tuple, set, map, date, bigInt } = require('fast-check');22const arb = string();23console.log('string', arb.shrink('abc'));24console.log('number', arb.shrink(3));25console.log('array', arb.shrink([1, 2, 3]));26console.log('record', arb.shrink({ a: 1, b: 2, c: 3 }));27console.log('tuple', arb.shrink([1, 2, 3]));28console.log('

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { shrinks } = require('fast-check/lib/src/check/arbitrary/ShrinkInternals.js');3const { tuple } = require('fast-check/lib/src/check/arbitrary/TupleArbitrary.js');4const { array } = require('fast-check/lib/src/check/arbitrary/ArrayArbitrary.js');5const arb = tuple(array(tuple(array(fc.integer()))), fc.integer());6const [x, y] = [ [ [[1, 2], [3, 4], [5, 6]], 7 ], 8 ];7const shrunk = shrinks(arb, x, y, 0);8console.log(shrunk);9const fc = require('fast-check');10const { tuple } = require('fast-check/lib/src/check/arbitrary/TupleArbitrary.js');11const { array } = require('fast-check/lib/src/check/arbitrary/ArrayArbitrary.js');12const arb = tuple(array(tuple(array(fc.integer()))), fc.integer());13const [x, y] = [ [ [[1, 2], [3, 4], [5, 6]], 7 ], 8 ];14const shrunk = arb.shrink([x, y]);15console.log(shrunk);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shrinks } = require("fast-check");2const { constantFrom } = require("fast-check");3const { string } = require("fast-check");4const { array } = require("fast-check");5const { tuple } = require("fast-check");6const { option } = require("fast-check");7const { record } = require("fast-check");8const { set } = require("fast-check");9const { map } = require("fast-check");10const { dictionary } = require("fast-check");11const { property } = require("fast-check");12const { oneof } = require("fast-check");13const { ascii } = require("fast-check");14const { asciiString } = require("fast-check");15const { unicode } = require("fast-check");16const { unicodeString } = require("fast-check");17const { fullUnicode } = require("fast-check");18const { fullUnicodeString } = require("fast-check");19const { char } = require("fast-check");20const { double } = require("fast-check");21const { float } = require("fast-check");22const { integer } = require("fast-check");23const { maxSafeInteger } = require("fast-check");24const { minSafeInteger } = require("fast-check");25const { nat } = require("fast-check");26const { noShrink } = require("fast-check");27const { option } = require("fast-check");28const { record } = require("fast-check");29const { set } = require("fast-check");30const { map } = require("fast-check");31const { dictionary } = require("fast-check");32const { constantFrom } = require("fast-check");33const { constant } = require("fast-check");34const { string } = require("fast-check");35const { array } = require("fast-check");36const { tuple } = require("fast-check");37const { option } = require("fast-check");38const { record } = require("fast-check");39const { set } = require("fast-check");40const { map } = require("fast-check");41const { dictionary } = require("fast-check");42const { constantFrom } = require("fast-check");43const { constant } = require("fast-check");44const { string } = require("fast-check");45const { array } = require("fast-check");46const { tuple } = require("fast-check");47const { option } = require("fast-check");48const { record } = require("fast-check");49const {

Full Screen

Using AI Code Generation

copy

Full Screen

1var fc = require("fast-check");2var shrinks = fc.shrinks;3var shrink = shrinks.shrink;4var shrinkNumber = shrink.number;5var shrinkString = shrink.string;6var shrinkArray = shrink.array;7var shrinkObject = shrink.object;8var shrinkRecord = shrink.record;9var shrinkInteger = shrink.integer;10var shrinkDouble = shrink.double;11var shrinkBoolean = shrink.boolean;12var shrinkDate = shrink.date;13var shrinkJson = shrink.json;14var shrinkConstant = shrink.constant;15var shrinkConstantFrom = shrink.constantFrom;16var shrinkConstantFromObject = shrink.constantFromObject;17var shrinkTuple = shrink.tuple;18var shrinkOneof = shrink.oneof;19var shrinkSubarray = shrink.subarray;20var shrinkSubarrayBy = shrink.subarrayBy;21var shrinkSubarrayByIndex = shrink.subarrayByIndex;22var shrinkSubarrayByLength = shrink.subarrayByLength;23var shrinkSubarrayBySize = shrink.subarrayBySize;24var shrinkSubarrayByStart = shrink.subarrayByStart;25var shrinkSubarrayByEnd = shrink.subarrayByEnd;26var shrinkSubarrayByStartAndLength = shrink.subarrayByStartAndLength;27var shrinkSubarrayByStartAndSize = shrink.subarrayByStartAndSize;28var shrinkSubarrayByEndAndLength = shrink.subarrayByEndAndLength;29var shrinkSubarrayByEndAndSize = shrink.subarrayByEndAndSize;30var shrinkSubarrayByStartAndEnd = shrink.subarrayByStartAndEnd;31var shrinkSubarrayByStartAndEndAndLength = shrink.subarrayByStartAndEndAndLength;32var shrinkSubarrayByStartAndEndAndSize = shrink.subarrayByStartAndEndAndSize;33var shrinkSubarrayByStartAndEndAndLengthAndSize = shrink.subarrayByStartAndEndAndLengthAndSize;34var shrinkSubarrayByStartAndEndAndLengthAndSizeAndIndex = shrink.subarrayByStartAndEndAndLengthAndSizeAndIndex;35var shrinkSubarrayByStartAndEndAndLengthAndSizeAndIndexAndValue = shrink.subarrayByStartAndEndAndLengthAndSizeAndIndexAndValue;36var shrinkSubarrayByStartAndEndAndLengthAndSizeAndIndexAndValueAndOriginal = shrink.subarrayByStartAndEndAndLengthAndSizeAndIndexAndValueAndOriginal;

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check')2const {shrink} = require('fast-check-shrinks')3fc.assert(4 fc.property(fc.array(fc.string()), (arr) => {5 const shrunk = shrink(arr, 3)6 return shrunk.every((item) => item.length <= 3)7 })8const fc = require('fast-check')9const {shrink} = require('fast-check-shrinks')10fc.assert(11 fc.property(fc.array(fc.string()), (arr) => {12 const shrunk = shrink(arr, 3)13 return shrunk.every((item) => item.length <= 3)14 })15const fc = require('fast-check')16const {shrink} = require('fast-check-shrinks')17fc.assert(18 fc.property(fc.array(fc.string()), (arr) => {19 const shrunk = shrink(arr, 3)20 return shrunk.every((item) => item.length <= 3)21 })22const fc = require('fast-check')23const {shrink} = require('fast-check-shrinks')24fc.assert(25 fc.property(fc.array(fc.string()), (arr) => {26 const shrunk = shrink(arr, 3)27 return shrunk.every((item) => item.length <= 3)28 })29const fc = require('fast-check')30const {shrink} = require('fast-check-shrinks')31fc.assert(32 fc.property(fc.array(fc.string()), (arr) => {33 const shrunk = shrink(arr, 3)34 return shrunk.every((item) => item.length <= 3)35 })36const fc = require('fast-check')37const {shrink} = require('fast-check-shrinks')38fc.assert(39 fc.property(fc.array(fc.string()), (arr) => {40 const shrunk = shrink(arr, 3)41 return shrunk.every((item) =>

Full Screen

Using AI Code Generation

copy

Full Screen

1const shrinks = require('fast-check-monorepo').shrinks;2const fc = require('fast-check');3const customShrinker = (value) => {4 if (value === 0) return shrinks.noop(value);5 if (value > 0) return shrinks.nat(value);6 return shrinks.integer(value);7};8const customShrinker2 = (value) => {9 if (value === 0) return shrinks.noop(value);10 if (value > 0) return shrinks.nat(value);11 return shrinks.integer(value);12};13const customShrinker3 = (value) => {14 if (value === 0) return shrinks.noop(value);15 if (value > 0) return shrinks.nat(value);16 return shrinks.integer(value);17};18const customShrinker4 = (value) => {19 if (value === 0) return shrinks.noop(value);20 if (value > 0) return shrinks.nat(value);21 return shrinks.integer(value);22};23const customShrinker5 = (value) => {24 if (value === 0) return shrinks.noop(value);25 if (value > 0) return shrinks.nat(value);26 return shrinks.integer(value);27};28const customShrinker6 = (value) => {29 if (value === 0) return shrinks.noop(value);30 if (value > 0) return shrinks.nat(value);31 return shrinks.integer(value);32};33const customShrinker7 = (value) => {34 if (value === 0) return shrinks.noop(value);35 if (value > 0) return shrinks.nat(value);36 return shrinks.integer(value);37};38const customShrinker8 = (value) => {39 if (value === 0) return shrinks.noop(value);40 if (value > 0) return shrinks.nat(value

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const shrinks = fc.shrinks;3const {string} = fc;4const shrinkString = shrinks((s) => {5 return s.length > 0 ? [s.slice(0, -1)] : [];6});7const shrinkString2 = shrinks((s) => {8 return s.length > 0 ? [s.slice(0, -1), s.slice(1)] : [];9});10const shrinkString3 = shrinks((s) => {11 return s.length > 0 ? [s.slice(0, -1), s.slice(1), s.slice(1, -1)] : [];12});13const shrinkString4 = shrinks((s) => {14 return s.length > 0 ? [s.slice(0, -1), s.slice(1), s.slice(1, -1), s.slice(0, -1) + s.slice(1)] : [];15});16const shrinkString5 = shrinks((s) => {17 return s.length > 0 ? [s.slice(0, -1), s.slice(1), s.slice(1, -1), s.slice(0, -1) + s.slice(1), s.slice(0, -1) + s.slice(2)] : [];18});19const shrinkString6 = shrinks((s) => {20 return s.length > 0 ? [s.slice(0, -1), s.slice(1), s.slice(1, -1), s.slice(0, -1) + s.slice(1), s.slice(0, -1) + s.slice(2), s.slice(0, -2) + s.slice(1)] : [];21});22const shrinkString7 = shrinks((s) => {23 return s.length > 0 ? [s.slice(0, -1), s.slice(1), s.slice(1, -1), s.slice(0, -1) + s.slice(1), s.slice(0, -1) + s.slice(2), s.slice(0, -2) + s.slice(1), s.slice(0, -2) + s.slice(2)] : [];24});25const shrinkString8 = shrinks((s) => {26 return s.length > 0 ? [s.slice(0, -1), s.slice(1), s.slice(1, -1

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shrinks, Arbitrary } = require("fast-check");2const { string } = require("fast-check");3const myStringArb = string();4const myShrinks = shrinks(myStringArb);5myShrinks("hello")6 .take(10)7 .toArray()8 .then((x) => {9 console.log(x);10 });11const { shrink, Arbitrary } = require("fast-check");12const { string } = require("fast-check");13const myStringArb = string();14shrink(myStringArb, "hello")15 .take(10)16 .toArray()17 .then((x) => {18 console.log(x);19 });20const { shrink, Arbitrary } = require("fast-check");21const { string } = require("fast-check");22const myStringArb = string();23shrink(myStringArb, "hello")24 .take(10)25 .toArray()26 .then((x) => {27 console.log(x);28 });

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 fast-check-monorepo 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