diff options
Diffstat (limited to 'spec/frontend/lib/utils/common_utils_spec.js')
| -rw-r--r-- | spec/frontend/lib/utils/common_utils_spec.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js index effc446d846..09eb362c77e 100644 --- a/spec/frontend/lib/utils/common_utils_spec.js +++ b/spec/frontend/lib/utils/common_utils_spec.js @@ -959,6 +959,25 @@ describe('common_utils', () => { }); }); + describe('roundDownFloat', () => { + it('Rounds down decimal places of a float number with provided precision', () => { + expect(commonUtils.roundDownFloat(3.141592, 3)).toBe(3.141); + }); + + it('Rounds down a float number to a whole number when provided precision is zero', () => { + expect(commonUtils.roundDownFloat(3.141592, 0)).toBe(3); + expect(commonUtils.roundDownFloat(3.9, 0)).toBe(3); + }); + + it('Rounds down float number to nearest 0, 10, 100, 1000 and so on when provided precision is below 0', () => { + expect(commonUtils.roundDownFloat(34567.14159, -1)).toBeCloseTo(34560); + expect(commonUtils.roundDownFloat(34567.14159, -2)).toBeCloseTo(34500); + expect(commonUtils.roundDownFloat(34567.14159, -3)).toBeCloseTo(34000); + expect(commonUtils.roundDownFloat(34567.14159, -4)).toBeCloseTo(30000); + expect(commonUtils.roundDownFloat(34567.14159, -5)).toBeCloseTo(0); + }); + }); + describe('searchBy', () => { const searchSpace = { iid: 1, |
