From 4941aa0217ea1cd7029863d08b52fc59aa918af1 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 19 Mar 2019 03:42:41 -0700 Subject: [PATCH] Improvements to helpers.almostWhole (#6120) --- src/core/core.helpers.js | 2 +- test/specs/core.helpers.tests.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 7922747dee9..52c8aea68a8 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -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) { diff --git a/test/specs/core.helpers.tests.js b/test/specs/core.helpers.tests.js index a075c0e8d85..1f2bc29d5a1 100644 --- a/test/specs/core.helpers.tests.js +++ b/test/specs/core.helpers.tests.js @@ -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() { @@ -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() {