Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A QUnit plugin for asserting that a number is approximately equal (or not) to an expected number, within a given tolerance.
JavaScript HTML
tag: v1.0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
.jshintrc
.mailmap
.travis.yml
AUTHORS.txt
Gruntfile.js
MIT-LICENSE.txt
README.md
package.json
qunit-assert-close.js

README.md

Build Status NPM version

QUnit Close assertion plugin

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.

Usage

assert.close(actual, expected, maxDifference, message);
assert.notClose(actual, expected, minDifference, message);

Where:

  • maxDifference: the maximum inclusive difference allowed (tolerance) between the actual and expected numbers
  • minDifference: the minimum exclusive difference allowed (tolerance) between the actual and expected numbers
  • actual, expected, message: The usual

Example

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.

Something went wrong with that request. Please try again.