"use strict";

var _tape = _interopRequireDefault(require("tape"));

var _decimals = require("./decimals");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(0, _tape.default)('cleanDecimalInput', t => {
  const cleanWithoutLimits = (0, _decimals.getCleanDecimalWithLimits)({
    maxLenBefore: undefined,
    maxLenAfter: undefined
  });
  const results = [['000', '0'], ['0.0', '0.0'], ['0.010', '0.010'], ['00.132', '0.132'], ['00123', '123'], ['0.1.32', '0.132'], ['abc.2342', '.2342'], ['1.2342', '1.2342'], ['01.2342', '1.2342'], ['01.-2*(*&@#(&$342', '1.2342'], ['+', '']];
  results.forEach(([input, output]) => {
    t.equal((0, _decimals.cleanDecimalInput)(input), output, "input ".concat(input, " should equal ").concat(output));
    t.equal(cleanWithoutLimits(input), output, 'should work with other FN too');
  });
  t.end();
});
(0, _tape.default)('getCleanDecimalWithLimits', t => {
  const maxLenBefore = (0, _decimals.getCleanDecimalWithLimits)({
    maxLenBefore: 3
  });
  t.equal(maxLenBefore('1234567.23432'), '123.23432');
  t.equal(maxLenBefore('0.23432'), '0.23432');
  t.equal(maxLenBefore('.'), '.');
  t.equal(maxLenBefore('.23'), '.23');
  t.equal(maxLenBefore('23.'), '23.');
  const maxLenAfter = (0, _decimals.getCleanDecimalWithLimits)({
    maxLenAfter: 2
  });
  t.equal(maxLenAfter('1234567.23432'), '1234567.23');
  t.equal(maxLenAfter('0.23432'), '0.23');
  t.equal(maxLenAfter('.'), '.');
  t.equal(maxLenAfter('.23'), '.23');
  t.equal(maxLenAfter('23.'), '23.');
  const both = (0, _decimals.getCleanDecimalWithLimits)({
    maxLenBefore: 4,
    maxLenAfter: 2
  });
  t.equal(both('1234567.23432'), '1234.23');
  t.equal(both('0.23432'), '0.23');
  t.equal(both('.'), '.');
  t.equal(both('.23'), '.23');
  t.equal(both('23.'), '23.');
  t.end();
});
(0, _tape.default)('roundToDecimal', t => {
  const input = [[45.96030533583161, 46.0], [100, 100], [22342.22242, 22342.2]];
  input.forEach(([start, expected]) => {
    t.equal((0, _decimals.roundToDecimal)(start, 1), expected, "".concat(start, " should be ").concat(expected));
  });
  t.end();
});
(0, _tape.default)('roundToPrecision', t => {
  const input = [[null, 3, 0], [undefined, 3, 0], [0, 3, 0], [NaN, 3, 0], [45.96030533583161, 1, 46], [45.96030533583161, 2, 46], [100, 3, 100], [1323.3, 5, 1323.3], [22342.22242, 1, 22342], [22342.22242, 2, 22342], [22342.22242, 3, 22342], [22342.22242, 4, 22342], [22342.22242, 5, 22342], [22342.22242, 6, 22342.2], [22342.22242, 7, 22342.22]];
  input.forEach(([start, precision, expected]) => {
    t.equal((0, _decimals.roundToPrecision)(start, precision), expected, "".concat(start, " should be ").concat(expected));
  });
  t.end();
});