This plugin for QUnit adds close
and notClose
assertion methods
to test that a number is approximately equal (or not) to an expected number, within a given tolerance.
assert.close(actual, expected, maxDifference, message);
assert.notClose(actual, expected, minDifference, message);
Where:
maxDifference
: the maximum inclusive difference allowed (tolerance) between theactual
andexpected
numbersminDifference
: the minimum exclusive difference allowed (tolerance) between theactual
andexpected
numbersactual
,expected
,message
: The usual
test('Example unit test', function(assert) {
assert.close(3.141, Math.PI, 0.001);
assert.notClose(3.1, Math.PI, 0.001);
}
For more examples, refer to the unit tests.