]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Improvements to helpers.almostWhole (#6120)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Tue, 19 Mar 2019 10:42:41 +0000 (03:42 -0700)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Tue, 19 Mar 2019 10:42:41 +0000 (11:42 +0100)
src/core/core.helpers.js
test/specs/core.helpers.tests.js

index 7922747dee95d0e2128c2766c978de8349577570..52c8aea68a845e8ab0fbd612a225dbda5fc16aee 100644 (file)
@@ -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) {
index a075c0e8d85ccc96a3566f1953cdefd3f22f81db..1f2bc29d5a16a7824d76b01625cb49815bc8f5ad 100644 (file)
@@ -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() {