From 80fb20fbe782e8f295dcaeb0dc8dcd78d666197d Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Sun, 19 Jul 2020 11:50:17 +0200 Subject: [PATCH] Fix some unit tests failing on IE 11 --- src/function/matrix/diff.js | 21 +++++++------------- test/unit-tests/function/matrix/diff.test.js | 8 +++++--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/function/matrix/diff.js b/src/function/matrix/diff.js index cb02de954..62fe950d9 100644 --- a/src/function/matrix/diff.js +++ b/src/function/matrix/diff.js @@ -3,9 +3,9 @@ import { isInteger } from '../../utils/number' import { isMatrix } from '../../utils/is' const name = 'diff' -const dependencies = ['typed', 'matrix', 'subtract', 'number', 'bignumber'] +const dependencies = ['typed', 'matrix', 'subtract', 'number'] -export const createDiff = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, subtract, number, bignumber }) => { +export const createDiff = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, subtract, number }) => { /** * Create a new matrix or array of the difference between elements of the given array * The optional dim parameter lets you specify the dimension to evaluate the difference of @@ -44,8 +44,9 @@ export const createDiff = /* #__PURE__ */ factory(name, dependencies, ({ typed, * * See Also: * - * Subtract - * PartitionSelect + * sum + * subtract + * partitionSelect * * @param {Array | Matrix} arr An array or matrix * @param {number} dim Dimension @@ -60,7 +61,7 @@ export const createDiff = /* #__PURE__ */ factory(name, dependencies, ({ typed, } }, 'Array | Matrix, number': function (arr, dim) { - if (!isInteger(dim)) throw RangeError('Dimension must be a whole number') + if (!isInteger(dim)) throw new RangeError('Dimension must be a whole number') if (isMatrix(arr)) { return matrix(_recursive(arr.toArray(), dim)) } else { @@ -68,15 +69,7 @@ export const createDiff = /* #__PURE__ */ factory(name, dependencies, ({ typed, } }, 'Array | Matrix, BigNumber': function (arr, dim) { - const maxInt = bignumber(Number.MAX_SAFE_INTEGER) - const minInt = bignumber(Number.MIN_SAFE_INTEGER) - if (dim > maxInt || dim < minInt) throw RangeError('The array does not have more than 2^53 dimensions') - if (!dim.isInt()) throw RangeError('Dimension must be a whole number') - if (isMatrix(arr)) { - return matrix(_recursive(arr.toArray(), number(dim))) - } else { - return _recursive(arr, number(dim)) - } + return this(arr, number(dim)) } }) diff --git a/test/unit-tests/function/matrix/diff.test.js b/test/unit-tests/function/matrix/diff.test.js index 265c8952c..fb50af45b 100644 --- a/test/unit-tests/function/matrix/diff.test.js +++ b/test/unit-tests/function/matrix/diff.test.js @@ -178,9 +178,11 @@ describe('diff', function () { assert.throws(function () { diff(matrix([1, 2, 3, 4]), math.bignumber(0.5)) }, RangeError) assert.throws(function () { diff(matrix([1, 2, 3, 4]), math.bignumber(-0.5)) }, RangeError) - // Unfortunately we will never know if these work properly - assert.throws(function () { diff(matrix([1, 2, 3, 4]), math.bignumber(Number.MAX_SAFE_INTEGER).plus(1)) }, RangeError) - assert.throws(function () { diff(matrix([1, 2, 3, 4]), math.bignumber(Number.MIN_SAFE_INTEGER).minus(1)) }, RangeError) + // Infinity + assert.throws(function () { diff(matrix([1, 2, 3, 4]), Infinity) }, RangeError) + assert.throws(function () { diff(matrix([1, 2, 3, 4]), -Infinity) }, RangeError) + assert.throws(function () { diff(matrix([1, 2, 3, 4]), math.bignumber('Infinity')) }, RangeError) + assert.throws(function () { diff(matrix([1, 2, 3, 4]), math.bignumber('-Infinity')) }, RangeError) }) it('should throw if array is not \'rectangular\'', function () {