1 import withDecimalPrecision from './withDecimalPrecision';
3 describe('withDecimalPrecision()', () => {
4 it('returns the same number when the precision is infinity', () => {
5 const list = [2.234, 5, 381712.0001, -1, -1.38, -0.99, -10282.12312];
6 expect(list.map((x) => withDecimalPrecision(x, Infinity))).toEqual(list);
9 it('is equivalent to Math.round when the precision is zero', () => {
10 const list = [2.234, 5, 0, -1, -1.38, -0.99, -10282.12312];
11 expect(list.map((x) => withDecimalPrecision(x, 0))).toEqual(list.map(Math.round));
14 it('returns 0 when the precision is minus infinity', () => {
15 const list = [2.234, 5, 0, -1, -1.38, -0.99, -10282.12312];
16 expect(list.map((x) => withDecimalPrecision(x, -Infinity))).toEqual(list.map(() => 0));
19 it('returns the expected values for some simple cases', () => {
20 const list = [122.234, 5, -0.54, -1, -1.387, 12.4491];
21 expect(list.map((x, i) => withDecimalPrecision(x, i - 2))).toEqual([100, 10, -1, -1, -1.39, 12.449]);