Skip to content

Commit

Permalink
Tests for assert.epsilon failing on NaN
Browse files Browse the repository at this point in the history
Tests to make sure assert.epsilon fails when either the epsilon or
actual arguments are NaN. Added a different failure message for the case
that epsilon is NaN.
  • Loading branch information
James Gibson committed Nov 6, 2014
1 parent ec0442c commit f5cec76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/assert/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ for (var key in messages) {
}

assert.epsilon = function (eps, actual, expected, message) {
if (isNaN(actual) || Math.abs(actual - expected) > eps) {
if (isNaN(eps)) {
assert.fail(actual, expected, message || "cannot compare {actual} with {expected} \u00B1 NaN");
} else if (isNaN(actual) || Math.abs(actual - expected) > eps) {
assert.fail(actual, expected, message || "expected {expected} \u00B1"+ eps +", but was {actual}");
}
};
Expand Down
6 changes: 6 additions & 0 deletions test/assert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ vows.describe('vows/assert').addBatch({
},
"`epsilon`": function() {
assert.epsilon(1e-5, 0.1+0.2, 0.3);
assert.throws(function() {
assert.epsilon(1e-5, NaN, 0.3);
});
assert.throws(function() {
assert.epsilon(NaN, 1.0, 1.0);
});
},
"`match`": function () {
assert.match("hello world", /^[a-z]+ [a-z]+$/);
Expand Down

0 comments on commit f5cec76

Please sign in to comment.