mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
Fix some unit tests failing on IE 11
This commit is contained in:
parent
96330dd347
commit
80fb20fbe7
@ -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))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -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 () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user