Change toBeCloseTo matcher to be more consistent.

It now calculates and compares a difference, rather than rounding
two separate quantities and testing for their equality.
This commit is contained in:
Dave Burt
2012-07-31 15:03:55 +10:00
parent dad4865fbf
commit 7e04571ec0
4 changed files with 9 additions and 10 deletions

View File

@@ -302,10 +302,7 @@ jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
if (!(precision === 0)) {
precision = precision || 2;
}
var multiplier = Math.pow(10, precision);
var actual = Math.round(this.actual * multiplier);
expected = Math.round(expected * multiplier);
return expected == actual;
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
};
/**