compare-functions
Version:
Functions to check equality for variouse criterea
80 lines (78 loc) • 2.36 kB
JavaScript
const cmp = require("./index");
const test = require('tape');
test("strict",t=>{
t.plan(3);
const v1 = null;
const v2 = undefined;
t.equal(v1==v2,true,"== equal");
t.equal(v1===v2,false,"=== equal");
t.equal(cmp.strict(v1,v2),false,"Strict");
});
test("asString",t=>{
t.plan(2);
const v1 = {
a:1
};
const v2 = {
b:2
};
t.equal(cmp.asString(v1,v2),true,"asString");
t.equal(cmp.strict(v1,v2),false,"strict");
});
test("functionSource",t=>{
t.plan(4);
const v1 = ()=>6;
const v2 = ()=>6;
t.equal(cmp.functionSource(5,5),false,"Not functions");
t.equal(cmp.functionSource(v1,v2),true,"Differnent functions, same source");
t.equal(cmp.strict(5,5),true,"Not functions: strict");
t.equal(cmp.strict(v1,v2),false,"Differnent functions, same source: strict");
});
test("setContent",t=>{
t.plan(5);
const v1 = new Set([1,2,3]);
const v2 = new Set([3,2,1]);
const v3 = new Set([3,2]);
t.equal(cmp.setContent(5,5),false,"Not sets");
t.equal(cmp.setContent(v1,v2),true,"Different order");
t.equal(cmp.setContent(v2,v3),false,"Entry count");
t.equal(cmp.strict(5,5),true,"Not sets: strict");
t.equal(cmp.strict(v1,v2),false,"Different order: strict");
});
test("mapContent",t=>{
t.plan(5);
const v1 = new Map([
["a",1,],
["b",2,],
["c",3,],
]);
const v2 = new Map([
["b",2,],
["c",3,],
["a",1,],
]);
const v3 = new Map([
["b",2,],
["c",3,],
]);
t.equal(cmp.mapContent(5,5),false,"Not maps");
t.equal(cmp.mapContent(v1,v2),true,"Different order");
t.equal(cmp.mapContent(v2,v3),false,"Entry count");
t.equal(cmp.strict(5,5),true,"Not maps: strict");
t.equal(cmp.strict(v1,v2),false,"Different order: strict");
});
test("near",t=>{
t.plan(7);
const v1 = 5;
const v2 = 5.5;
const v3 = 6;
const v4 = 6.1;
const near = cmp.near(1);
t.equal(cmp.near(1,v1,v2),true,"Well in range");
t.equal(cmp.near(1,v1,v3),true,"Edge of range");
t.equal(cmp.near(1,v1,v4),false,"Outside range");
t.equal(near(v1,v2),true,"Well in range: curried");
t.equal(near(v1,v3),true,"Edge of range: curried");
t.equal(near(v1,v4),false,"Outside range: curried");
t.equal(cmp.strict(v1,v2),false,"Strict");
});