eq

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/others/eq

说明

比较两个值是否全等(NaN === NaN)

用法

eq.example.ts
eq.test.ts
import { eq } from "./ddzy/utility/others/eq";
// ? 基本类型值
const s1 = [100, 100];
const p1 = eq(s1[0], s1[1]);
console.log(p1);
console.log('----------------');
// ? 引用类型值, 指向不同的内存地址
const s2 = [{}, {}];
const p2 = eq(s2[0], s2[1]);
console.log(p2);
console.log('------------------');
// ? 引用类型值, 指向相同的内存地址
const o3 = {};
const s3 = [o3, o3];
const p3 = eq(s3[0], s3[1]);
console.log(p3);
console.log('-------------------');
// ? 都为NaN, 也是相等
const s4 = [NaN, NaN];
const p4 = eq(s4[0], s4[1]);
console.log(p4);
import { eq } from "../../utility/others/eq";
describe('eq tests: ', () => {
test('eq should return true or false when receive two basic value that equals', () => {
const received = [100, 100];
const expected = true;
const result = eq(received[0], received[1]);
expect(result).toBe(expected);
});
test('eq should return false when receive two object but point at different memory', () => {
const received = [{}, {}];
const expected = false;
const result = eq(received[0], received[1]);
expect(result).toBe(expected);
});
test('eq should return true when receive two object point at same memory', () => {
const obj = {};
const received = [obj, obj];
const expected = true;
const result = eq(received[0], received[1]);
expect(result).toBe(expected);
});
test('eq should return true when receive two NaN value', () => {
const received = [NaN, NaN];
const expected = true;
const result = eq(received[0], received[1]);
expect(result).toBe(expected);
});
});