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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// Tests the test utilities themselves.
(function() {
load("jstests/aggregation/extras/utils.js");
const verbose = false;
const example = [
{_id: ObjectId("4dc07fedd8420ab8d0d4066d"), pageViews: 5, tags: ["fun", "good"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066e"), pageViews: 7, tags: ["fun", "nasty"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066f"), pageViews: 6, tags: ["nasty", "filthy"]}
];
assert(arrayEq(example, example, verbose));
assert(resultsEq(example, example, verbose));
const exampleDifferentOrder = [
{_id: ObjectId("4dc07fedd8420ab8d0d4066d"), pageViews: 5, tags: ["fun", "good"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066f"), pageViews: 6, tags: ["nasty", "filthy"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066e"), pageViews: 7, tags: ["fun", "nasty"]},
];
assert(resultsEq(exampleDifferentOrder, example, verbose));
assert(resultsEq(example, exampleDifferentOrder, verbose));
assert(!orderedArrayEq(example, exampleDifferentOrder, verbose));
const exampleFewerEntries = [
{_id: ObjectId("4dc07fedd8420ab8d0d4066e"), pageViews: 7, tags: ["fun", "nasty"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066f"), pageViews: 6, tags: ["nasty", "filthy"]}
];
assert(!resultsEq(example, exampleFewerEntries, verbose));
assert(!resultsEq(exampleFewerEntries, example, verbose));
const exampleNoIds = [
{pageViews: 5, tags: ["fun", "good"]},
{pageViews: 7, tags: ["fun", "nasty"]},
{pageViews: 6, tags: ["nasty", "filthy"]}
];
assert(!resultsEq(example, exampleNoIds, verbose));
assert(!resultsEq(exampleNoIds, example, verbose));
const exampleMissingTags = [
{_id: ObjectId("4dc07fedd8420ab8d0d4066d"), pageViews: 5, tags: ["fun"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066e"), pageViews: 7, tags: ["fun", "nasty"]},
{_id: ObjectId("4dc07fedd8420ab8d0d4066f"), pageViews: 6, tags: ["filthy"]}
];
assert(!resultsEq(example, exampleMissingTags, verbose));
assert(!resultsEq(exampleMissingTags, example, verbose));
const exampleDifferentIds = [
{_id: 0, pageViews: 5, tags: ["fun", "good"]},
{_id: 1, pageViews: 7, tags: ["fun", "nasty"]},
{_id: 2, pageViews: 6, tags: ["nasty", "filthy"]}
];
assert(resultsEq(example, exampleDifferentIds));
assert(resultsEq(exampleDifferentIds, example));
// Test using a custom comparator.
assert(customDocumentEq({
left: {a: 1, b: 3},
right: {a: "ignore", b: 3},
verbose: verbose,
valueComparator: (l, r) => {
if (l == "ignore" || r == "ignore") {
return true;
}
return l == r;
}
}));
assert(!customDocumentEq({
left: {a: 1, b: 3},
right: {a: 3, b: 3},
valueComparator: (l, r) => {
if (l == "ignore" || r == "ignore") {
return true;
}
return l == r;
}
}));
// Test using a custom comparator with arrays.
assert(customDocumentEq({
left: {a: [1, 2], b: 3},
right: {a: [2, "ignore"], b: 3},
verbose: verbose,
valueComparator: (l, r) => {
if (l == "ignore" || r == "ignore") {
return true;
}
return l == r;
}
}));
assert(!customDocumentEq({
left: {a: [1, 2], b: 3},
right: {a: [3, "ignore"], b: 3},
verbose: verbose,
valueComparator: (l, r) => {
if (l == "ignore" || r == "ignore") {
return true;
}
return l == r;
}
}));
// Test using a custom comparator with arrays of objects.
assert(customDocumentEq({
left: {a: [{b: 1}, {b: 2}, {b: 3}]},
right: {a: [{b: "ignore"}, {b: 2}, {b: 3}]},
verbose: verbose,
valueComparator: (l, r) => {
if (l == "ignore" || r == "ignore") {
return true;
}
return l == r;
}
}));
assert(!customDocumentEq({
left: {a: [{b: 1}, {b: 2}, {b: 1}]},
right: {a: [{b: "ignore"}, {b: 2}, {b: 3}]},
verbose: verbose,
valueComparator: (l, r) => {
if (l == "ignore" || r == "ignore") {
return true;
}
return l == r;
}
}));
assert(!anyEq(5, [5], verbose));
assert(!anyEq([5], 5, verbose));
assert(!anyEq("5", 5, verbose));
assert(!anyEq(5, "5", verbose));
assert(arrayEq([{c: 6}, [5], [4, 5], 2, undefined, 3, null, 4, 5],
[undefined, null, 2, 3, 4, 5, {c: 6}, [4, 5], [5]],
verbose));
assert(arrayEq([undefined, null, 2, 3, 4, 5, {c: 6}, [4, 5], [5]],
[{c: 6}, [5], [4, 5], 2, undefined, 3, null, 4, 5],
verbose));
}());
|