Merge branch 'paulvanbrenk-fix-1695'

- Merges #1710 from @paulvanbrenk
- Fixes #1695
This commit is contained in:
Gregg Van Hove
2019-05-20 17:09:46 -07:00
2 changed files with 15 additions and 1 deletions

View File

@@ -90,4 +90,18 @@ describe("toBeCloseTo", function() {
result = matcher.compare(1.23, 1.234);
expect(result.pass).toBe(true);
});
it("handles edge cases with rounding", function () {
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
result;
// these cases resulted in false negatives in version of V8
// included in Node.js 12 and Chrome 74 (and Edge Chromium)
result = matcher.compare(4.030904708957288, 4.0309, 5);
expect(result.pass).toBe(true);
result = matcher.compare(4.82665525779431,4.82666, 5);
expect(result.pass).toBe(true);
result = matcher.compare(-2.82665525779431, -2.82666, 5);
expect(result.pass).toBe(true);
});
});

View File

@@ -26,7 +26,7 @@ getJasmineRequireObj().toBeCloseTo = function() {
var maxDelta = Math.pow(10, -precision) / 2;
return {
pass: Math.round(delta * pow) / pow <= maxDelta
pass: Math.round(delta * pow) <= maxDelta * pow
};
}
};