Skip to content

Commit

Permalink
Cambio test para que se ejecute discrepances una sola vez por fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Oct 31, 2016
1 parent 609855c commit f3df998
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function getClass(variable) {

function compare(resultArray, a, b, index) {
var diff = discrepances(a[index], b[index]);
// console.log("compare", index, a[index], b[index], diff)
resultArray.push(diff || null);
}

Expand Down Expand Up @@ -76,6 +77,8 @@ function compareArrays(a, b) {
for(var i_ab=0; i_ab<max; ++i_ab){ compare(res, a, b, i_ab); }
if(a.length !== b.length) { rv.length = discrepances(a.length,b.length); }
res.forEach(function(r,index) { if(r) { rv[index] = r; } });
var rrr = rv.length ? {array:rv} : null;
// console.log("compareArrays -> ", rrr)
return rv.length ? {array:rv} : null;
}

Expand Down Expand Up @@ -125,6 +128,7 @@ function isSimpleValue(classType) {

discrepances = function discrepances(a, b){
if(a === b){ return null; }
// console.log("discrepances(", a, b, ")")
var typeA = getType(a);
var typeB = getType(b);
if(typeA === typeB) {
Expand All @@ -139,14 +143,17 @@ discrepances = function discrepances(a, b){
return r;
} else {
if(classA==='Array') {
// console.log("arrays", a, b)
return compareArrays(a, b);
} else if(classA==='Date') {
return compareDates(a, b);
} else if(classA==='Object') {
return compareObjects(a, b);
}
// console.log(" not handled (1)", typeA, a, b)
}
}
// console.log(" not handled (2)", typeA, a, b)
} else {
var r={types:[typeA,typeB]};
if(isSimpleValue(typeA) && isSimpleValue(typeB)) {
Expand Down
14 changes: 9 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ describe("discrepances", function(){
return true;
}
it("fixture: "+JSON.stringify(fixture), function(){
// console.log("RES", JSON4all.stringify(discrepances(fixture.a, fixture.b)));
// console.log("EXP", JSON4all.stringify(fixture.expect));
expect(discrepances(fixture.a, fixture.b)).to.eql(fixture.expect);
expect(JSON.stringify(discrepances(fixture.a, fixture.b))).to.eql(JSON.stringify(fixture.expect));
expect(JSON4all.stringify(discrepances(fixture.a, fixture.b))).to.eql(JSON4all.stringify(fixture.expect));
var expJ = JSON.stringify(fixture.expect);
var expJA = JSON4all.stringify(fixture.expect);
var res = discrepances(fixture.a, fixture.b);
var resJ = JSON.stringify(res);
var resJA = JSON4all.stringify(res);
// console.log("RES", resJA); console.log("EXP", expJA);
expect(res).to.eql(fixture.expect);
expect(resJ).to.eql(expJ);
expect(resJA).to.eql(expJA);
});
});
});

0 comments on commit f3df998

Please sign in to comment.