Skip to content

Commit

Permalink
Merge pull request tj#86 from titarenko/master
Browse files Browse the repository at this point in the history
Added #approximately(value, delta, desc) for comparison of numbers within given precision
  • Loading branch information
tj committed Sep 21, 2012
2 parents dd81e18 + c364d07 commit 58be9b8
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 58be9b8

Please sign in to comment.