Move roughlyEqual into expect.js
This commit is contained in:
@@ -299,6 +299,24 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert value is within _tol_ of _n_.
|
||||
*
|
||||
* @param {Number} n
|
||||
* @param {Number} tol
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Assertion.prototype.roughlyEqual =
|
||||
Assertion.prototype.kindaEqual = function(n, tol) {
|
||||
this.assert(
|
||||
Math.abs(this.obj - n) <= tol
|
||||
, function(){ return 'expected ' + i(this.obj) + ' to be within ' + tol + ' of ' + n }
|
||||
, function(){ return 'expected ' + i(this.obj) + ' not to be within ' + tol + ' of ' + n });
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert string value matches _regexp_.
|
||||
*
|
||||
|
||||
43
test/spec/ol/expect.test.js
Normal file
43
test/spec/ol/expect.test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
goog.provide('ol.test.expect.js');
|
||||
|
||||
|
||||
describe('expect.js', function() {
|
||||
|
||||
describe('roughlyEqual', function() {
|
||||
|
||||
it('can tell the difference between 1 and 3', function() {
|
||||
expect(1).not.to.roughlyEqual(3, 1);
|
||||
});
|
||||
|
||||
it('really can tell the difference between 1 and 3', function() {
|
||||
expect(function() {
|
||||
expect(1).to.roughlyEqual(3, 0.5);
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('kindaEqual', function() {
|
||||
|
||||
it('thinks that 1 ain\'t so different from 2', function() {
|
||||
expect(1).to.kindaEqual(2, 1);
|
||||
});
|
||||
|
||||
it('knows that, like, 1 and 2 would, like, totally dig each other',
|
||||
function() {
|
||||
expect(function() {
|
||||
expect(1).to.kindaEqual(2, 1);
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('roughlyEqual and kindaEqual', function() {
|
||||
|
||||
it('it\'s like they\'re soul mates', function() {
|
||||
expect(expect(0).to.roughlyEqual).to.be(expect(1).to.kindaEqual);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -19,11 +19,6 @@ function waitsFor(condition, message, timeout, callback) {
|
||||
}
|
||||
|
||||
|
||||
expect.Assertion.prototype.roughlyEqual = function(other, tol) {
|
||||
return Math.abs(this.actual - other) <= tol;
|
||||
};
|
||||
|
||||
|
||||
expect.Assertion.prototype.intersectWith = function(other) {
|
||||
return this.obj.intersects(other);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user