mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-30 01:34:26 +02:00
final tree compare test coverage, yayness
This commit is contained in:
parent
f8fec430be
commit
1a846bbad3
2 changed files with 28 additions and 6 deletions
|
@ -87,6 +87,32 @@ describe('Tree Compare', function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('compares only master with hash agnostic and asserts', function() {
|
||||||
|
var jugglingGoal = require('../src/levels/mixed/jugglingCommits').level.goalTreeString;
|
||||||
|
testMethod(
|
||||||
|
{
|
||||||
|
compareOnlyMasterHashAgnosticWithAsserts: true,
|
||||||
|
'goalAsserts': {
|
||||||
|
'master': [
|
||||||
|
function(data) {
|
||||||
|
return data.C2 > data.C3;
|
||||||
|
},
|
||||||
|
function(data) {
|
||||||
|
return data.C2 > data.C1;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
jugglingGoal,
|
||||||
|
{
|
||||||
|
// level solved with a bunch of extra dangling commits
|
||||||
|
'%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C3%27%27%22%2C%22id%22%3A%22master%22%7D%2C%22newImage%22%3A%7B%22target%22%3A%22C2%22%2C%22id%22%3A%22newImage%22%7D%2C%22caption%22%3A%7B%22target%22%3A%22C3%22%2C%22id%22%3A%22caption%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%2C%22C3%22%3A%7B%22parents%22%3A%5B%22C2%22%5D%2C%22id%22%3A%22C3%22%7D%2C%22C3%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C3%27%22%7D%2C%22C2%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%22%7D%2C%22C2%27%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%27%22%7D%2C%22C2%27%27%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%27%27%22%7D%2C%22C2%27%5E4%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%27%5E4%22%7D%2C%22C3%27%27%22%3A%7B%22parents%22%3A%5B%22C2%27%5E4%22%5D%2C%22id%22%3A%22C3%27%27%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22master%22%2C%22id%22%3A%22HEAD%22%7D%7D': true,
|
||||||
|
// level with the number of hashes being equal when we want more
|
||||||
|
'%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C3%27%5E7%22%2C%22id%22%3A%22master%22%7D%2C%22newImage%22%3A%7B%22target%22%3A%22C2%22%2C%22id%22%3A%22newImage%22%7D%2C%22caption%22%3A%7B%22target%22%3A%22C3%22%2C%22id%22%3A%22caption%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%2C%22C3%22%3A%7B%22parents%22%3A%5B%22C2%22%5D%2C%22id%22%3A%22C3%22%7D%2C%22C3%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C3%27%22%7D%2C%22C2%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%22%7D%2C%22C2%27%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%27%22%7D%2C%22C2%27%27%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%27%27%22%7D%2C%22C2%27%5E4%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%27%5E4%22%7D%2C%22C3%27%27%22%3A%7B%22parents%22%3A%5B%22C2%27%5E4%22%5D%2C%22id%22%3A%22C3%27%27%22%7D%2C%22C3%27%27%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C3%27%27%27%22%7D%2C%22C2%27%5E5%22%3A%7B%22parents%22%3A%5B%22C3%27%27%27%22%5D%2C%22id%22%3A%22C2%27%5E5%22%7D%2C%22C2%27%5E6%22%3A%7B%22parents%22%3A%5B%22C3%27%27%27%22%5D%2C%22id%22%3A%22C2%27%5E6%22%7D%2C%22C2%27%5E7%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%27%5E7%22%7D%2C%22C3%27%5E4%22%3A%7B%22parents%22%3A%5B%22C2%27%5E7%22%5D%2C%22id%22%3A%22C3%27%5E4%22%7D%2C%22C3%27%5E5%22%3A%7B%22parents%22%3A%5B%22C2%27%5E7%22%5D%2C%22id%22%3A%22C3%27%5E5%22%7D%2C%22C3%27%5E6%22%3A%7B%22parents%22%3A%5B%22C2%27%5E7%22%5D%2C%22id%22%3A%22C3%27%5E6%22%7D%2C%22C3%27%5E7%22%3A%7B%22parents%22%3A%5B%22C2%27%5E7%22%5D%2C%22id%22%3A%22C3%27%5E7%22%7D%2C%22C3%27%5E8%22%3A%7B%22parents%22%3A%5B%22C2%27%5E7%22%5D%2C%22id%22%3A%22C3%27%5E8%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22master%22%2C%22id%22%3A%22HEAD%22%7D%7D': false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,6 @@ TreeCompare.evalAsserts = function(tree, assertsPerBranch) {
|
||||||
_.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);
|
||||||
|
|
||||||
console.log('EVAL ASSETS was', result);
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,7 +140,6 @@ TreeCompare.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
||||||
// * go to the branch given by the key
|
// * go to the branch given by the key
|
||||||
// * traverse upwards, storing the amount of hashes on each in the data object
|
// * traverse upwards, storing the amount of hashes on each in the data object
|
||||||
// * then come back and perform functions on data
|
// * then come back and perform functions on data
|
||||||
console.log('doing asserts on', branchName);
|
|
||||||
|
|
||||||
if (!tree.branches[branchName]) {
|
if (!tree.branches[branchName]) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -153,19 +150,18 @@ TreeCompare.evalAssertsOnBranch = function(tree, branchName, asserts) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('data is', data);
|
|
||||||
var result = true;
|
var result = true;
|
||||||
_.each(asserts, function(assert) {
|
_.each(asserts, function(assert) {
|
||||||
try {
|
try {
|
||||||
result = result && assert(data);
|
result = result && assert(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.err(err);
|
console.warn('error during assert', err);
|
||||||
|
console.log(err);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue