UNPKG

deep-copy-diagnostics

Version:

Ultra-fast definitive testing for deep copies and deep copy algorithms

130 lines (101 loc) 3.58 kB
const {deepEquivalent} = require("../deep-equivalent.js"); function claim(b, message) { if(b) console.log(`\u2713 ${message} is true`) else console.log(`\u2639 ${message} is false: should be true`) console.log(deepEquivalent.message) } console.log('------------------------------------------------------------------') function test_1() { console.log('test_1') const buffer_x = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,]).buffer const buffer_y = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]).buffer const x = { a: new Uint8Array(buffer_x), b: new Uint8Array(buffer_x, 2,3), c:new Uint8Array(buffer_x, 4,5), d: new Uint16Array(buffer_x, 2,4), e: new Int16Array(buffer_x, 2,4), f: new Uint32Array(buffer_x, 4,4), g: new Int32Array(buffer_x, 4,4), h: new Float32Array(buffer_x, 4,4), //i: new Float64Array([buffer_x, 8,8]), j: new DataView(buffer_x, 2,4) } const y = { a: new Uint8Array(buffer_y), b: new Uint8Array(buffer_y, 2,3), c:new Uint8Array(buffer_y, 4,5), d: new Uint16Array(buffer_y, 2,4), e: new Int16Array(buffer_y, 2,4), f: new Uint32Array(buffer_y, 4,4), g: new Int32Array(buffer_y, 4,4), h: new Float32Array(buffer_y, 4,4), //i: new Float64Array(buffer_y, 8,8), j: new DataView(buffer_y, 2,4) } claim(deepEquivalent(x,y), 'deepEquivalent(x,y)') } test_1() console.log('------------------------------------------------------------------') function test_DataView() { console.log('test_DataView') const buffer = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]).buffer const x = { a: new DataView(buffer, 2,3), } const y = { a: new DataView(buffer,2,3), } claim(!deepEquivalent(x,y), '!deepEquivalent(x,y)') } test_DataView() console.log('------------------------------------------------------------------') function test_Uint8Array() { console.log('test_Uint8Array') const buffer = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]).buffer const x = { a: new Uint8Array(buffer), } const y = { a: new Uint8Array(buffer), } claim(!deepEquivalent(x,y), '!deepEquivalent(x,y)') } test_Uint8Array() console.log('------------------------------------------------------------------') function test_Int8Array() { console.log('test_Int8Array') const buffer = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]).buffer const x = { a: new Int8Array(buffer, 2,3), } const y = { a: new Int8Array(buffer,2,3), } claim(!deepEquivalent(x,y), '!deepEquivalent(x,y)') } test_Int8Array() console.log('------------------------------------------------------------------') function test_2() { console.log('test_2') const buffer = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]).buffer const buffer2 = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]).buffer const x = { a: new Set([buffer]), b: new Uint32Array(buffer) } const y = { a: new Set([buffer2]), b: new Uint32Array(buffer) } claim(!deepEquivalent(x,y), '!deepEquivalent(x,y)') } test_2()