Skip to content

Commit 4941aa0

Browse files
benmccannsimonbrunel
authored andcommitted
Improvements to helpers.almostWhole (#6120)
1 parent 390a8d7 commit 4941aa0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/core/core.helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = function() {
7171
};
7272
helpers.almostWhole = function(x, epsilon) {
7373
var rounded = Math.round(x);
74-
return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
74+
return ((rounded - epsilon) <= x) && ((rounded + epsilon) >= x);
7575
};
7676
helpers.max = function(array) {
7777
return array.reduce(function(max, value) {

test/specs/core.helpers.tests.js

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ describe('Core helper tests', function() {
4646
it('should correctly determine if a numbers are essentially whole', function() {
4747
expect(helpers.almostWhole(0.99999, 0.0001)).toBe(true);
4848
expect(helpers.almostWhole(0.9, 0.0001)).toBe(false);
49+
expect(helpers.almostWhole(1234567890123, 0.0001)).toBe(true);
50+
expect(helpers.almostWhole(1234567890123.001, 0.0001)).toBe(false);
4951
});
5052

5153
it('should generate integer ids', function() {
@@ -81,6 +83,8 @@ describe('Core helper tests', function() {
8183
expect(helpers._decimalPlaces('1')).toBe(undefined);
8284
expect(helpers._decimalPlaces('')).toBe(undefined);
8385
expect(helpers._decimalPlaces(undefined)).toBe(undefined);
86+
expect(helpers._decimalPlaces(12345678.1234)).toBe(4);
87+
expect(helpers._decimalPlaces(1234567890.1234567)).toBe(7);
8488
});
8589

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

0 commit comments

Comments
 (0)