|
| 1 | +const { assert, test, skip, module: describe, only } = require('qunit'); |
| 2 | +const { GPU } = require('../../src'); |
| 3 | + |
| 4 | +describe('internal: GPU methods'); |
| 5 | + |
| 6 | +test('.createKernelMap() object map with settings', () => { |
| 7 | + const gpu = new GPU(); |
| 8 | + let source = null; |
| 9 | + let settings = null; |
| 10 | + function bob() {} |
| 11 | + function tom() {} |
| 12 | + class MockKernel { |
| 13 | + constructor(_source, _settings) { |
| 14 | + source = _source; |
| 15 | + settings = _settings; |
| 16 | + this.context = 'context'; |
| 17 | + this.canvas = 'canvas'; |
| 18 | + this.subKernels = []; |
| 19 | + } |
| 20 | + addSubKernel(subKernel) { |
| 21 | + this.subKernels.push(subKernel); |
| 22 | + } |
| 23 | + } |
| 24 | + gpu.Kernel = MockKernel; |
| 25 | + const subKernels = { |
| 26 | + bobResult: bob, |
| 27 | + tomResult: tom |
| 28 | + }; |
| 29 | + const kernelSource = function() {}; |
| 30 | + const masterSettings = {}; |
| 31 | + const kernel = gpu.createKernelMap(subKernels, kernelSource, masterSettings); |
| 32 | + assert.equal(source, kernelSource.toString()); |
| 33 | + assert.notEqual(settings, masterSettings); |
| 34 | + assert.equal(gpu.canvas, 'canvas'); |
| 35 | + assert.equal(gpu.context, 'context'); |
| 36 | + assert.equal(settings.functions, gpu.functions); |
| 37 | + assert.equal(settings.nativeFunctions, gpu.nativeFunctions); |
| 38 | + assert.equal(settings.gpu, gpu); |
| 39 | + assert.equal(settings.validate, true); |
| 40 | + assert.deepEqual(kernel.subKernels, [ |
| 41 | + { |
| 42 | + name: 'bob', |
| 43 | + source: bob.toString(), |
| 44 | + property: 'bobResult' |
| 45 | + }, |
| 46 | + { |
| 47 | + name: 'tom', |
| 48 | + source: tom.toString(), |
| 49 | + property: 'tomResult' |
| 50 | + } |
| 51 | + ]); |
| 52 | +}); |
| 53 | + |
| 54 | +test('.createKernelMap() array map with settings', () => { |
| 55 | + const gpu = new GPU(); |
| 56 | + let source = null; |
| 57 | + let settings = null; |
| 58 | + function bob() {} |
| 59 | + function tom() {} |
| 60 | + class MockKernel { |
| 61 | + constructor(_source, _settings) { |
| 62 | + source = _source; |
| 63 | + settings = _settings; |
| 64 | + this.context = 'context'; |
| 65 | + this.canvas = 'canvas'; |
| 66 | + this.subKernels = []; |
| 67 | + } |
| 68 | + addSubKernel(subKernel) { |
| 69 | + this.subKernels.push(subKernel); |
| 70 | + } |
| 71 | + } |
| 72 | + gpu.Kernel = MockKernel; |
| 73 | + const subKernels = [bob, tom]; |
| 74 | + const kernelSource = function() {}; |
| 75 | + const masterSettings = {}; |
| 76 | + const kernel = gpu.createKernelMap(subKernels, kernelSource, masterSettings); |
| 77 | + assert.equal(source, kernelSource.toString()); |
| 78 | + assert.notEqual(settings, masterSettings); |
| 79 | + assert.equal(gpu.canvas, 'canvas'); |
| 80 | + assert.equal(gpu.context, 'context'); |
| 81 | + assert.equal(settings.functions, gpu.functions); |
| 82 | + assert.equal(settings.nativeFunctions, gpu.nativeFunctions); |
| 83 | + assert.equal(settings.gpu, gpu); |
| 84 | + assert.equal(settings.validate, true); |
| 85 | + assert.deepEqual(kernel.subKernels, [ |
| 86 | + { |
| 87 | + name: 'bob', |
| 88 | + source: bob.toString(), |
| 89 | + property: 0 |
| 90 | + }, |
| 91 | + { |
| 92 | + name: 'tom', |
| 93 | + source: tom.toString(), |
| 94 | + property: 1 |
| 95 | + } |
| 96 | + ]); |
| 97 | +}); |
0 commit comments