Gestalt equality; also export matcherEquals
This commit is contained in:
parent
d36a65d843
commit
e413e86588
21
route.js
21
route.js
|
@ -1041,6 +1041,11 @@ function Routing(exports) {
|
|||
return is_emptyMatcher(this.subscriptions) && is_emptyMatcher(this.advertisements);
|
||||
};
|
||||
|
||||
GestaltLevel.prototype.equals = function (other) {
|
||||
return matcherEquals(this.subscriptions, other.subscriptions)
|
||||
&& matcherEquals(this.advertisements, other.advertisements);
|
||||
};
|
||||
|
||||
function straightGestaltLevelOp(op) {
|
||||
return function (p1, p2) {
|
||||
return new GestaltLevel(op(p1.subscriptions, p2.subscriptions),
|
||||
|
@ -1098,6 +1103,21 @@ function Routing(exports) {
|
|||
return new Gestalt(mls);
|
||||
};
|
||||
|
||||
Gestalt.prototype.equals = function (other) {
|
||||
if (this.metaLevels.length !== other.metaLevels.length) return false;
|
||||
for (var i = 0; i < this.metaLevels.length; i++) {
|
||||
var ls1 = this.metaLevels[i];
|
||||
var ls2 = other.metaLevels[i];
|
||||
if (ls1.length !== ls2.length) return false;
|
||||
for (var j = 0; j < ls1.length; j++) {
|
||||
var p1 = ls1[j];
|
||||
var p2 = ls2[j];
|
||||
if (!p1.equals(p2)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
function simpleGestalt(isAdv, pat, metaLevel, level) {
|
||||
var matcher = compilePattern(true, pat);
|
||||
var l = new GestaltLevel(isAdv ? emptyMatcher : matcher,
|
||||
|
@ -1286,6 +1306,7 @@ function Routing(exports) {
|
|||
exports.projectionToPattern = projectionToPattern;
|
||||
exports.project = project;
|
||||
exports.matcherKeys = matcherKeys;
|
||||
exports.matcherEquals = matcherEquals;
|
||||
exports.prettyMatcher = prettyMatcher;
|
||||
|
||||
exports.GestaltLevel = GestaltLevel;
|
||||
|
|
25
tr.js
25
tr.js
|
@ -101,3 +101,28 @@ dump(r.simpleGestalt(false, "A", 0, 2).label(123).matchValue("A", 2, false));
|
|||
dump(r.simpleGestalt(false, "A", 2, 0).label(123).matchValue("A", 2, false));
|
||||
dump(r.simpleGestalt(false, "A", 2, 1).label(123).matchValue("A", 2, false));
|
||||
dump(r.simpleGestalt(false, "A", 2, 2).label(123).matchValue("A", 2, false));
|
||||
|
||||
dump(r.matcherEquals(mAny, mAAny) === false);
|
||||
dump(r.matcherEquals(mAny, mAny) === true);
|
||||
dump(r.matcherEquals(mAAny, mAAny) === true);
|
||||
dump(r.matcherEquals(r.union(r.compilePattern(r.arrayToSet(['A']), [r.__, 'A']),
|
||||
r.compilePattern(r.arrayToSet(['B']), [r.__, 'B'])),
|
||||
r.union(r.compilePattern(r.arrayToSet(['A']), [r.__, 'A']),
|
||||
r.compilePattern(r.arrayToSet(['B']), [r.__, 'B'])))
|
||||
=== true);
|
||||
dump(r.matcherEquals(r.union(r.compilePattern(r.arrayToSet(['A']), [r.__, 'A']),
|
||||
r.compilePattern(r.arrayToSet(['B']), [r.__, 'B'])),
|
||||
r.union(r.compilePattern(r.arrayToSet(['B']), [r.__, 'B']),
|
||||
r.compilePattern(r.arrayToSet(['A']), [r.__, 'A'])))
|
||||
=== true);
|
||||
|
||||
dump(r.simpleGestalt(false, "A", 0, 0).union(r.simpleGestalt(true, "B", 0, 0))
|
||||
.equals(r.simpleGestalt(false, "A", 0, 0).union(r.simpleGestalt(true, "B", 0, 0)))
|
||||
=== true);
|
||||
dump(r.simpleGestalt(false, "A", 0, 0).union(r.simpleGestalt(true, "B", 0, 0))
|
||||
.equals(r.simpleGestalt(true, "B", 0, 0).union(r.simpleGestalt(false, "A", 0, 0)))
|
||||
=== true);
|
||||
|
||||
dump(r.simpleGestalt(false, "A", 0, 0).union(r.simpleGestalt(true, "B", 0, 0))
|
||||
.equals(r.simpleGestalt(false, "B", 0, 0).union(r.simpleGestalt(true, "A", 0, 0)))
|
||||
=== false);
|
||||
|
|
Loading…
Reference in New Issue