From 9cca46958cb6a37cd73d1e30f0ce265797786e2c Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 25 May 2021 08:44:46 -0700 Subject: [PATCH] test(TypedArrays): add tests for getPointerArray --- test/_utils.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/_utils.js b/test/_utils.js index ea26716e..7e93043b 100644 --- a/test/_utils.js +++ b/test/_utils.js @@ -13,6 +13,38 @@ describe('utils', function() { describe('typed-arrays', function() { + describe('#.getPointerArray', function() { + var validatePointerArrayConstructor = function (min, max, expectedCtor) { + it(`returns ${expectedCtor} for ${min}`, () => { + assert.strictEqual(typed.getPointerArray(min), expectedCtor); + }); + it(`returns ${expectedCtor} for ${(max - min) / 2}`, () => { + assert.strictEqual(typed.getPointerArray((max - min) / 2), expectedCtor); + }); + it(`returns ${expectedCtor} for ${max}`, () => { + assert.strictEqual(typed.getPointerArray(max), expectedCtor); + }); + }; + + describe('returns Uint8Array for capacity <= Math.pow(2, 8)', function() { + validatePointerArrayConstructor(0, Math.pow(2, 8), Uint8Array); + }); + + describe('returns Uint16Array for Math.pow(2, 8) < capacity <= Math.pow(2, 16)', function() { + validatePointerArrayConstructor(Math.pow(2, 8) + 1, Math.pow(2, 16), Uint16Array); + }); + + describe('returns Uint32Array for Math.pow(2, 16) < capacity <= Math.pow(2, 32)', function() { + validatePointerArrayConstructor(Math.pow(2, 16) + 1, Math.pow(2, 32), Uint32Array); + }); + + describe('throws error for capacity > Math.pow(2, 32)', function() { + assert.throws(function() { + typed.getPointerArray(Math.pow(2, 32) + 1); + }, /Pointer Array of size > 4294967295 is not supported/); + }); + }); + describe('#.getMinimalRepresentation', function() { it('should return the correct type.', function() {