mathjs/test/unit-tests/expression/transform/utils/lastDimToZeroBase.test.js
Josef Wittmann 928a950f02
Remove Duplication (#2093)
* Remove customString duplication in Node

* Extract last dimension change in transform

* Add unit tests to lastDimToZeroBase

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2021-01-31 11:13:51 +01:00

52 lines
1.6 KiB
JavaScript

import assert from 'assert'
import math from '../../../../../src/defaultInstance.js'
import { lastDimToZeroBase } from '../../../../../src/expression/transform/utils/lastDimToZeroBase.js'
describe('lastDimToZeroBase', function () {
it('should not alter args with length !== 2', function () {
let args = []
assert.deepStrictEqual(lastDimToZeroBase(args), args)
args = [[1, 2]]
assert.deepStrictEqual(lastDimToZeroBase(args), args)
args = [1, 2, 3]
assert.deepStrictEqual(lastDimToZeroBase(args), args)
})
it('should only alter args, if first argument is a collection', function () {
let args = [1, 2]
assert.deepStrictEqual(lastDimToZeroBase(args), args)
args = [[1, 2], 2]
assert.notDeepStrictEqual(lastDimToZeroBase(args), args)
args = [math.matrix([1, 2]), 2]
assert.notDeepStrictEqual(lastDimToZeroBase(args), args)
})
it('should not alter args, if second argument is not number or big number', function () {
const args = [[1, 2], false]
assert.deepStrictEqual(lastDimToZeroBase(args), args)
})
it('should work for numbers', function () {
const args = [[1, 2], 1]
const expected = [[1, 2], 0]
assert.deepStrictEqual(lastDimToZeroBase(args), expected)
})
it('should work for big numbers', function () {
const args = [[1, 2], math.bignumber(1)]
const expected = [[1, 2], math.bignumber(0)]
assert.deepStrictEqual(lastDimToZeroBase(args), expected)
})
it('should not mutate input', function () {
const args = [[3, 2], 1]
const initialArgs = args.slice()
lastDimToZeroBase(args)
assert.deepStrictEqual(args, initialArgs)
})
})