diff --git a/examples/runner.js b/examples/runner.js index 9355955..3c1dc69 100644 --- a/examples/runner.js +++ b/examples/runner.js @@ -50,4 +50,16 @@ test('Point#add()', function(){ point.should.respondTo('add'); }); +test('Math#sin()', function(){ + Math.sin(12).should.be.approximately(-0.5365, 1e-3); +}); + +test('Math#cos()', function(){ + Math.cos(0).should.not.be.approximately(10, 1e-3); +}); + +test('Math#log()', function(){ + Math.log(10).should.be.approximately(10, 1e-3); +}); + console.log(); \ No newline at end of file diff --git a/lib/should.js b/lib/should.js index f603a35..fa7a4f0 100644 --- a/lib/should.js +++ b/lib/should.js @@ -321,6 +321,19 @@ Assertion.prototype = { return this; }, + /** + * Assert within value +- delta (inclusive). + * + * @param {Number} value + * @param {Number} delta + * @param {String} description + * @api public + */ + + approximately: function(value, delta, description) { + return this.within(value - delta, value + delta, description); + }, + /** * Assert typeof. *