Skip to content

Commit

Permalink
Added #approximately(value, delta, description) for doing assertions …
Browse files Browse the repository at this point in the history
…on results of operations with numbers.
  • Loading branch information
titarenko committed Sep 21, 2012
1 parent dd81e18 commit c364d07
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
13 changes: 13 additions & 0 deletions lib/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit c364d07

Please sign in to comment.