UNPKG

deep-copy-diagnostics

Version:

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

139 lines (125 loc) 3.53 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"); // `Err #7 source${path} = source${xSeenPath} but target${path} != target${xSeenPath}` const x = {a:{b:{c:1}}} const y = {a:{b:{c:1}}} x.a.b.d = x.a y.a.b.d = x.a //{} claim(!deepEquivalent(x,y), '!deepEquivalent(x,y)') } test_1(); console.log('-----------------------------------------------------------------'); function test_2() { console.log("Test 2"); const x = {} x.a = {} x.a.a = x const y = {} y.a = {} y.a.a = {} y.a.a.a = y claim(!deepEquivalent(x,y),'!deepEquivalent') } test_2(); console.log('-----------------------------------------------------------------'); function test_3() { console.log("Test 3"); // `Err #8 source${path} = source${xSeenPath} but target${path} = target${ySeenPath}` const x = {a:{b:{c:+Infinity}}} const y = {a:{b:{c:+Infinity}}} x.a.b.d = x.a y.a.b.d = y claim(!deepEquivalent(x,y),'!deepEquivalent(x,y)') } test_3(); console.log('-----------------------------------------------') function test_Circular() { console.log("Test test_Circular"); const x = {a:{b:{c:1}}} const y = {a:{b:{c:1}}} x.a.b.d = x y.a.b.d = x claim(!deepEquivalent(x,y),'!deepEquivalent(x,y)') } test_Circular(); console.log('-----------------------------------------------') function test_Circularb() { console.log("Test test_Circularb"); const x = {a:{b:{c:1}}} const y = {a:{b:{c:1}}} x.a.b.d = x y.a.b.d = y claim(deepEquivalent(x,y),'deepEquivalent(x,y)') } test_Circularb(); console.log('-----------------------------------------------') function test_Duplicate() { console.log("Test test_Duplicate"); // `Err #7 source${path} = source${xSeenPath} but target${path} != target${xSeenPath}` const x = {} const y = {} x.a = {} x.a.a = {} x.a.a.a = {} x.b = {} x.b.b = {} x.b.b.b = x.a.a.a y.a = {} y.a.a = {} y.a.a.a = {} y.b = {} y.b.b = {} y.b.b.b = {} claim(!deepEquivalent(x,y),'!deepEquivalent(x,y)') } test_Duplicate(); console.log('-----------------------------------------------') function test_Circle_In_Map() { console.log("test_Circle_In_Map"); const ax = {a:1} const bx = {b:2} const cx = {c:2} const x = new Map() x.set(ax,bx) x.set(bx,ax) const ay = {a:1} const by = {b:2} const cy = {c:2} const y = new Map() x.set(ax,bx) x.set(bx,ax) y.set(ay,by) y.set(by,cy) claim(!deepEquivalent(x,y),'!deepEquivalent(x,y)') } test_Circle_In_Map(); console.log('-----------------------------------------------') function test_Circle_In_Map_Set() { console.log("test_Circle_In_Map_Set"); const ax = {a:1} const bx = {b:2} const cx = {c:2} const x = {p:new Set([ax,bx,cx]), q:new Map([[cx,bx]])} const ay = {a:1} const by = {b:2} const cy = {c:2} const y = {p:new Set([ay,by,cy]), q:new Map([[cy,ay]])} claim(!deepEquivalent(x,y),'!deepEquivalent(x,y)') } test_Circle_In_Map_Set();