All files / src/utils tests.utils.js

94.12% Statements 16/17
100% Branches 7/7
87.5% Functions 7/8
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22    1x   6x   1x   5x 500000x 500000x     5x   1x   1x 5x   500000x  
import weightList from '../weightList';
 
export const defaultTimes = 200;
 
export const genLoop = number => Array(number || defaultTimes).fill();
 
export const defaultLoop = genLoop();
 
export const getTimesGenerated = map => map.reduce((obj, b) => {
  obj[b.id] = ++obj[b.id] || 1;
  return obj;
}, {});
 
export const between = (x, min, max) => x >= min && x <= max;
 
export const diff = (a, b) => Math.abs(a - b);
 
export const calculatePercent = (portion, total, precision = 2) => 
  Number(((portion / total) * 100).toFixed(precision));
 
export const generateItems = (options, times) => genLoop(times).map(() => weightList(options));