2021-12-28 14:02:29 +00:00
|
|
|
import assertionWrapper from './assertion-wrapper.js'
|
2019-11-24 03:29:24 +00:00
|
|
|
|
2021-12-28 14:02:29 +00:00
|
|
|
const NEAR_ZERO = 5e-6 // 0.000005, Firefox fails at higher levels of precision.
|
2019-11-24 03:29:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks that the supplied values are equal with a high though not absolute degree of precision.
|
|
|
|
* @param {Float} actual
|
|
|
|
* @param {Float} expected
|
|
|
|
* @param {string} message
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function almostEquals (actual, expected, message) {
|
2021-12-28 14:02:29 +00:00
|
|
|
message = message || (actual + ' did not equal ' + expected)
|
|
|
|
const result = Math.abs(actual - expected) < NEAR_ZERO
|
|
|
|
return { result, message, actual, expected }
|
2019-11-24 03:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {external:chai} _chai
|
|
|
|
* @param {external:chai_utils} utils
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function setAssertionMethods (_chai, utils) {
|
2021-12-28 14:02:29 +00:00
|
|
|
const wrap = assertionWrapper(_chai, utils)
|
2019-11-24 03:29:24 +00:00
|
|
|
|
2021-12-28 14:02:29 +00:00
|
|
|
assert.almostEquals = wrap(almostEquals)
|
2019-11-24 03:29:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 14:02:29 +00:00
|
|
|
export default setAssertionMethods
|