Skip to content

Commit

Permalink
LibJS: Add tests for %TypedArray%.prototype.toReversed
Browse files Browse the repository at this point in the history
  • Loading branch information
beesaferoot committed Jun 30, 2022
1 parent bbde673 commit 5535af6
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,55 @@ const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array];

test("length is 0", () => {
TYPED_ARRAYS.forEach(T => {
expect(T.prototype.reverse).toHaveLength(0);
expect(T.prototype.toReversed).toHaveLength(0);
});

BIGINT_TYPED_ARRAYS.forEach(T => {
expect(T.prototype.toReverse).toHaveLength(0);
expect(T.prototype.toReversed).toHaveLength(0);
});
});

describe("basic functionality", () => {
test("Odd length array", () => {
TYPED_ARRAYS.forEach(T => {
const array = new T([1, 2, 3]);
expect(array.reverse()).toEqual([3, 2, 1]);
expect(array).toEqual([3, 2, 1]);

expect(array.toReversed()).toEqual([3, 2, 1]);
expect(array).toEqual([1, 2, 3]);
});

BIGINT_TYPED_ARRAYS.forEach(T => {
const array = new T([1n, 2n, 3n]);
expect(array.reverse()).toEqual([3n, 2n, 1n]);
expect(array).toEqual([3n, 2n, 1n]);
expect(array.toReversed()).toEqual([3n, 2n, 1n]);
expect(array).toEqual([1n, 2n, 3n]);
});
});

test("Even length array", () => {
TYPED_ARRAYS.forEach(T => {
const array = new T([1, 2]);
expect(array.reverse()).toEqual([2, 1]);
expect(array).toEqual([2, 1]);
expect(array.toReversed()).toEqual([2, 1]);
expect(array).toEqual([1, 2]);
});

BIGINT_TYPED_ARRAYS.forEach(T => {
const array = new T([1n, 2n]);
expect(array.reverse()).toEqual([2n, 1n]);
expect(array).toEqual([2n, 1n]);
expect(array.toReversed()).toEqual([2n, 1n]);
expect(array).toEqual([1n, 2n]);
});
});

test("Empty array", () => {
TYPED_ARRAYS.forEach(T => {
const array = new T([]);
expect(array.reverse()).toEqual([]);
expect(array.toReversed()).toEqual([]);
expect(array).toEqual([]);
});

BIGINT_TYPED_ARRAYS.forEach(T => {
const array = new T([]);
expect(array.reverse()).toEqual([]);
expect(array.toReversed()).toEqual([]);
expect(array).toEqual([]);
});
});
});
});

0 comments on commit 5535af6

Please sign in to comment.