mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
WOOHOOOOOOO assertion engine complete. Issue #28 this is crazy
This commit is contained in:
parent
e4b82fd653
commit
f9cdc32fcb
5 changed files with 51 additions and 1096 deletions
|
@ -6310,7 +6310,6 @@ var Level = Sandbox.extend({
|
||||||
} else if (this.level.compareOnlyMasterHashAgnostic) {
|
} else if (this.level.compareOnlyMasterHashAgnostic) {
|
||||||
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
||||||
} else if (this.level.compareOnlyMasterHashAgnosticWithAsserts) {
|
} else if (this.level.compareOnlyMasterHashAgnosticWithAsserts) {
|
||||||
console.log('doing it this way');
|
|
||||||
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
||||||
solved = solved && this.treeCompare.evalAsserts(
|
solved = solved && this.treeCompare.evalAsserts(
|
||||||
current,
|
current,
|
||||||
|
@ -9104,12 +9103,13 @@ TreeCompare.prototype.compareBranchesWithinTreesHashAgnostic = function(treeA, t
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.evalAsserts = function(tree, assertsPerBranch) {
|
TreeCompare.prototype.evalAsserts = function(tree, assertsPerBranch) {
|
||||||
|
|
||||||
var result = true;
|
var result = true;
|
||||||
_.each(assertsPerBranch, function(asserts, branchName) {
|
_.each(assertsPerBranch, function(asserts, branchName) {
|
||||||
result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
|
result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
|
||||||
}, this);
|
}, this);
|
||||||
return true;
|
|
||||||
|
console.log('EVAL ASSETS was', result);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
||||||
|
@ -9126,10 +9126,12 @@ TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var queue = [branchName.target];
|
var branch = tree.branches[branchName];
|
||||||
|
var queue = [branch.target];
|
||||||
var data = {};
|
var data = {};
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
var commitRef = queue.pop();
|
var commitRef = queue.pop();
|
||||||
|
console.log(commitRef);
|
||||||
data[this.getBaseRef(commitRef)] = this.getNumHashes(commitRef);
|
data[this.getBaseRef(commitRef)] = this.getNumHashes(commitRef);
|
||||||
|
|
||||||
queue = queue.concat(tree.commits[commitRef].parents);
|
queue = queue.concat(tree.commits[commitRef].parents);
|
||||||
|
@ -9188,11 +9190,15 @@ TreeCompare.prototype.getRecurseCompareHashAgnostic = function(treeA, treeB) {
|
||||||
|
|
||||||
// some buildup functions
|
// some buildup functions
|
||||||
var getStrippedCommitCopy = _.bind(function(commit) {
|
var getStrippedCommitCopy = _.bind(function(commit) {
|
||||||
|
if (!commit) { return {}; }
|
||||||
return _.extend(
|
return _.extend(
|
||||||
{},
|
{},
|
||||||
commit,
|
commit,
|
||||||
{id: this.getBaseRef(commit.id)
|
{
|
||||||
});
|
id: this.getBaseRef(commit.id),
|
||||||
|
parents: null
|
||||||
|
}
|
||||||
|
);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
var isEqual = function(commitA, commitB) {
|
var isEqual = function(commitA, commitB) {
|
||||||
|
@ -9219,8 +9225,9 @@ TreeCompare.prototype.getRecurseCompare = function(treeA, treeB, options) {
|
||||||
// we loop through each parent ID. we sort the parent ID's beforehand
|
// we loop through each parent ID. we sort the parent ID's beforehand
|
||||||
// so the index lookup is valid. for merge commits this will duplicate some of the
|
// so the index lookup is valid. for merge commits this will duplicate some of the
|
||||||
// checking (because we aren't doing graph search) but it's not a huge deal
|
// checking (because we aren't doing graph search) but it's not a huge deal
|
||||||
var allParents = _.unique(commitA.parents.concat(commitB.parents));
|
var maxNumParents = Math.max(commitA.parents.length, commitB.parents.length);
|
||||||
_.each(allParents, function(pAid, index) {
|
_.each(_.range(maxNumParents), function(index) {
|
||||||
|
var pAid = commitA.parents[index];
|
||||||
var pBid = commitB.parents[index];
|
var pBid = commitB.parents[index];
|
||||||
|
|
||||||
// if treeA or treeB doesn't have this parent,
|
// if treeA or treeB doesn't have this parent,
|
||||||
|
@ -18898,10 +18905,10 @@ require.define("/levels/mixed/3.js",function(require,module,exports,__dirname,__
|
||||||
},
|
},
|
||||||
"startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}",
|
"startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}",
|
||||||
"compareOnlyMasterHashAgnosticWithAsserts": true,
|
"compareOnlyMasterHashAgnosticWithAsserts": true,
|
||||||
"asserts": {
|
"goalAsserts": {
|
||||||
"master": [
|
"master": [
|
||||||
function(data) {
|
function(data) {
|
||||||
return data.C2 === data.C3 + 1;
|
return data.C2 > data.C3;
|
||||||
},
|
},
|
||||||
function(data) {
|
function(data) {
|
||||||
return data.C2 > data.C1;
|
return data.C2 > data.C1;
|
||||||
|
@ -22798,12 +22805,13 @@ TreeCompare.prototype.compareBranchesWithinTreesHashAgnostic = function(treeA, t
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.evalAsserts = function(tree, assertsPerBranch) {
|
TreeCompare.prototype.evalAsserts = function(tree, assertsPerBranch) {
|
||||||
|
|
||||||
var result = true;
|
var result = true;
|
||||||
_.each(assertsPerBranch, function(asserts, branchName) {
|
_.each(assertsPerBranch, function(asserts, branchName) {
|
||||||
result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
|
result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
|
||||||
}, this);
|
}, this);
|
||||||
return true;
|
|
||||||
|
console.log('EVAL ASSETS was', result);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
||||||
|
@ -22820,10 +22828,12 @@ TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var queue = [branchName.target];
|
var branch = tree.branches[branchName];
|
||||||
|
var queue = [branch.target];
|
||||||
var data = {};
|
var data = {};
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
var commitRef = queue.pop();
|
var commitRef = queue.pop();
|
||||||
|
console.log(commitRef);
|
||||||
data[this.getBaseRef(commitRef)] = this.getNumHashes(commitRef);
|
data[this.getBaseRef(commitRef)] = this.getNumHashes(commitRef);
|
||||||
|
|
||||||
queue = queue.concat(tree.commits[commitRef].parents);
|
queue = queue.concat(tree.commits[commitRef].parents);
|
||||||
|
@ -22882,11 +22892,15 @@ TreeCompare.prototype.getRecurseCompareHashAgnostic = function(treeA, treeB) {
|
||||||
|
|
||||||
// some buildup functions
|
// some buildup functions
|
||||||
var getStrippedCommitCopy = _.bind(function(commit) {
|
var getStrippedCommitCopy = _.bind(function(commit) {
|
||||||
|
if (!commit) { return {}; }
|
||||||
return _.extend(
|
return _.extend(
|
||||||
{},
|
{},
|
||||||
commit,
|
commit,
|
||||||
{id: this.getBaseRef(commit.id)
|
{
|
||||||
});
|
id: this.getBaseRef(commit.id),
|
||||||
|
parents: null
|
||||||
|
}
|
||||||
|
);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
var isEqual = function(commitA, commitB) {
|
var isEqual = function(commitA, commitB) {
|
||||||
|
@ -22913,8 +22927,9 @@ TreeCompare.prototype.getRecurseCompare = function(treeA, treeB, options) {
|
||||||
// we loop through each parent ID. we sort the parent ID's beforehand
|
// we loop through each parent ID. we sort the parent ID's beforehand
|
||||||
// so the index lookup is valid. for merge commits this will duplicate some of the
|
// so the index lookup is valid. for merge commits this will duplicate some of the
|
||||||
// checking (because we aren't doing graph search) but it's not a huge deal
|
// checking (because we aren't doing graph search) but it's not a huge deal
|
||||||
var allParents = _.unique(commitA.parents.concat(commitB.parents));
|
var maxNumParents = Math.max(commitA.parents.length, commitB.parents.length);
|
||||||
_.each(allParents, function(pAid, index) {
|
_.each(_.range(maxNumParents), function(index) {
|
||||||
|
var pAid = commitA.parents[index];
|
||||||
var pBid = commitB.parents[index];
|
var pBid = commitB.parents[index];
|
||||||
|
|
||||||
// if treeA or treeB doesn't have this parent,
|
// if treeA or treeB doesn't have this parent,
|
||||||
|
@ -24486,7 +24501,6 @@ var Level = Sandbox.extend({
|
||||||
} else if (this.level.compareOnlyMasterHashAgnostic) {
|
} else if (this.level.compareOnlyMasterHashAgnostic) {
|
||||||
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
||||||
} else if (this.level.compareOnlyMasterHashAgnosticWithAsserts) {
|
} else if (this.level.compareOnlyMasterHashAgnosticWithAsserts) {
|
||||||
console.log('doing it this way');
|
|
||||||
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
||||||
solved = solved && this.treeCompare.evalAsserts(
|
solved = solved && this.treeCompare.evalAsserts(
|
||||||
current,
|
current,
|
||||||
|
@ -32637,10 +32651,10 @@ require.define("/src/levels/mixed/3.js",function(require,module,exports,__dirnam
|
||||||
},
|
},
|
||||||
"startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}",
|
"startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}",
|
||||||
"compareOnlyMasterHashAgnosticWithAsserts": true,
|
"compareOnlyMasterHashAgnosticWithAsserts": true,
|
||||||
"asserts": {
|
"goalAsserts": {
|
||||||
"master": [
|
"master": [
|
||||||
function(data) {
|
function(data) {
|
||||||
return data.C2 === data.C3 + 1;
|
return data.C2 > data.C3;
|
||||||
},
|
},
|
||||||
function(data) {
|
function(data) {
|
||||||
return data.C2 > data.C1;
|
return data.C2 > data.C1;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -103,12 +103,13 @@ TreeCompare.prototype.compareBranchesWithinTreesHashAgnostic = function(treeA, t
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.evalAsserts = function(tree, assertsPerBranch) {
|
TreeCompare.prototype.evalAsserts = function(tree, assertsPerBranch) {
|
||||||
|
|
||||||
var result = true;
|
var result = true;
|
||||||
_.each(assertsPerBranch, function(asserts, branchName) {
|
_.each(assertsPerBranch, function(asserts, branchName) {
|
||||||
result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
|
result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
|
||||||
}, this);
|
}, this);
|
||||||
return true;
|
|
||||||
|
console.log('EVAL ASSETS was', result);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
||||||
|
@ -125,10 +126,12 @@ TreeCompare.prototype.evalAssertsOnBranch = function(tree, branchName, asserts)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var queue = [branchName.target];
|
var branch = tree.branches[branchName];
|
||||||
|
var queue = [branch.target];
|
||||||
var data = {};
|
var data = {};
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
var commitRef = queue.pop();
|
var commitRef = queue.pop();
|
||||||
|
console.log(commitRef);
|
||||||
data[this.getBaseRef(commitRef)] = this.getNumHashes(commitRef);
|
data[this.getBaseRef(commitRef)] = this.getNumHashes(commitRef);
|
||||||
|
|
||||||
queue = queue.concat(tree.commits[commitRef].parents);
|
queue = queue.concat(tree.commits[commitRef].parents);
|
||||||
|
@ -187,11 +190,15 @@ TreeCompare.prototype.getRecurseCompareHashAgnostic = function(treeA, treeB) {
|
||||||
|
|
||||||
// some buildup functions
|
// some buildup functions
|
||||||
var getStrippedCommitCopy = _.bind(function(commit) {
|
var getStrippedCommitCopy = _.bind(function(commit) {
|
||||||
|
if (!commit) { return {}; }
|
||||||
return _.extend(
|
return _.extend(
|
||||||
{},
|
{},
|
||||||
commit,
|
commit,
|
||||||
{id: this.getBaseRef(commit.id)
|
{
|
||||||
});
|
id: this.getBaseRef(commit.id),
|
||||||
|
parents: null
|
||||||
|
}
|
||||||
|
);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
var isEqual = function(commitA, commitB) {
|
var isEqual = function(commitA, commitB) {
|
||||||
|
@ -218,8 +225,9 @@ TreeCompare.prototype.getRecurseCompare = function(treeA, treeB, options) {
|
||||||
// we loop through each parent ID. we sort the parent ID's beforehand
|
// we loop through each parent ID. we sort the parent ID's beforehand
|
||||||
// so the index lookup is valid. for merge commits this will duplicate some of the
|
// so the index lookup is valid. for merge commits this will duplicate some of the
|
||||||
// checking (because we aren't doing graph search) but it's not a huge deal
|
// checking (because we aren't doing graph search) but it's not a huge deal
|
||||||
var allParents = _.unique(commitA.parents.concat(commitB.parents));
|
var maxNumParents = Math.max(commitA.parents.length, commitB.parents.length);
|
||||||
_.each(allParents, function(pAid, index) {
|
_.each(_.range(maxNumParents), function(index) {
|
||||||
|
var pAid = commitA.parents[index];
|
||||||
var pBid = commitB.parents[index];
|
var pBid = commitB.parents[index];
|
||||||
|
|
||||||
// if treeA or treeB doesn't have this parent,
|
// if treeA or treeB doesn't have this parent,
|
||||||
|
|
|
@ -321,7 +321,6 @@ var Level = Sandbox.extend({
|
||||||
} else if (this.level.compareOnlyMasterHashAgnostic) {
|
} else if (this.level.compareOnlyMasterHashAgnostic) {
|
||||||
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
||||||
} else if (this.level.compareOnlyMasterHashAgnosticWithAsserts) {
|
} else if (this.level.compareOnlyMasterHashAgnosticWithAsserts) {
|
||||||
console.log('doing it this way');
|
|
||||||
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
|
||||||
solved = solved && this.treeCompare.evalAsserts(
|
solved = solved && this.treeCompare.evalAsserts(
|
||||||
current,
|
current,
|
||||||
|
|
|
@ -6,10 +6,10 @@ exports.level = {
|
||||||
},
|
},
|
||||||
"startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}",
|
"startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}",
|
||||||
"compareOnlyMasterHashAgnosticWithAsserts": true,
|
"compareOnlyMasterHashAgnosticWithAsserts": true,
|
||||||
"asserts": {
|
"goalAsserts": {
|
||||||
"master": [
|
"master": [
|
||||||
function(data) {
|
function(data) {
|
||||||
return data.C2 === data.C3 + 1;
|
return data.C2 > data.C3;
|
||||||
},
|
},
|
||||||
function(data) {
|
function(data) {
|
||||||
return data.C2 > data.C1;
|
return data.C2 > data.C1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue