cloudboost-tv
Version:
Database Service that does Storage, Search, Real-time and a whole lot more.
124 lines (108 loc) • 3.09 kB
JavaScript
/*!
* Should
* Copyright(c) 2010-2014 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
module.exports = function(should, Assertion) {
/**
* Assert given object is NaN
* @name NaN
* @memberOf Assertion
* @category assertion numbers
* @example
*
* (10).should.not.be.NaN;
* NaN.should.be.NaN;
*/
Assertion.add('NaN', function() {
this.params = { operator: 'to be NaN' };
this.assert(this.obj !== this.obj);
}, true);
/**
* Assert given object is not finite (positive or negative)
*
* @name Infinity
* @memberOf Assertion
* @category assertion numbers
* @example
*
* (10).should.not.be.Infinity;
* NaN.should.not.be.Infinity;
*/
Assertion.add('Infinity', function() {
this.params = { operator: 'to be Infinity' };
this.is.a.Number
.and.not.a.NaN
.and.assert(!isFinite(this.obj));
}, true);
/**
* Assert given number between `start` and `finish` or equal one of them.
*
* @name within
* @memberOf Assertion
* @category assertion numbers
* @param {number} start Start number
* @param {number} finish Finish number
* @param {string} [description] Optional message
* @example
*
* (10).should.be.within(0, 20);
*/
Assertion.add('within', function(start, finish, description) {
this.params = { operator: 'to be within ' + start + '..' + finish, message: description };
this.assert(this.obj >= start && this.obj <= finish);
});
/**
* Assert given number near some other `value` within `delta`
*
* @name approximately
* @memberOf Assertion
* @category assertion numbers
* @param {number} value Center number
* @param {number} delta Radius
* @param {string} [description] Optional message
* @example
*
* (9.99).should.be.approximately(10, 0.1);
*/
Assertion.add('approximately', function(value, delta, description) {
this.params = { operator: 'to be approximately ' + value + " ±" + delta, message: description };
this.assert(Math.abs(this.obj - value) <= delta);
});
/**
* Assert given number above `n`.
*
* @name above
* @alias Assertion#greaterThan
* @memberOf Assertion
* @category assertion numbers
* @param {number} n Margin number
* @param {string} [description] Optional message
* @example
*
* (10).should.be.above(0);
*/
Assertion.add('above', function(n, description) {
this.params = { operator: 'to be above ' + n, message: description };
this.assert(this.obj > n);
});
/**
* Assert given number below `n`.
*
* @name below
* @alias Assertion#lessThan
* @memberOf Assertion
* @category assertion numbers
* @param {number} n Margin number
* @param {string} [description] Optional message
* @example
*
* (0).should.be.above(10);
*/
Assertion.add('below', function(n, description) {
this.params = { operator: 'to be below ' + n, message: description };
this.assert(this.obj < n);
});
Assertion.alias('above', 'greaterThan');
Assertion.alias('below', 'lessThan');
};