it('should have no hooks registered', done => { Parse.Hooks.getFunctions().then( res => { expect(res.constructor).toBe(Array.prototype.constructor); done(); }, err => { jfail(err); done(); } ); });
/** * * @desc Splits an array into smaller arrays. * Number of elements in one small chunk is given by `part` * * @param {Number[]} array - The array to split into chunks * @param {Number} part - elements in one chunk * * @returns {Number[]} An array of smaller chunks */ splitArray(array, part) { const result = []; for (let i = 0; i < array.length; i += part) { result.push(new array.constructor(array.buffer, i * 4 + array.byteOffset, part)); } return result; }
validate(categories: CategoryDto[], args: ValidationArguments) { if (categories === null || categories === undefined ) { return true; } if (categories.constructor !== Array) { return false; } if (categories.length > ArticleConstants.MAX_CATEGORY_COUNT) { return false; } const validator = new Validator(); for (const category of categories) { if (!validator.isInt(category.id)) { return false; } } return true; }
describe('mse', () => { test('should return the same array if an array are passed', () => { const collection = zeros(10); const temp = toArray(collection); expect(collection.prototype).toBe(temp.prototype); }); test('should return an array if object is passed', () => { const collection = { name: 'Steve Jobs', alive: false, }; const temp = toArray(collection); expect(temp.constructor).toBe(Float32Array); expect(temp.length).toBe(Object.keys(collection).length); }); });
function testReturn(mode, context, canvas) { const gpu = new GPU({ mode }); const originalKernel = gpu.createKernel(function(a) { return a[this.thread.x] + 1; }, { canvas, context, output: [6], precision: 'unsigned', pipeline: true, }); const a = [1, 2, 3, 4, 5, 6]; const expected = new Float32Array([2, 3, 4, 5, 6, 7]); const originalResult = originalKernel(a); assert.equal(originalResult.constructor.name, 'GLTextureUnsigned'); const kernelString = originalKernel.toString(a); const newResult = new Function('return ' + kernelString)()({ context })(a); assert.deepEqual(newResult.toArray(), expected); gpu.destroy(); }
function testArrayWithoutTypeDefined(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return this.thread.x; }) .setOutput([10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.x]; }) .setOutput([10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Float32Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
function testArray3D2(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return [this.thread.x, this.thread.x * this.thread.y * this.thread.z]; }) .setOutput([10, 10, 10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.z][this.thread.y][this.thread.x]; }) .setArgumentTypes({ value: 'Array3D(2)' }) .setOutput([10, 10, 10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
function testArray1D3(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return [this.thread.x, this.thread.x + 1, this.thread.x + 2]; }) .setOutput([10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.x]; }) .setArgumentTypes({ value: 'Array1D(3)' }) .setOutput([10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
function testArrayWithTypeDefined(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return this.thread.x; }) .setOutput([10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.x]; }) .setArgumentTypes({ value: 'Array' }) .setOutput([10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Float32Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
function testArray1D2(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return [this.thread.x, this.thread.x + 1]; }) .setOutput([10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.x]; }) .setArgumentTypes({ value: 'Array1D(2)' }) .setOutput([10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
validate(tags: TagDto[], args: ValidationArguments) { if (tags === null || tags === undefined ) { return true; } if (tags.constructor !== Array) { return false; } if (tags.length > ArticleConstants.MAX_TAG_COUNT) { return false; } const validator = new Validator(); for (const tag of tags) { if (!validator.isInt(tag.id)) { return false; } } return true; }
function testArray3D3(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return [this.thread.x, this.thread.y, this.thread.z]; }) .setOutput([10, 10, 10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.z][this.thread.y][this.thread.x]; }) .setArgumentTypes({ value: 'Array3D(3)' }) .setOutput([10, 10, 10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
it('should have no triggers registered', done => { Parse.Hooks.getTriggers().then( res => { expect(res.constructor).toBe(Array.prototype.constructor); done(); }, err => { jfail(err); done(); } ); });
function testArray2D3(mode) { const gpu = new GPU({ mode }); const texture = ( gpu.createKernel(function() { return [this.thread.x, this.thread.y, this.thread.x * this.thread.y]; }) .setOutput([10, 10]) .setPipeline(true) .setPrecision('single') )(); const expected = texture.toArray(); const kernel = gpu.createKernel(function(value) { return value[this.thread.y][this.thread.x]; }) .setArgumentTypes({ value: 'Array2D(3)' }) .setOutput([10, 10]) .setPipeline(false) .setPrecision('single'); assert.notEqual(texture.constructor, Array); assert.equal(expected.constructor, Array); assert.deepEqual(kernel(texture), expected); assert.deepEqual(kernel(expected), expected); gpu.destroy(); }
function testReturn(mode, context, canvas) { const gpu = new GPU({ mode }); const originalKernel = gpu.createKernel(function(a) { return a[this.thread.x] + 1; }, { canvas, context, output: [6], precision: 'single', pipeline: true, }); const a = [1, 2, 3, 4, 5, 6]; const expected = new Float32Array([2, 3, 4, 5, 6, 7]); const originalResult = originalKernel(a); assert.equal(originalResult.constructor.name, 'GLTextureFloat'); const kernelString = originalKernel.toString(a); const newResult = new Function('return ' + kernelString)()({ context })(a); assert.deepEqual(newResult.toArray(), expected); gpu.destroy(); }