From 62011dab28b47ef9a24870734775743a82d0a2d0 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 14 Mar 2013 23:55:25 +0100 Subject: [PATCH] Move roughlyEqual into expect.js --- test/expect-0.2.0-ol3/expect.js | 18 ++++++++++++++ test/spec/ol/expect.test.js | 43 +++++++++++++++++++++++++++++++++ test/test-extensions.js | 5 ---- 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 test/spec/ol/expect.test.js diff --git a/test/expect-0.2.0-ol3/expect.js b/test/expect-0.2.0-ol3/expect.js index 58c7049e0e..24fc5d7437 100644 --- a/test/expect-0.2.0-ol3/expect.js +++ b/test/expect-0.2.0-ol3/expect.js @@ -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_. * diff --git a/test/spec/ol/expect.test.js b/test/spec/ol/expect.test.js new file mode 100644 index 0000000000..8c71af21c8 --- /dev/null +++ b/test/spec/ol/expect.test.js @@ -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); + }); + + }); + +}); diff --git a/test/test-extensions.js b/test/test-extensions.js index 333bce0cb9..eeec0751ff 100644 --- a/test/test-extensions.js +++ b/test/test-extensions.js @@ -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); };