Skip to content

Commit

Permalink
Improvements to helpers.almostWhole (#6120)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored and simonbrunel committed Mar 19, 2019
1 parent 390a8d7 commit 4941aa0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/core.helpers.js
Expand Up @@ -71,7 +71,7 @@ module.exports = function() {
};
helpers.almostWhole = function(x, epsilon) {
var rounded = Math.round(x);
return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
return ((rounded - epsilon) <= x) && ((rounded + epsilon) >= x);
};
helpers.max = function(array) {
return array.reduce(function(max, value) {
Expand Down
4 changes: 4 additions & 0 deletions test/specs/core.helpers.tests.js
Expand Up @@ -46,6 +46,8 @@ describe('Core helper tests', function() {
it('should correctly determine if a numbers are essentially whole', function() {
expect(helpers.almostWhole(0.99999, 0.0001)).toBe(true);
expect(helpers.almostWhole(0.9, 0.0001)).toBe(false);
expect(helpers.almostWhole(1234567890123, 0.0001)).toBe(true);
expect(helpers.almostWhole(1234567890123.001, 0.0001)).toBe(false);
});

it('should generate integer ids', function() {
Expand Down Expand Up @@ -81,6 +83,8 @@ describe('Core helper tests', function() {
expect(helpers._decimalPlaces('1')).toBe(undefined);
expect(helpers._decimalPlaces('')).toBe(undefined);
expect(helpers._decimalPlaces(undefined)).toBe(undefined);
expect(helpers._decimalPlaces(12345678.1234)).toBe(4);
expect(helpers._decimalPlaces(1234567890.1234567)).toBe(7);
});

it('should get an angle from a point', function() {
Expand Down

0 comments on commit 4941aa0

Please sign in to comment.