mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
* add placeholder for apply function * added apply function * add test coverage for apply utility * stylsitic name change in apply source code * stylistic format change to test * improved description of function parameters * moved the apply function to the public matrix functions * update location and reference of unit test * fixed function reference paths in apply for location in function * changed path to apply in apply.test * make apply a typed function, update unit test * added typing error test to coverage * remove apply.test.js from the utils test function * added transform function for apply * add unit test for apply.transform.js
24 lines
919 B
JavaScript
24 lines
919 B
JavaScript
const assert = require('assert')
|
|
const math = require('../../../src/main')
|
|
|
|
const sum = math.sum
|
|
const apply = math.expression.transform.apply
|
|
|
|
describe('apply.transform', function () {
|
|
it('should apply a function to the rows of a matrix with one based indices', function () {
|
|
assert.deepStrictEqual(apply([[1, 2], [3, 4]], 1, sum), [4, 6])
|
|
})
|
|
|
|
it('should apply a function to the columns of a matrix with one based indices', function () {
|
|
assert.deepStrictEqual(apply([[1, 2], [3, 4]], 2, sum), [3, 7])
|
|
})
|
|
|
|
it('should throw an error if the dimension is below the range for one based indices', function () {
|
|
assert.throws(function () { apply([[1, 2], [3, 4]], 0, sum) }, /Index out of range/)
|
|
})
|
|
|
|
it('should throw an error if the dimension is above the range for one based indices', function () {
|
|
assert.throws(function () { apply([[1, 2], [3, 4]], 3, sum) }, /Index out of range/)
|
|
})
|
|
})
|