A QUnit plugin for asserting numerical comparisons like greater than, less than, etc.
JavaScript HTML
Latest commit 512118e Oct 2, 2016 @JamesMGreene v1.1.0
Permalink
Failed to load latest commit information.
test First cut. v1.0.0 Mar 23, 2015
.gitignore First cut. v1.0.0 Mar 23, 2015
.jshintrc
.travis.yml Updated TravisCI to use new container infrastructure Sep 30, 2015
Gruntfile.js First cut. v1.0.0 Mar 23, 2015
LICENSE
README.md Updated README badges to use the correct projects Oct 2, 2016
package.json v1.1.0 Oct 2, 2016
qunit-assert-compare.js Update assertion context for QUnit v1.15.0+ Oct 2, 2016

README.md

Build Status NPM version

qunit-assert-compare

A QUnit plugin for asserting numerical comparisons like greater than, less than, etc.

QUnit numerical comparison assertion plugin

This plugin for QUnit adds a handful of custom assertion methods to test for various numerical comparison situations:

  • eq: equal to
  • neq: not equal to
  • lt: less than
  • lte: less than or equal to
  • gt: greater than
  • gte: greater than or equal to
  • compare: sorting-style comparisons

Usage

assert.eq(num1, num2, message);
assert.neq(num1, num2, message);
assert.lt(num1, num2, message);
assert.lte(num1, num2, message);
assert.gt(num1, num2, message);
assert.gte(num1, num2, message);
assert.compare(num1, num2, expected, message);

Where:

  • num1: The lefthand operand
  • num2: The righthand operand
  • message: Optional message, same as for other assertions
  • expected: [ONLY used for assert.compare!] A sorting-style return value for the numerical comparison:
    • -1 (less than)
    • 0 (equal to)
    • 1 (greater than)

Examples

module('Example module')

test('Example unit test', function(assert) {
  assert.eq(2, 2);
  assert.neq(-2, 2);
  assert.lt(-2, 2);
  assert.lte(2, 2);
  assert.gt(2, -2);
  assert.gte(2, 2);

  assert.compare(-2, 2, -1);
});

For more examples, refer to the unit tests.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

License

Copyright (c) 2015-2016 James M. Greene Licensed under the MIT license.