Files
openlayers/test/node/expect.js
2021-05-01 10:18:23 -06:00

37 lines
717 B
JavaScript

import expect from 'expect.js';
/**
* Assert value is within some tolerance of a number.
* @param {number} n Number.
* @param {number} tol Tolerance.
* @return {expect.Assertion} The assertion.
*/
expect.Assertion.prototype.roughlyEqual = function (n, tol) {
this.assert(
Math.abs(this.obj - n) <= tol,
function () {
return (
'expected ' +
expect.stringify(this.obj) +
' to be within ' +
tol +
' of ' +
n
);
},
function () {
return (
'expected ' +
expect.stringify(this.obj) +
' not to be within ' +
tol +
' of ' +
n
);
}
);
return this;
};
export default expect;