Skip to content

Commit

Permalink
test(TypedArrays): add tests for getPointerArray
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored and Yomguithereal committed May 25, 2021
1 parent 66e494d commit 9cca469
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9cca469

Please sign in to comment.