1'use strict'; 2 3require('../common'); 4const assert = require('assert'); 5 6function makeBlock(f) { 7 const args = Array.prototype.slice.call(arguments, 1); 8 return function() { 9 return f.apply(this, args); 10 }; 11} 12 13const equalArrayPairs = [ 14 [new Uint8Array(1e5), new Uint8Array(1e5)], 15 [new Uint16Array(1e5), new Uint16Array(1e5)], 16 [new Uint32Array(1e5), new Uint32Array(1e5)], 17 [new Uint8ClampedArray(1e5), new Uint8ClampedArray(1e5)], 18 [new Int8Array(1e5), new Int8Array(1e5)], 19 [new Int16Array(1e5), new Int16Array(1e5)], 20 [new Int32Array(1e5), new Int32Array(1e5)], 21 [new Float32Array(1e5), new Float32Array(1e5)], 22 [new Float64Array(1e5), new Float64Array(1e5)], 23 [new Float32Array([+0.0]), new Float32Array([+0.0])], 24 [new Uint8Array([1, 2, 3, 4]).subarray(1), new Uint8Array([2, 3, 4])], 25 [new Uint16Array([1, 2, 3, 4]).subarray(1), new Uint16Array([2, 3, 4])], 26 [new Uint32Array([1, 2, 3, 4]).subarray(1, 3), new Uint32Array([2, 3])], 27 [new ArrayBuffer(3), new ArrayBuffer(3)], 28 [new SharedArrayBuffer(3), new SharedArrayBuffer(3)], 29]; 30 31const looseEqualArrayPairs = [ 32 [new Float32Array([+0.0]), new Float32Array([-0.0])], 33 [new Float64Array([+0.0]), new Float64Array([-0.0])], 34]; 35 36const notEqualArrayPairs = [ 37 [new ArrayBuffer(3), new SharedArrayBuffer(3)], 38 [new Int16Array(256), new Uint16Array(256)], 39 [new Int16Array([256]), new Uint16Array([256])], 40 [new Float64Array([+0.0]), new Float32Array([-0.0])], 41 [new Uint8Array(2), new Uint8Array(3)], 42 [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])], 43 [new Uint8ClampedArray([300, 2, 3]), new Uint8Array([300, 2, 3])], 44 [new Uint16Array([2]), new Uint16Array([3])], 45 [new Uint16Array([0]), new Uint16Array([256])], 46 [new Int16Array([0]), new Uint16Array([256])], 47 [new Int16Array([-256]), new Uint16Array([0xff00])], // same bits 48 [new Int32Array([-256]), new Uint32Array([0xffffff00])], // ditto 49 [new Float32Array([0.1]), new Float32Array([0.0])], 50 [new Float32Array([0.1]), new Float32Array([0.1, 0.2])], 51 [new Float64Array([0.1]), new Float64Array([0.0])], 52 [new Uint8Array([1, 2, 3]).buffer, new Uint8Array([4, 5, 6]).buffer], 53 [ 54 new Uint8Array(new SharedArrayBuffer(3)).fill(1).buffer, 55 new Uint8Array(new SharedArrayBuffer(3)).fill(2).buffer, 56 ], 57 [new ArrayBuffer(2), new ArrayBuffer(3)], 58 [new SharedArrayBuffer(2), new SharedArrayBuffer(3)], 59 [new ArrayBuffer(2), new SharedArrayBuffer(3)], 60 [ 61 new Uint8Array(new ArrayBuffer(3)).fill(1).buffer, 62 new Uint8Array(new SharedArrayBuffer(3)).fill(2).buffer, 63 ], 64]; 65 66equalArrayPairs.forEach((arrayPair) => { 67 // eslint-disable-next-line no-restricted-properties 68 assert.deepEqual(arrayPair[0], arrayPair[1]); 69 assert.deepStrictEqual(arrayPair[0], arrayPair[1]); 70}); 71 72looseEqualArrayPairs.forEach((arrayPair) => { 73 // eslint-disable-next-line no-restricted-properties 74 assert.deepEqual(arrayPair[0], arrayPair[1]); 75 assert.throws( 76 makeBlock(assert.deepStrictEqual, arrayPair[0], arrayPair[1]), 77 assert.AssertionError 78 ); 79}); 80 81notEqualArrayPairs.forEach((arrayPair) => { 82 assert.throws( 83 // eslint-disable-next-line no-restricted-properties 84 makeBlock(assert.deepEqual, arrayPair[0], arrayPair[1]), 85 assert.AssertionError 86 ); 87 assert.throws( 88 makeBlock(assert.deepStrictEqual, arrayPair[0], arrayPair[1]), 89 assert.AssertionError 90 ); 91}); 92