-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequalz.spec.ts
94 lines (72 loc) · 2.02 KB
/
equalz.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { _equalz, equalz } from "./equalz.js";
test("literal", () => {
expect(equalz(5, 5)).toBe(true);
});
test("same reference", () => {
const o = {};
expect(equalz(o, o)).toBe(true);
});
test("non standard", () => {
const a = Buffer.from("");
const b = Buffer.from("");
expect(equalz(a, b)).toBe(true);
expect(_equalz(a, b)).toBe(true);
const c = Buffer.from("hello");
const d = Buffer.from("world");
expect(equalz(c, d)).toBe(false);
expect(_equalz(c, d)).toBe(false);
});
test("different standards", () => {
const a = new String();
const b = new Date();
expect(equalz(a, b)).toBe(false);
expect(_equalz(a, b)).toBe(false);
});
test("array", () => {
const a = [1, 2, 3];
const b = [1, 2, 3];
expect(equalz(a, b)).toBe(true);
expect(_equalz(a, b)).toBe(true);
const c = [1, 2, 3];
const d = [1, 1, 1];
expect(equalz(c, d)).toBe(false);
expect(_equalz(c, d)).toBe(false);
});
test("object", () => {
const a = {};
const b = {};
expect(equalz(a, b)).toBe(true);
expect(_equalz(a, b)).toBe(true);
const c = { a: 1 };
const d = { a: 1 };
expect(equalz(c, d)).toBe(true);
expect(_equalz(c, d)).toBe(true);
const e = { a: 1 };
const f = { a: 1, b: 2 };
expect(equalz(e, f)).toBe(false);
expect(_equalz(e, f)).toBe(false);
});
test("dates", () => {
const c = new Date(0);
const d = new Date(9);
expect(equalz(c, d)).toBe(false);
expect(_equalz(c, d)).toBe(false);
const e = new Date(0);
const f = new Date(0);
expect(equalz(e, f)).toBe(true);
expect(_equalz(e, f)).toBe(true);
});
test("deep object", () => {
const c = { a: 1, d: { c: 5 } };
const d = { a: 1, d: { c: 5 } };
expect(equalz(c, d)).toBe(true);
expect(_equalz(c, d)).toBe(true);
const e = { a: 1, d: { c: 5 } };
const f = { a: 1, d: { c: 6 } };
expect(_equalz(e, f)).toBe(false);
expect(_equalz(e, f)).toBe(false);
const g = { a: 1, d: { c: new Date(0) } };
const h = { a: 1, d: { c: new Date(1) } };
expect(equalz(g, h)).toBe(false);
expect(_equalz(g, h)).toBe(false);
});