Linting: StandardJS for src/, test/; Prettier for types/ (#2544)

* setup linting with eslint-config-standard, prettier

* [autofix] npm run lint -- --fix with new setup

* [manual] fix types/ directory errors

* [manual] fix linting errors in test/ directory

* [manual] fix single linting error in src/

* revert ts-expect-error comment change

* error on .only in mocha tests

* fix test description typo

* move some short objects to single line

* add and gitignore eslintcache

* individually suppress ts any

* set --max-warnings to 0

* extract matrices to constants

* update ts-expect-error comments
This commit is contained in:
Chris Chudzicki 2022-04-29 06:04:01 -04:00 committed by GitHub
parent ad847cc008
commit 13a3d4c198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 4177 additions and 3877 deletions

55
.eslintrc.cjs Normal file
View File

@ -0,0 +1,55 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: ['eslint:recommended'],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
ignorePatterns: ['*.generated.js'],
rules: {},
overrides: [
{
files: ['*.js', '*.cjs', '*.mjs'],
extends: [
'standard'
]
},
{
files: ['*.test.js'],
plugins: ['mocha'],
extends: [
'standard',
'plugin:mocha/recommended'
],
rules: {
'mocha/no-skipped-tests': 'error',
'mocha/no-exclusive-tests': 'error',
'mocha/no-setup-in-describe': 'off',
'mocha/no-identical-title': 'off' // TODO: Remove this
}
},
{
files: ['types/*.ts'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended' // this should come last
],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' }
]
},
plugins: ['@typescript-eslint'],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
project: 'types/tsconfig.json'
}
}
]
}

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ _site
node_modules
.nyc_output
/coverage
.eslintcache
lib
*.generated.js

4
.prettierrc.cjs Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
semi: false,
singleQuote: true,
}

3573
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@
],
"dependencies": {
"@babel/runtime": "^7.17.9",
"@types/mocha": "^9.1.1",
"complex.js": "^2.1.1",
"decimal.js": "^10.3.1",
"escape-latex": "^1.2.0",
@ -42,6 +43,8 @@
"@babel/preset-env": "7.16.11",
"@babel/register": "7.17.7",
"@types/assert": "^1.5.6",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"assert": "2.0.0",
"babel-loader": "8.2.4",
"benchmark": "2.1.4",
@ -49,6 +52,14 @@
"core-js": "3.22.0",
"del": "6.0.0",
"dtslint": "4.2.1",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-mocha": "^10.0.4",
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"expect-type": "^0.13.0",
"expr-eval": "2.0.2",
"fancy-log": "2.0.0",
@ -75,8 +86,8 @@
"numericjs": "1.2.6",
"nyc": "15.1.0",
"pad-right": "0.2.2",
"prettier": "^2.6.2",
"process": "0.11.10",
"standard": "16.0.4",
"sylvester": "0.0.21",
"ts-node": "10.7.0",
"typescript": "4.6.3",
@ -135,7 +146,7 @@
"build:docs": "gulp --gulpfile gulpfile.cjs docs",
"compile": "gulp --gulpfile gulpfile.cjs compile",
"watch": "gulp --gulpfile gulpfile.cjs watch",
"lint": "standard --env=mocha --env=worker",
"lint": "eslint --cache --max-warnings 0 src/ test/ types/",
"format": "npm run lint -- --fix",
"validate:ascii": "gulp --gulpfile gulpfile.cjs validate:ascii",
"test": "npm run test:src && npm run lint",

View File

@ -82,8 +82,8 @@ export function importFactory (typed, load, math, importedFactories) {
} else if (isFactory(value) || name !== undefined) {
const flatName = isFactory(value)
? isTransformFunctionFactory(value)
? (value.fn + '.transform') // TODO: this is ugly
: value.fn
? (value.fn + '.transform') // TODO: this is ugly
: value.fn
: name
// we allow importing the same function twice if it points to the same implementation

View File

@ -32,10 +32,7 @@ export const createBlockNode = /* #__PURE__ */ factory(name, dependencies, ({ Re
if (!isNode(node)) throw new TypeError('Property "node" must be a Node')
if (typeof visible !== 'boolean') throw new TypeError('Property "visible" must be a boolean')
return {
node: node,
visible: visible
}
return { node, visible }
})
}
@ -102,7 +99,7 @@ export const createBlockNode = /* #__PURE__ */ factory(name, dependencies, ({ Re
const block = this.blocks[i]
const node = this._ifNode(callback(block.node, 'blocks[' + i + '].node', this))
blocks[i] = {
node: node,
node,
visible: block.visible
}
}

View File

@ -177,7 +177,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
true: true,
false: false,
null: null,
undefined: undefined
undefined
}
const NUMERIC_CONSTANTS = [
@ -620,10 +620,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
while (state.token === '\n' || state.token === ';') { // eslint-disable-line no-unmodified-loop-condition
if (blocks.length === 0 && node) {
visible = (state.token !== ';')
blocks.push({
node: node,
visible: visible
})
blocks.push({ node, visible })
}
getToken(state)
@ -632,10 +629,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
node.comment = state.comment
visible = (state.token !== ';')
blocks.push({
node: node,
visible: visible
})
blocks.push({ node, visible })
}
}

View File

@ -233,8 +233,8 @@ export const createQr = /* #__PURE__ */ factory(name, dependencies, (
// return matrices
return {
Q: Q,
R: R,
Q,
R,
toString: function () {
return 'Q: ' + this.Q.toString() + '\nR: ' + this.R.toString()
}

View File

@ -43,7 +43,7 @@ export function createSolveValidation ({ DenseMatrix }) {
}
return new DenseMatrix({
data: data,
data,
size: [rows, 1],
datatype: b._datatype
})
@ -64,7 +64,7 @@ export function createSolveValidation ({ DenseMatrix }) {
}
return new DenseMatrix({
data: data,
data,
size: [rows, 1],
datatype: b._datatype
})
@ -86,7 +86,7 @@ export function createSolveValidation ({ DenseMatrix }) {
}
return new DenseMatrix({
data: data,
data,
size: [rows, 1],
datatype: b._datatype
})
@ -109,7 +109,7 @@ export function createSolveValidation ({ DenseMatrix }) {
}
return new DenseMatrix({
data: data,
data,
size: [rows, 1]
})
}
@ -124,7 +124,7 @@ export function createSolveValidation ({ DenseMatrix }) {
}
return new DenseMatrix({
data: data,
data,
size: [rows, 1]
})
}

View File

@ -153,9 +153,6 @@ export const createCsChol = /* #__PURE__ */ factory(name, dependencies, (
})
}
// return L & P
return {
L: L,
P: P
}
return { L, P }
}
})

View File

@ -45,8 +45,5 @@ export function csLeaf (i, j, w, first, maxfirst, prevleaf, ancestor) {
w[ancestor + s] = q
}
}
return {
jleaf: jleaf,
q: q
}
return { jleaf, q }
}

View File

@ -160,10 +160,6 @@ export const createCsLu = /* #__PURE__ */ factory(name, dependencies, ({ abs, di
uvalues.splice(unz, uvalues.length - unz)
uindex.splice(unz, uindex.length - unz)
// return LU factor
return {
L: L,
U: U,
pinv: pinv
}
return { L, U, pinv }
}
})

View File

@ -54,7 +54,7 @@ export const createNthRoots = /* #__PURE__ */ factory(name, dependencies, ({ typ
roots.push(_calculateExactResult[halfPiFactor % 4](r))
continue
}
roots.push(new Complex({ r: r, phi: (arg + 2 * Math.PI * k) / root }))
roots.push(new Complex({ r, phi: (arg + 2 * Math.PI * k) / root }))
}
return roots
}

View File

@ -131,7 +131,7 @@ export const createExpm = /* #__PURE__ */ factory(name, dependencies, ({ typed,
for (let q = 0; q <= k; q++) {
const j = k - q
if (errorEstimate(infNorm, q, j) < eps) {
return { q: q, j: j }
return { q, j }
}
}
}

View File

@ -106,7 +106,7 @@ export const createGamma = /* #__PURE__ */ factory(name, dependencies, ({ typed,
}
const precision = config.precision + (Math.log(n.toNumber()) | 0)
const Big = BigNumber.clone({ precision: precision })
const Big = BigNumber.clone({ precision })
if (n % 2 === 1) {
return n.times(bigFactorial(new BigNumber(n - 1)))

View File

@ -30,7 +30,7 @@ export const createBin = factory(name, dependencies, ({ typed, format }) => {
return format(n, { notation: 'bin' })
},
'number | BigNumber, number': function (n, wordSize) {
return format(n, { notation: 'bin', wordSize: wordSize })
return format(n, { notation: 'bin', wordSize })
}
})
})

View File

@ -30,7 +30,7 @@ export const createHex = factory(name, dependencies, ({ typed, format }) => {
return format(n, { notation: 'hex' })
},
'number | BigNumber, number': function (n, wordSize) {
return format(n, { notation: 'hex', wordSize: wordSize })
return format(n, { notation: 'hex', wordSize })
}
})
})

View File

@ -31,7 +31,7 @@ export const createOct = factory(name, dependencies, ({ typed, format }) => {
return format(n, { notation: 'oct' })
},
'number | BigNumber, number': function (n, wordSize) {
return format(n, { notation: 'oct', wordSize: wordSize })
return format(n, { notation: 'oct', wordSize })
}
})
})

View File

@ -130,7 +130,7 @@ export const createComplexClass = /* #__PURE__ */ factory(name, dependencies, ()
}
if (isNumber(phi)) {
return new Complex({ r: r, phi: phi })
return new Complex({ r, phi })
}
throw new TypeError('Phi is not a number nor an angle unit.')

View File

@ -730,7 +730,7 @@ export const createDenseMatrixClass = /* #__PURE__ */ factory(name, dependencies
// create DenseMatrix
return new DenseMatrix({
data: data,
data,
size: [n],
datatype: this._datatype
})
@ -848,7 +848,7 @@ export const createDenseMatrixClass = /* #__PURE__ */ factory(name, dependencies
// create DenseMatrix
return new DenseMatrix({
data: data,
data,
size: [rows, columns]
})
}

View File

@ -34,8 +34,8 @@ export const createFibonacciHeapClass = /* #__PURE__ */ factory(name, dependenci
FibonacciHeap.prototype.insert = function (key, value) {
// create node
const node = {
key: key,
value: value,
key,
value,
degree: 0
}
// check we have a node in the minimum

View File

@ -326,10 +326,10 @@ export const createSparseMatrixClass = /* #__PURE__ */ factory(name, dependencie
// return matrix
return new SparseMatrix({
values: values,
index: index,
ptr: ptr,
size: size,
values,
index,
ptr,
size,
datatype: matrix._datatype
})
}
@ -931,9 +931,9 @@ export const createSparseMatrixClass = /* #__PURE__ */ factory(name, dependencie
ptr.push(values.length)
// return sparse matrix
return new SparseMatrix({
values: values,
index: index,
ptr: ptr,
values,
index,
ptr,
size: [maxRow - minRow + 1, maxColumn - minColumn + 1]
})
}
@ -1179,9 +1179,9 @@ export const createSparseMatrixClass = /* #__PURE__ */ factory(name, dependencie
ptr.push(values.length)
// return matrix
return new SparseMatrix({
values: values,
index: index,
ptr: ptr,
values,
index,
ptr,
size: [n, 1]
})
}
@ -1327,9 +1327,9 @@ export const createSparseMatrixClass = /* #__PURE__ */ factory(name, dependencie
ptr.push(values.length)
// create SparseMatrix
return new SparseMatrix({
values: values,
index: index,
ptr: ptr,
values,
index,
ptr,
size: [rows, columns]
})
}

View File

@ -368,7 +368,7 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
unit.units.push({
unit: res.unit,
prefix: res.prefix,
power: power
power
})
for (let i = 0; i < BASE_DIMENSIONS.length; i++) {
unit.dimensions[i] += (res.unit.dimensions[i] || 0) * power
@ -538,10 +538,7 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
if (hasOwnProperty(UNITS, str)) {
const unit = UNITS[str]
const prefix = unit.prefixes['']
return {
unit,
prefix
}
return { unit, prefix }
}
for (const name in UNITS) {
@ -555,10 +552,7 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
: undefined
if (prefix !== undefined) {
// store unit, prefix, and value
return {
unit,
prefix
}
return { unit, prefix }
}
}
}
@ -3205,11 +3199,11 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
BASE_UNITS[baseName] = newBaseUnit
newUnit = {
name: name,
name,
value: 1,
dimensions: BASE_UNITS[baseName].dimensions.slice(0),
prefixes: prefixes,
offset: offset,
prefixes,
offset,
base: BASE_UNITS[baseName]
}
@ -3219,11 +3213,11 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
}
} else {
newUnit = {
name: name,
name,
value: defUnit.value,
dimensions: defUnit.dimensions.slice(0),
prefixes: prefixes,
offset: offset
prefixes,
offset
}
// Create a new base if no matching base exists

View File

@ -47,4 +47,4 @@ export function lruQueue (limit) {
map = Object.create(null)
}
}
};
}

View File

@ -338,11 +338,7 @@ export function splitNumber (value) {
exponent++
}
return {
sign: sign,
coefficients: coefficients,
exponent: exponent
}
return { sign, coefficients, exponent }
}
/**

View File

@ -192,7 +192,7 @@ export function canDefineProperty () {
// test needed for broken IE8 implementation
try {
if (Object.defineProperty) {
Object.defineProperty({}, 'x', { get: function () {} })
Object.defineProperty({}, 'x', { get: function () { return null } })
return true
}
} catch (e) {}

View File

@ -3,7 +3,7 @@ import { addDependencies, divideDependencies, piDependencies } from '../../src/e
import { create } from '../../src/core/create.js'
describe('dependencies', function () {
it('should create functions from a collection of dependencies', () => {
it('should create functions from a collection of dependencies', function () {
const { add, divide, pi } = create({
addDependencies,
divideDependencies,
@ -15,7 +15,7 @@ describe('dependencies', function () {
assert.strictEqual(pi, Math.PI)
})
it('should create functions from with config', () => {
it('should create functions with config', function () {
const config = { number: 'BigNumber' }
const { pi } = create({
piDependencies

View File

@ -10,7 +10,7 @@ const {
} = createSnapshotFromFactories(factoriesAny)
describe('mainAny', function () {
it('should export functions', () => {
it('should export functions', function () {
assert.strictEqual(add(2, 3), 5)
assert.strictEqual(sqrt(4), 2)
})
@ -72,22 +72,22 @@ describe('mainAny', function () {
assert.throws(() => { evaluate('SymbolNode') }, /Undefined symbol SymbolNode/)
})
it('should export constants', () => {
it('should export constants', function () {
assert.strictEqual(pi, Math.PI)
})
it('should export physical constants', () => {
it('should export physical constants', function () {
assert.strictEqual(speedOfLight.toString(), '2.99792458e+8 m / s')
})
it('should export type checking functions', () => {
it('should export type checking functions', function () {
assert.strictEqual(isObject({}), true)
assert.strictEqual(isObject(null), false)
assert.strictEqual(isMatrix([]), false)
assert.strictEqual(isMatrix(matrix()), true)
})
it('should export evaluate having functions and constants', () => {
it('should export evaluate having functions and constants', function () {
assert.strictEqual(evaluate('sqrt(4)'), 2)
assert.strictEqual(evaluate('pi'), Math.PI)
assert.strictEqual(evaluate('A[1]', { A: [1, 2, 3] }), 1) // one-based evaluation
@ -103,12 +103,12 @@ describe('mainAny', function () {
assert.strictEqual(typeof evaluate('rationalize'), 'function')
})
it('should export chain with all functions', () => {
it('should export chain with all functions', function () {
assert.strictEqual(chain(2).add(3).done(), 5)
assert.strictEqual(chain('x + 2 * x').simplify().done().toString(), '3 * x')
})
it('should get/set scope variables', () => {
it('should get/set scope variables', function () {
const math = create(all)
const evaluate = math.evaluate
@ -119,7 +119,7 @@ describe('mainAny', function () {
assert.deepStrictEqual(scope, { b: 2 })
})
it('should evaluate assignement and access', () => {
it('should evaluate assignement and access', function () {
const math = create(all)
const evaluate = math.evaluate
@ -130,13 +130,13 @@ describe('mainAny', function () {
assert.deepStrictEqual(scope, { A: [10, 200, 30] })
})
it('should export evaluate having help and embedded docs', () => {
it('should export evaluate having help and embedded docs', function () {
const h = evaluate('help(simplify)')
assert(h.toString().indexOf('Name: simplify') >= 0, true)
})
it('should export reviver', () => {
it('should export reviver', function () {
const json = '{"mathjs":"Complex","re":2,"im":4}'
const c = new Complex(2, 4)

View File

@ -10,7 +10,7 @@ const {
} = createSnapshotFromFactories(factoriesNumber)
describe('mainNumber', function () {
it('should export functions', () => {
it('should export functions', function () {
assert.strictEqual(add(2, 3), 5)
assert.strictEqual(sqrt(4), 2)
})
@ -82,17 +82,17 @@ describe('mainNumber', function () {
assert.throws(() => { evaluate('SymbolNode') }, /Undefined symbol SymbolNode/)
})
it('should export constants', () => {
it('should export constants', function () {
assert.strictEqual(pi, Math.PI)
})
it('should export type checking functions', () => {
it('should export type checking functions', function () {
assert.strictEqual(isObject({}), true)
assert.strictEqual(isObject(null), false)
assert.strictEqual(isNumber('23'), false)
})
it('should export evaluate having functions and constants', () => {
it('should export evaluate having functions and constants', function () {
assert.strictEqual(evaluate('sqrt(4)'), 2)
assert.strictEqual(evaluate('pi'), Math.PI)
@ -107,25 +107,25 @@ describe('mainNumber', function () {
assert.strictEqual(typeof evaluate('rationalize'), 'function')
})
it('should export chain with all functions', () => {
it('should export chain with all functions', function () {
assert.strictEqual(chain(2).add(3).done(), 5)
})
it('derivative should work', () => {
it('derivative should work', function () {
assert.strictEqual(derivative('2x', 'x').toString(), '2')
})
it('simplify should work', () => {
it('simplify should work', function () {
assert.strictEqual(simplify('2x + 3x').toString(), '5 * x')
})
it('should export evaluate having help and embedded docs', () => {
it('should export evaluate having help and embedded docs', function () {
const h = evaluate('help(simplify)')
assert(h.toString().indexOf('Name: simplify') >= 0, true)
})
it('should get/set scope variables', () => {
it('should get/set scope variables', function () {
const math = create(all)
const evaluate = math.evaluate
@ -136,7 +136,7 @@ describe('mainNumber', function () {
assert.deepStrictEqual(scope, { b: 2 })
})
it('doe not support assignement and access right now', () => {
it('doe not support assignement and access right now', function () {
// TODO: implement support for subset in number implementation
assert.throws(function () {
evaluate('A[2]', { A: [10, 20, 30] })
@ -148,7 +148,7 @@ describe('mainNumber', function () {
}, /No "index" implementation available/)
})
it('should export reviver', () => {
it('should export reviver', function () {
const json = '{"mathjs":"Range","start":2,"end":10}'
const r = new Range(2, 10)

View File

@ -305,11 +305,11 @@ const bigwarning = `WARNING: ${knownProblems.size} known errors converted ` +
`\n WARNING: ${knownUndocumented.size} symbols in math are known to ` +
'be undocumented; PLEASE EXTEND the documentation.'
describe(bigwarning + '\n Testing examples from (jsdoc) comments', () => {
describe(bigwarning + '\n Testing examples from (jsdoc) comments', function () {
const allNames = Object.keys(math)
const srcPath = path.resolve(__dirname, '../../src') + '/'
const allDocs = docgenerator.collectDocs(allNames, srcPath)
it("should cover all names (but doesn't yet)", () => {
it("should cover all names (but doesn't yet)", function () {
const documented = new Set(Object.keys(allDocs))
const badUndocumented = allNames.filter(name => {
return !(documented.has(name) ||
@ -330,9 +330,9 @@ describe(bigwarning + '\n Testing examples from (jsdoc) comments', () => {
byCategory[fun.category].push(fun.doc)
}
for (const category in byCategory) {
describe('category: ' + category, () => {
describe('category: ' + category, function () {
for (const doc of byCategory[category]) {
it('satisfies ' + doc.name, () => {
it('satisfies ' + doc.name, function () {
console.log(` Testing ${doc.name} ...`) // can remove once no known failures; for now it clarifies "PLEASE RESOLVE"
const lines = doc.examples
lines.push('//') // modifies doc but OK for test

View File

@ -112,7 +112,7 @@ describe('slu - matrix market', function () {
values: cvalues,
index: cindex,
ptr: cptr,
size: size,
size,
datatype: A._datatype
})
}

View File

@ -19,11 +19,11 @@ describe('tree shaking', function () {
const bundleName = 'treeShakingApp.bundle.js'
const bundleLicenseName = 'treeShakingApp.bundle.js.LICENSE.txt'
before(() => {
before(function () {
cleanup()
})
after(() => {
after(function () {
cleanup()
})

View File

@ -2,7 +2,7 @@ import assert from 'assert'
import math from '../../../src/defaultInstance.js'
describe('config', function () {
it('should allow setting config after having overwritten import', () => {
it('should allow setting config after having overwritten import', function () {
const math2 = math.create()
assert.strictEqual(math2.typeOf(math2.pi), 'number')

View File

@ -238,7 +238,7 @@ describe('import', function () {
return text.toUpperCase()
}
math.import({ foo: foo })
math.import({ foo })
assert(hasOwnProperty(math, 'foo'))
assert.strictEqual(math.foo, foo)
@ -251,7 +251,7 @@ describe('import', function () {
return 'test'
}
math.import({ mean: mean }, { override: true })
math.import({ mean }, { override: true })
assert(hasOwnProperty(math, 'mean'))
assert.strictEqual(math.mean, mean)
@ -259,8 +259,8 @@ describe('import', function () {
assert.strictEqual(math.expression.mathWithTransform.mean, mean)
})
describe('factory', () => {
it('should import a factory function', () => {
describe('factory', function () {
it('should import a factory function', function () {
const math2 = create()
assert.strictEqual(math2.multiplyTest, undefined)
@ -273,7 +273,7 @@ describe('import', function () {
assert.strictEqual(math2.cubeTest(3), 27)
})
it('should import an array with factory functions', () => {
it('should import an array with factory functions', function () {
const math2 = create()
assert.strictEqual(math2.multiplyTest, undefined)
@ -285,7 +285,7 @@ describe('import', function () {
assert.strictEqual(math2.cubeTest(3), 27)
})
it('should not allow nested nested paths in a factory', () => {
it('should not allow nested nested paths in a factory', function () {
const math2 = create()
assert.strictEqual(math2.tools, undefined)
@ -295,7 +295,7 @@ describe('import', function () {
}, /Factory name should not contain a nested path/)
})
it('should import an array with factory functions in the correct order, resolving dependencies', () => {
it('should import an array with factory functions in the correct order, resolving dependencies', function () {
const math2 = create()
assert.strictEqual(math2.multiplyTest, undefined)
@ -308,7 +308,7 @@ describe('import', function () {
assert.strictEqual(math2.cubeTest(3), 27)
})
it('should NOT import factory functions with custom name', () => {
it('should NOT import factory functions with custom name', function () {
// changed since v6
const math2 = create()
@ -328,7 +328,7 @@ describe('import', function () {
assert.strictEqual(math2.cubeTest(3), 27)
})
it('should throw an error when a dependency is missing with import factory', () => {
it('should throw an error when a dependency is missing with import factory', function () {
const math2 = create()
assert.throws(() => {
@ -338,22 +338,27 @@ describe('import', function () {
})
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should import a factory with name', function () {
// TODO: unit test importing a factory
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should import a factory with path', function () {
// TODO: unit test importing a factory
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should import a factory without name', function () {
// TODO: unit test importing a factory
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should pass the namespace to a factory function', function () {
// TODO: unit test importing a factory
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should import an Array', function () {
// TODO: unit test importing an Array containing stuff
})

View File

@ -26,14 +26,14 @@ describe('parse', function () {
assert.strictEqual(nodes[1].compile().evaluate(), 9)
})
it('should parse expressions with internal newlines', () => {
it('should parse expressions with internal newlines', function () {
assert.ok(math.parse('[1,\n2]') instanceof ArrayNode)
assert.ok(math.parse('{x:1,\n y:2}') instanceof ObjectNode)
assert.ok(math.parse('f(x,\n y)') instanceof FunctionNode)
assert.ok(math.parse('3+\n7') instanceof OperatorNode)
})
it('should parse expressions with internal newlines and comments', () => {
it('should parse expressions with internal newlines and comments', function () {
assert.ok(math.parse('[1, # One\n2]') instanceof ArrayNode)
assert.ok(math.parse('{x:1, # x-coordinate\n y:2}') instanceof ObjectNode)
assert.ok(math.parse('f(x, # first argument\n y)') instanceof FunctionNode)

View File

@ -140,7 +140,7 @@ describe('FunctionAssignmentNode', function () {
return toObject(scope)
}
outputScope.rawArgs = true
math.import({ outputScope: outputScope }, { override: true })
math.import({ outputScope }, { override: true })
// f(x) = outputScope(x)
const x = new SymbolNode('x')
@ -149,7 +149,7 @@ describe('FunctionAssignmentNode', function () {
const scope = { a: 2 }
const f = n.evaluate(scope)
assert.deepStrictEqual(f(3), { a: 2, f: f, x: 3 })
assert.deepStrictEqual(f(3), { a: 2, f, x: 3 })
})
it('should pass function arguments in scope to functions with rawArgs returned by another function', function () {
@ -163,8 +163,8 @@ describe('FunctionAssignmentNode', function () {
}
math.import({
outputScope: outputScope,
returnOutputScope: returnOutputScope
outputScope,
returnOutputScope
}, { override: true })
// f(x, y) = returnOutputScope(x)(y)
@ -185,7 +185,7 @@ describe('FunctionAssignmentNode', function () {
return toObject(scope)
}
outputScope.transform.rawArgs = true
math.import({ outputScope: outputScope }, { override: true })
math.import({ outputScope }, { override: true })
// f(x) = outputScope(x)
const x = new SymbolNode('x')
@ -216,7 +216,7 @@ describe('FunctionAssignmentNode', function () {
assert.deepStrictEqual(myFunc([1, 2, 3], 10), [10, 20, 30])
})
it('should evaluate a function passed as a parameter', () => {
it('should evaluate a function passed as a parameter', function () {
const applicator = math.evaluate('applicator(f,x) = f(x)')
assert.strictEqual(applicator(math.exp, 1), math.e)
const repeater = math.evaluate('repeater(f,x) = f(f(x))')
@ -433,7 +433,7 @@ describe('FunctionAssignmentNode', function () {
{ name: 'x', type: 'number' },
{ name: 'y', type: 'any' }
],
expr: expr
expr
})
const parsed = FunctionAssignmentNode.fromJSON(json)

View File

@ -115,7 +115,7 @@ describe('FunctionNode', function () {
return 'myFunction(' + args.join(', ') + ')'
}
myFunction.rawArgs = true
mymath.import({ myFunction: myFunction })
mymath.import({ myFunction })
const s = new SymbolNode('myFunction')
const a = new mymath.ConstantNode(4)
@ -162,7 +162,7 @@ describe('FunctionNode', function () {
assert.ok(false, 'should not be executed')
}
myFunction.rawArgs = true
mymath.import({ myFunction: myFunction })
mymath.import({ myFunction })
const s = new mymath.SymbolNode('myFunction')
const a = new mymath.ConstantNode(4)
@ -620,7 +620,7 @@ describe('FunctionNode', function () {
assert.throws(function () { tree.toTex() }, TypeError)
})
it('evaluates different sorts of function calls', () => {
it('evaluates different sorts of function calls', function () {
const examples = [
['1; square(3)', 9],
['f(x) = x*x; f(3)', 9],
@ -636,7 +636,7 @@ describe('FunctionNode', function () {
}
})
it('produces clear error messages when the callee is not a function', () => {
it('produces clear error messages when the callee is not a function', function () {
const throwers = [
['tau(3)', TypeError, /tau.*value[\s\S]*6.28/],
['f = 7; f(3)', TypeError, /f.*value[\s\S]*7/],
@ -660,7 +660,7 @@ describe('FunctionNode', function () {
})
// FIXME: custom instances should have there own function, not return the same function?
after(() => {
after(function () {
const customMath = math.create()
delete customMath.add.toTex
delete customMath.sum.toTex

View File

@ -12,7 +12,7 @@ const ObjectNode = math.ObjectNode
describe('ObjectNode', function () {
it('should create an ObjectNode', function () {
const c = new ConstantNode(1)
const a = new ObjectNode({ c: c })
const a = new ObjectNode({ c })
const b = new ObjectNode()
assert(a instanceof ObjectNode)
assert(b instanceof ObjectNode)
@ -37,7 +37,7 @@ describe('ObjectNode', function () {
it('should evaluate an ObjectNode', function () {
const c = new ConstantNode(1)
const a = new ObjectNode({ c: c })
const a = new ObjectNode({ c })
const b = new ObjectNode()
assert.deepStrictEqual(a.compile().evaluate(), { c: 1 })
@ -50,9 +50,9 @@ describe('ObjectNode', function () {
const c = new ConstantNode(3)
const d = new ConstantNode(4)
const n2 = new ObjectNode({ a: a, b: b })
const n3 = new ObjectNode({ c: c, d: d })
const n4 = new ObjectNode({ n2: n2, n3: n3 })
const n2 = new ObjectNode({ a, b })
const n3 = new ObjectNode({ c, d })
const n4 = new ObjectNode({ n2, n3 })
const expr = n4.compile()
assert.deepStrictEqual(expr.evaluate(), { n2: { a: 1, b: 2 }, n3: { c: 3, d: 4 } })
@ -62,7 +62,7 @@ describe('ObjectNode', function () {
const a = new ConstantNode(1)
const b = new SymbolNode('x')
const c = new ConstantNode(2)
const d = new ObjectNode({ a: a, b: b, c: c })
const d = new ObjectNode({ a, b, c })
assert.deepStrictEqual(d.filter(function (node) { return node instanceof ObjectNode }), [d])
assert.deepStrictEqual(d.filter(function (node) { return node instanceof SymbolNode }), [b])
@ -74,7 +74,7 @@ describe('ObjectNode', function () {
it('should run forEach on an ObjectNode', function () {
const a = new SymbolNode('x')
const b = new ConstantNode(2)
const c = new ObjectNode({ a: a, b: b })
const c = new ObjectNode({ a, b })
const nodes = []
const paths = []
@ -93,7 +93,7 @@ describe('ObjectNode', function () {
it('should map an ObjectNode', function () {
const a = new SymbolNode('x')
const b = new ConstantNode(2)
const c = new ObjectNode({ a: a, b: b })
const c = new ObjectNode({ a, b })
const d = new ConstantNode(3)
const nodes = []
@ -119,7 +119,7 @@ describe('ObjectNode', function () {
it('should throw an error when the map callback does not return a node', function () {
const a = new SymbolNode('x')
const b = new ConstantNode(2)
const c = new ObjectNode({ a: a, b: b })
const c = new ObjectNode({ a, b })
assert.throws(function () {
c.map(function () { return undefined })
@ -129,7 +129,7 @@ describe('ObjectNode', function () {
it('should transform an ObjectNodes parameters', function () {
const a = new SymbolNode('x')
const b = new ConstantNode(2)
const c = new ObjectNode({ a: a, b: b })
const c = new ObjectNode({ a, b })
const d = new ConstantNode(3)
const e = c.transform(function (node) {
@ -144,7 +144,7 @@ describe('ObjectNode', function () {
it('should transform an ObjectNode itself', function () {
const a = new SymbolNode('x')
const b = new ConstantNode(2)
const c = new ObjectNode({ a: a, b: b })
const c = new ObjectNode({ a, b })
const d = new ConstantNode(3)
const e = c.transform(function (node) {
@ -159,8 +159,8 @@ describe('ObjectNode', function () {
const a = new ConstantNode(1)
const b = new ConstantNode(2)
const c = new ConstantNode(3)
const d = new ObjectNode({ a: a, b: b })
const e = new ObjectNode({ c: c, d: d })
const d = new ObjectNode({ a, b })
const e = new ObjectNode({ c, d })
let count = 0
e.traverse(function (node, path, parent) {
@ -205,7 +205,7 @@ describe('ObjectNode', function () {
it('should clone an ObjectNode', function () {
const a = new SymbolNode('x')
const b = new ConstantNode(2)
const c = new ObjectNode({ a: a, b: b })
const c = new ObjectNode({ a, b })
const d = c.clone()
assert(d instanceof ObjectNode)
@ -236,8 +236,8 @@ describe('ObjectNode', function () {
const a = new ConstantNode(1)
const b = new ConstantNode(2)
const c = new ConstantNode(3)
const n1 = new ObjectNode({ a: a, b: b })
const n2 = new ObjectNode({ c: c, n1: n1 })
const n1 = new ObjectNode({ a, b })
const n2 = new ObjectNode({ c, n1 })
assert.strictEqual(n2.toString(), '{"c": 3, "n1": {"a": 1, "b": 2}}')
})
@ -251,7 +251,7 @@ describe('ObjectNode', function () {
const a = new ConstantNode(1)
const b = new ConstantNode(2)
const n = new ObjectNode({ a: a, b: b })
const n = new ObjectNode({ a, b })
assert.strictEqual(n.toString({ handler: customFunction }), '{"a": const(1, number), "b": const(2, number)}')
})
@ -260,13 +260,13 @@ describe('ObjectNode', function () {
const b = new ConstantNode(1)
const c = new ConstantNode(2)
const node = new ObjectNode({ b: b, c: c })
const node = new ObjectNode({ b, c })
const json = node.toJSON()
assert.deepStrictEqual(json, {
mathjs: 'ObjectNode',
properties: { b: b, c: c }
properties: { b, c }
})
const parsed = ObjectNode.fromJSON(json)
@ -277,8 +277,8 @@ describe('ObjectNode', function () {
const a = new ConstantNode(1)
const b = new ConstantNode(2)
const c = new ConstantNode(3)
const n1 = new ObjectNode({ a: a, b: b })
const n2 = new ObjectNode({ c: c, n1: n1 })
const n1 = new ObjectNode({ a, b })
const n2 = new ObjectNode({ c, n1 })
assert.strictEqual(n2.toTex(), '\\left\\{\\begin{array}{ll}\\mathbf{c:} & 3\\\\\n\\mathbf{n1:} & \\left\\{\\begin{array}{ll}\\mathbf{a:} & 1\\\\\n\\mathbf{b:} & 2\\\\\\end{array}\\right\\}\\\\\\end{array}\\right\\}')
})
@ -292,7 +292,7 @@ describe('ObjectNode', function () {
const a = new ConstantNode(1)
const b = new ConstantNode(2)
const n = new ObjectNode({ a: a, b: b })
const n = new ObjectNode({ a, b })
assert.strictEqual(n.toTex({ handler: customFunction }), '\\left\\{\\begin{array}{ll}\\mathbf{a:} & const\\left(1, number\\right)\\\\\n\\mathbf{b:} & const\\left(2, number\\right)\\\\\\end{array}\\right\\}')
})

View File

@ -391,7 +391,7 @@ describe('security', function () {
assert.deepStrictEqual(math.evaluate('chain'), math.unit('chain'))
})
it('should not allow polluting the Object prototype via config', () => {
it('should not allow polluting the Object prototype via config', function () {
const obj = {}
assert.strictEqual(obj.polluted, undefined)
@ -401,7 +401,7 @@ describe('security', function () {
assert.strictEqual(obj.polluted, undefined)
})
it('should not allow polluting the Object prototype via config via the expression parser', () => {
it('should not allow polluting the Object prototype via config via the expression parser', function () {
const obj = {}
assert.strictEqual(obj.polluted, undefined)
@ -410,7 +410,7 @@ describe('security', function () {
assert.strictEqual(obj.polluted, undefined)
})
it('should not allow polluting the Object prototype by creating an object in the expression parser', () => {
it('should not allow polluting the Object prototype by creating an object in the expression parser', function () {
const obj = {}
assert.strictEqual(obj.polluted, undefined)

View File

@ -98,7 +98,7 @@ describe('slu', function () {
values: cvalues,
index: cindex,
ptr: cptr,
size: size,
size,
datatype: A._datatype
})
}

View File

@ -122,6 +122,7 @@ describe('rationalize', function () {
assert.strictEqual(stri(math.rationalize(no)), '(-20*x^4+28*x^3+104*x^2+6*x-12)/(6*x^2+5*x-4)')
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('processes a really complex expression', function () {
// note this test passes but takes for ever to complete

View File

@ -4,6 +4,7 @@ import assert from 'assert'
import math from '../../../../src/defaultInstance.js'
const expLibrary = []
// eslint-disable-next-line mocha/no-exports
export function simplifyAndCompare (left, right, rules, scope, opt, stringOpt) {
expLibrary.push(left)
let simpLeft
@ -159,10 +160,10 @@ describe('simplify', function () {
function doubleIt (x) { return x + x }
const f = new math.FunctionNode(new math.SymbolNode('doubleIt'), [new math.SymbolNode('value')])
assert.strictEqual(f.toString(), 'doubleIt(value)')
assert.strictEqual(f.evaluate({ doubleIt: doubleIt, value: 4 }), 8)
assert.strictEqual(f.evaluate({ doubleIt, value: 4 }), 8)
const fsimplified = math.simplifyCore(f)
assert.strictEqual(fsimplified.toString(), 'doubleIt(value)')
assert.strictEqual(fsimplified.evaluate({ doubleIt: doubleIt, value: 4 }), 8)
assert.strictEqual(fsimplified.evaluate({ doubleIt, value: 4 }), 8)
})
it('should handle immediately invoked function assignments', function () {
@ -404,6 +405,7 @@ describe('simplify', function () {
assert.strictEqual(res.toString(), '30 * x')
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should compute and simplify derivatives (3)', function () {
// TODO: this requires the + operator to support Nodes,
// i.e. math.add(5, math.parse('2')) => return an OperatorNode

View File

@ -58,7 +58,7 @@ describe('simplifyCore', function () {
assert.strictEqual(result, 'x + y - 1')
})
it('should recurse through arbitrary binary operators', () => {
it('should recurse through arbitrary binary operators', function () {
testSimplifyCore('x+0==5', 'x == 5')
testSimplifyCore('(x*1) % (y^1)', 'x % y')
})

View File

@ -123,7 +123,7 @@ describe('addScalar', function () {
approx.deepEqual(add(math.unit(math.complex(-3, 2), 'g'), math.unit(math.complex(5, -6), 'g')).toString(), '(2 - 4i) g')
})
it('should add units properly even when they have offsets', () => {
it('should add units properly even when they have offsets', function () {
let t = math.unit(20, 'degC')
assert.deepStrictEqual(add(t, math.unit(1, 'degC')), math.unit(21, 'degC'))
t = math.unit(68, 'degF')

View File

@ -5,34 +5,34 @@ import math from '../../../../src/defaultInstance.js'
const { invmod, complex, bignumber } = math
describe('invmod', function () {
it('should find the multiplicative inverse for basic cases', () => {
it('should find the multiplicative inverse for basic cases', function () {
assert.strictEqual(invmod(2, 7), 4)
assert.strictEqual(invmod(3, 11), 4)
assert.strictEqual(invmod(10, 17), 12)
})
it('should return NaN when there is no multiplicative inverse', () => {
it('should return NaN when there is no multiplicative inverse', function () {
assert(isNaN(invmod(3, 15)))
assert(isNaN(invmod(14, 7)))
assert(isNaN(invmod(42, 1200)))
})
it('should work when a≥b', () => {
it('should work when a≥b', function () {
assert.strictEqual(invmod(4, 3), 1)
assert(isNaN(invmod(7, 7)))
})
it('should work for negative values', () => {
it('should work for negative values', function () {
assert.strictEqual(invmod(-2, 7), 3)
assert.strictEqual(invmod(-2000000, 21), 10)
})
it('should calculate invmod for BigNumbers', () => {
it('should calculate invmod for BigNumbers', function () {
assert.deepStrictEqual(invmod(bignumber(13), bignumber(25)), bignumber(2))
assert.deepStrictEqual(invmod(bignumber(-7), bignumber(48)), bignumber(41))
})
it('should calculate invmod for mixed BigNumbers and Numbers', () => {
it('should calculate invmod for mixed BigNumbers and Numbers', function () {
assert.deepStrictEqual(invmod(bignumber(44), 7), bignumber(4))
assert.deepStrictEqual(invmod(4, math.bignumber(15)), bignumber(4))
})

View File

@ -57,6 +57,7 @@ describe('mod', function () {
assert.deepStrictEqual(mod(bignumber(8), bignumber(3)).valueOf(), bignumber(2).valueOf())
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should calculate the modulus of bignumbers for fractions', function () {
assert.deepStrictEqual(mod(bignumber(7).div(3), bignumber(1).div(3)), bignumber(0))
})

View File

@ -169,7 +169,7 @@ describe('multiply', function () {
assert.strictEqual(multiply(unit(math.complex(3, -4), 'N'), unit(math.complex(7, -2), 'm')).toString(), '(13 - 34i) J')
})
it('should evaluate a complicated unit multiplication', () => {
it('should evaluate a complicated unit multiplication', function () {
const v1 = math.evaluate('0.1 kg/s * 4.2 J/degC/g * 5 degC')
approx.equal(v1.value, 2100)
})
@ -183,6 +183,7 @@ describe('multiply', function () {
})
// TODO: cleanup once decided to not downgrade BigNumber to number
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should multiply a bignumber and a unit correctly', function () {
assert.strictEqual(multiply(bignumber(2), unit('5 mm')).toString(), '10 mm')
assert.strictEqual(multiply(bignumber(2), unit('5 mm')).toString(), '10 mm')
@ -191,6 +192,7 @@ describe('multiply', function () {
})
// TODO: cleanup once decided to not downgrade BigNumber to number
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should multiply a bignumber and a unit without value correctly', function () {
assert.strictEqual(multiply(bignumber(2), unit('mm')).toString(), '2 mm')
assert.strictEqual(multiply(bignumber(2), unit('km')).toString(), '2 km')

View File

@ -60,7 +60,7 @@ describe('sign', function () {
assert.deepStrictEqual(math.sign(math.unit(complex(3, 4), 'mi')), complex(0.6, 0.8))
})
it('should throw an error on a valueless unit or a unit with offset', () => {
it('should throw an error on a valueless unit or a unit with offset', function () {
assert.throws(() => math.sign(math.unit('ohm')), TypeError)
assert.throws(() => math.sign(math.unit('-3 degC')), /ambiguous/)
})

View File

@ -94,7 +94,7 @@ describe('subtract', function () {
assert.deepStrictEqual(subtract(math.unit(math.complex(10, 10), 'K'), math.unit(3, 'K')), math.unit(math.complex(7, 10), 'K'))
})
it('should subtract units even when they have offsets', () => {
it('should subtract units even when they have offsets', function () {
let t = math.unit(20, 'degC')
assert.deepStrictEqual(subtract(t, math.unit(1, 'degC')), math.unit(19, 'degC'))
t = math.unit(68, 'degF')

View File

@ -13,6 +13,7 @@ describe('unaryMinus', function () {
})
// TODO: unary minus should return bignumber on boolean input when configured for bignumber
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should return bignumber unary minus of a boolean', function () {
const bigmath = math.create({ number: 'BigNumber' })
assert.deepStrictEqual(bigmath.unaryMinus(true), bigmath.bignumber(-1))

View File

@ -65,7 +65,7 @@ describe('eigs', function () {
)
})
it('calculates eigenvalues for 2x2 matrix with complex entries', () => {
it('calculates eigenvalues for 2x2 matrix with complex entries', function () {
approx.deepEqual(
eigs([[3, -2], [complex(4, 2), -1]]).values,
[complex(0.08982028, 2.197368227), complex(1.91017972, -2.197368227)])
@ -145,7 +145,7 @@ describe('eigs', function () {
approx.deepEqual(Ei, E)
})
it('complex matrix eigenvector check', () => {
it('complex matrix eigenvector check', function () {
// Example from issue #2478
const A = [[1, 2, 3], [2, 4, 0], [3, 0, 1]]
const cnt = 0.1

View File

@ -32,7 +32,7 @@ function assertValidPinv (A, A_) {
}
describe('pinv', function () {
function test (A, A_, strict = false) {
function check (A, A_, strict = false) {
const pinvA = pinv(A)
if (A_) {
if (strict) assert.deepStrictEqual(pinvA, A_)
@ -54,20 +54,20 @@ describe('pinv', function () {
}
}
it('should return the inverse of a number', function () {
test(4, 1 / 4, true)
test(math.bignumber(4), math.bignumber(1 / 4), true)
check(4, 1 / 4, true)
check(math.bignumber(4), math.bignumber(1 / 4), true)
})
it('should return the inverse of a matrix with just one value', function () {
test([4], [1 / 4], true)
test([[4]], [[1 / 4]], true)
check([4], [1 / 4], true)
check([[4]], [[1 / 4]], true)
})
it('should return the inverse for each element in an array', function () {
test([4], [1 / 4], true)
test([[4]], [[1 / 4]], true)
check([4], [1 / 4], true)
check([[4]], [[1 / 4]], true)
test([
check([
[1, 4, 7],
[3, 0, 5],
[-1, 9, 11]
@ -77,7 +77,7 @@ describe('pinv', function () {
[-3.375, 1.625, 1.5]
])
test([
check([
[2, -1, 0],
[-1, 2, -1],
[0, -1, 2]
@ -87,7 +87,7 @@ describe('pinv', function () {
[1 / 4, 1 / 2, 3 / 4]
])
test([
check([
[1, 0, 0],
[0, 0, 1],
[0, 1, 0]
@ -97,7 +97,7 @@ describe('pinv', function () {
[0, 1, 0]
])
test([
check([
[1, 0, 0],
[0, -1, 1],
[0, 0, 1]
@ -109,14 +109,14 @@ describe('pinv', function () {
})
it('should return the inverse for each element in a matrix', function () {
test(math.matrix([4]), math.matrix([1 / 4]), true)
test(math.matrix([[4]]), math.matrix([[1 / 4]]), true)
test(math.matrix([[4]], 'sparse'), math.matrix([[1 / 4]], 'sparse'), true)
test(math.matrix([[1, 2], [3, 4]], 'sparse'), math.matrix([[-2, 1], [1.5, -0.5]], 'sparse'), true)
check(math.matrix([4]), math.matrix([1 / 4]), true)
check(math.matrix([[4]]), math.matrix([[1 / 4]]), true)
check(math.matrix([[4]], 'sparse'), math.matrix([[1 / 4]], 'sparse'), true)
check(math.matrix([[1, 2], [3, 4]], 'sparse'), math.matrix([[-2, 1], [1.5, -0.5]], 'sparse'), true)
})
it('should return the MoorePenrose inverse of complex matrices', function () {
test(
check(
math.evaluate(`[
[0.4032 + 0.0876i, 0.1678 + 0.0390i, 0.5425 + 0.5118i],
[0.3174 + 0.3352i, 0.9784 + 0.4514i, -0.4416 - 1.3188i],
@ -131,14 +131,14 @@ describe('pinv', function () {
})
it('should return the MoorePenrose inverse of non-square matrices', function () {
test([[0, 0]], [[0], [0]], true)
check([[0, 0]], [[0], [0]], true)
test([1, 2, 3], [1 / 14, 2 / 14, 3 / 14])
check([1, 2, 3], [1 / 14, 2 / 14, 3 / 14])
test([[1, 2, 3], [4, 5, 6]], [[-17 / 18, 8 / 18], [-2 / 18, 2 / 18], [13 / 18, -4 / 18]])
test([[1, 4], [2, 5], [3, 6]], [[-17 / 18, -2 / 18, 13 / 18], [8 / 18, 2 / 18, -4 / 18]])
check([[1, 2, 3], [4, 5, 6]], [[-17 / 18, 8 / 18], [-2 / 18, 2 / 18], [13 / 18, -4 / 18]])
check([[1, 4], [2, 5], [3, 6]], [[-17 / 18, -2 / 18, 13 / 18], [8 / 18, 2 / 18, -4 / 18]])
test([
check([
[64, 2, 3, 61, 60, 6],
[9, 55, 54, 12, 13, 51],
[17, 47, 46, 20, 21, 43],
@ -155,9 +155,9 @@ describe('pinv', function () {
})
it('should return the MoorePenrose inverse of non-invertable matrices', function () {
test([[0]], [[0]], true)
test([[1, 0], [0, 0]], [[1, 0], [0, 0]])
test([[1, 1, 1], [1, 0, 0], [0, 0, 0]], [[0, 1, 0], [0.5, -0.5, 0], [0.5, -0.5, 0]])
check([[0]], [[0]], true)
check([[1, 0], [0, 0]], [[1, 0], [0, 0]])
check([[1, 1, 1], [1, 0, 0], [0, 0, 0]], [[0, 1, 0], [0.5, -0.5, 0], [0.5, -0.5, 0]])
})
it('should throw an error in case of wrong number of arguments', function () {

View File

@ -152,6 +152,7 @@ describe('range', function () {
})
// FIXME: should give the right error
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should not cast a single number or boolean to string', function () {
assert.throws(function () { range(2) }, /TypeError: Too few arguments/)
assert.throws(function () { range(true) }, /TypeError: Unexpected type of argument/)

View File

@ -18,8 +18,8 @@ const EPSILON = isInternetExplorer() ? 1e-6 : 1e-11
// lgamma for reals
const CEPSILON = 5e-8
describe('lgamma', () => {
it('should calculate the lgamma of 0 and negative numbers', () => {
describe('lgamma', function () {
it('should calculate the lgamma of 0 and negative numbers', function () {
assert.strictEqual(lgamma(0), Infinity)
assert.ok(isNaN(lgamma(-0.0005)))
@ -32,7 +32,7 @@ describe('lgamma', () => {
assert.ok(isNaN(lgamma(-123456.123456)))
})
it('should calculate the lgamma of a positive numbers', () => {
it('should calculate the lgamma of a positive numbers', function () {
// computation reference: https://www.wolframalpha.com/input?i=LogGamma%5Bx%5D
approx.equal(lgamma(/**/ 0.000000001), /* */ 20.7232658363691954921, EPSILON)
@ -51,13 +51,13 @@ describe('lgamma', () => {
approx.equal(lgamma(/* */ 1e92), /**/ 2.1083782855545220293e94, EPSILON)
})
it('should calculate the lgamma of an irrational number', () => {
it('should calculate the lgamma of an irrational number', function () {
approx.equal(lgamma(Math.SQRT2), -0.12038230351896920333, EPSILON)
approx.equal(lgamma(Math.PI), 0.82769459232343710153, EPSILON)
approx.equal(lgamma(Math.E), 0.449461741820067667, EPSILON)
})
it('should calculate the lgamma of a complex number', () => {
it('should calculate the lgamma of a complex number', function () {
approx.deepEqual(lgamma(math.complex(0, 0)), math.complex(Infinity), EPSILON)
approx.deepEqual(
lgamma(math.complex(0.000000001, 0.000000001)),
@ -200,7 +200,7 @@ describe('lgamma', () => {
)
})
it('should calculate the lgamma of some special arguments', () => {
it('should calculate the lgamma of some special arguments', function () {
approx.equal(lgamma(true), 0, EPSILON)
assert.strictEqual(lgamma(false), Infinity)
@ -211,21 +211,21 @@ describe('lgamma', () => {
assert.ok(!isFinite(lgamma(-Infinity)))
})
it('should throw an error if called with a big number', () => {
it('should throw an error if called with a big number', function () {
assert.throws(() => lgamma(math.bignumber(0)))
})
it('should throw an error if called with invalid number of arguments', () => {
it('should throw an error if called with invalid number of arguments', function () {
assert.throws(() => lgamma())
assert.throws(() => lgamma(1, 3))
})
it('should throw an error if called with invalid type of argument', () => {
it('should throw an error if called with invalid type of argument', function () {
assert.throws(() => lgamma(new Date()))
assert.throws(() => lgamma('a string'))
})
it('should LaTeX lgamma', () => {
it('should LaTeX lgamma', function () {
const expression = math.parse('lgamma(2.5)')
assert.strictEqual(expression.toTex(), '\\ln\\Gamma\\left(2.5\\right)')
})

View File

@ -59,6 +59,7 @@ describe('quantileSeq', function () {
})
// FIXME: should return the quantileSeq of an array of bignumbers with number probability
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should return the quantileSeq of an array of bignumbers with number probability', function () {
approx.equal(quantileSeq([bignumber(0.5377), bignumber(1.8339), bignumber(-2.2588), bignumber(0.8622),
bignumber(0.3188), bignumber(-1.3077), bignumber(-0.4336), bignumber(0.3426),

View File

@ -117,7 +117,9 @@ describe('variance', function () {
assert.throws(function () { variance('a') }, /Error: Cannot convert "a" to a number/)
})
it('should throw an error if the axis exceeds the dimension of the matrix')
it('should throw an error if the axis exceeds the dimension of the matrix', function () {
// TODO
})
it('should throw an error if called with an empty array', function () {
assert.throws(function () { variance([]) })

View File

@ -357,7 +357,7 @@ describe('format', function () {
})
})
it('should format expressions', () => {
it('should format expressions', function () {
assert.strictEqual(math.format(math.parse('0.3333'), { precision: 1 }), '0.3')
assert.strictEqual(math.format(math.parse('0.3333 + [0.4444]'), { precision: 1 }), '0.3 + [0.4]')

View File

@ -11,13 +11,13 @@ describe('fraction', function () {
equalFraction(math.fraction(null), new Fraction(0))
})
it('should fail to create a fraction in case of non-integer quotient', () => {
it('should fail to create a fraction in case of non-integer quotient', function () {
assert.throws(() => math.fraction(4, 5.1), /Parameters must be integer/)
assert.throws(() => math.fraction(62.8, 10), /Parameters must be integer/)
assert.throws(() => math.fraction(Infinity, 3), /Parameters must be integer/)
})
it('should create a fraction from a quotient regardless of integrality', () => {
it('should create a fraction from a quotient regardless of integrality', function () {
equalFraction(math.divide(math.fraction(4), math.fraction(5.1)),
math.fraction(40, 51))
})

View File

@ -166,12 +166,14 @@ describe('SparseMatrix', function () {
})
// TODO: add some more input validations to SparseMatrix
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should throw an error when input array does not have two dimensions', function () {
assert.throws(function () { console.log(new SparseMatrix([1, 2, 3])) }, /DimensionError: Two dimensional array expected/)
assert.throws(function () { console.log(new SparseMatrix([[[1]], [[2]], [[3]]])) }, /DimensionError: Two dimensional array expected/)
})
// TODO: add some more input validations to SparseMatrix
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should throw an error when the dimensions of the input array are invalid', function () {
assert.throws(function () {
console.log(new SparseMatrix(
@ -1504,7 +1506,7 @@ describe('SparseMatrix', function () {
})
})
describe('index ordering', () => {
describe('index ordering', function () {
const orderedSparseMatrix = new SparseMatrix({
values: [1, 3, 2, 4],
index: [0, 1, 0, 1],
@ -1526,7 +1528,7 @@ describe('SparseMatrix', function () {
{ value: 4, index: [1, 1] }
]
it('should have parsed the two test matrices correctly', () => {
it('should have parsed the two test matrices correctly', function () {
assert.deepStrictEqual(orderedSparseMatrix.toArray(), [[1, 2], [3, 4]])
assert.deepStrictEqual(unorderedSparseMatrix.toArray(), [[1, 2], [3, 4]])
})

View File

@ -1008,7 +1008,7 @@ describe('Unit', function () {
assert(math.isBigNumber(unitP.value))
})
it('should multiply/divide units with offsets correctly', () => {
it('should multiply/divide units with offsets correctly', function () {
const unit1 = new Unit(1, 'm')
const unit2 = new Unit(1, 'degC')
const unit3 = new Unit(1, 'm degC')
@ -1021,7 +1021,8 @@ describe('Unit', function () {
assert.deepStrictEqual(unit4.divide(unit5), unit6)
})
it.skip('should cancel units in numerator and denominator', () => {
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should cancel units in numerator and denominator', function () {
assert.strictEqual(math.evaluate('2 J/K/g * 2 g').toString(), '4 J / K')
assert.strictEqual(math.evaluate('2 J/K/g * 2K').toString(), '4 J / g')
})

View File

@ -136,7 +136,7 @@ describe('physical constants', function () {
assert.strictEqual(createPlanckTemperature(dependencies).toString(), '1.416785e+32 K')
})
it('should create BigNumber unit values if configured', () => {
it('should create BigNumber unit values if configured', function () {
const config = { number: 'BigNumber', precision: 64, epsilon: 1e-12 }
const dependencies = { config, BigNumber, Unit }
const molarMass = createMolarMass(dependencies)

View File

@ -2,7 +2,7 @@ import assert from 'assert'
import { sortFactories, factory, isFactory } from '../../../src/utils/factory.js'
describe('factory', function () {
it('should test whether something is a factory', () => {
it('should test whether something is a factory', function () {
assert.strictEqual(isFactory(), false)
assert.strictEqual(isFactory({}), false)
@ -20,7 +20,7 @@ describe('factory', function () {
assert.strictEqual(isFactory(factory3), true)
})
it('should only pass the dependencies, not the whole scope', (done) => {
it('should only pass the dependencies, not the whole scope', function (done) {
const f = factory('fn1', ['a', 'c'], (scope) => {
assert.deepStrictEqual(scope, { a: 1, c: 3 })
@ -31,7 +31,8 @@ describe('factory', function () {
})
// FIXME: this unit test doesn't work on IE either remove sortFactories if redundant, or use it and get the test working
it.skip('should order functions by their dependencies (1)', () => {
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should order functions by their dependencies (1)', function () {
function fn1 () { return 1 }
const fn2factory = factory('fn2', ['fn1'], () => {})
const fn3factory = factory('fn3', ['fn2'], () => {})
@ -51,7 +52,7 @@ describe('factory', function () {
.map(f => f.fn || f.name), ['fn1', 'fn2', 'fn3', 'fn5', 'fn4'])
})
it('should order functions by their dependencies (2)', () => {
it('should order functions by their dependencies (2)', function () {
const fn1 = factory('fn1', [], () => {})
const fn2 = factory('fn2', ['fn4'], () => {})
const fn3 = factory('fn3', [], () => {})
@ -62,7 +63,8 @@ describe('factory', function () {
})
// TODO: throw an error in case of circular dependencies
it.skip('should not go crazy with circular dependencies', () => {
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should not go crazy with circular dependencies', function () {
const fn1factory = factory('fn1', ['fn2'], () => {})
const fn2factory = factory('fn2', ['fn1'], () => {})
@ -73,7 +75,7 @@ describe('factory', function () {
.map(f => f.fn), ['fn2', 'fn1'])
})
it('should allow optional dependencies', () => {
it('should allow optional dependencies', function () {
const createFn1 = factory('fn1', ['a', '?b'], ({ a, b }) => {
return () => ({ a, b })
})
@ -84,7 +86,7 @@ describe('factory', function () {
assert.deepStrictEqual(a(), { a: 2, b: undefined })
})
it('should attach meta information to a factory function', () => {
it('should attach meta information to a factory function', function () {
const createFn1 = factory('fn1', [], () => {})
assert.strictEqual(createFn1.meta, undefined)

View File

@ -75,7 +75,7 @@ describe('util.function', function () {
})
describe('memoizeCompare', function () {
it('should memoize using comparison', () => {
it('should memoize using comparison', function () {
let execCount = 0
function multiply (obj) {

View File

@ -2,7 +2,7 @@ import assert from 'assert'
import { isMap, ObjectWrappingMap, toObject, createMap, assign } from '../../../src/utils/map.js'
describe('maps', function () {
it('should provide isMap, a function to tell maps from non-maps', () => {
it('should provide isMap, a function to tell maps from non-maps', function () {
assert.ok(isMap(new Map()))
assert.ok(!isMap([]))
assert.ok(!isMap({}))
@ -29,7 +29,7 @@ describe('maps', function () {
}
})
it('should wrap an object in a map-like object', () => {
it('should wrap an object in a map-like object', function () {
const obj = {
a: 1,
b: 2,
@ -82,7 +82,7 @@ describe('maps', function () {
assert.strictEqual(innerObject, obj)
})
it('should create a map from objects, maps, or undefined', () => {
it('should create a map from objects, maps, or undefined', function () {
const emptyMap = createMap()
assert.ok(isMap(emptyMap))
@ -97,7 +97,7 @@ describe('maps', function () {
}
})
it('should let us transform a map into an object', () => {
it('should let us transform a map into an object', function () {
const actualMap = new Map()
.set('a', 1)
.set('b', 2)
@ -116,7 +116,7 @@ describe('maps', function () {
assert.strictEqual(toObject(wrappedMap), obj)
})
it('should provide an assign function like Object.assign', () => {
it('should provide an assign function like Object.assign', function () {
const target = new Map()
.set('a', 1)
.set('b', 2)

View File

@ -87,13 +87,13 @@ describe('object', function () {
it('should extend an object with all properties of an other object', function () {
const e = {}
const o1 = { a: 2, b: 3 }
const o2 = { a: 4, b: null, c: undefined, d: 5, e: e }
const o2 = { a: 4, b: null, c: undefined, d: 5, e }
const o3 = extend(o1, o2)
assert.strictEqual(o1, o3)
assert.strictEqual(o1.e, o3.e)
assert.deepStrictEqual(o3, { a: 4, b: null, c: undefined, d: 5, e: e })
assert.deepStrictEqual(o2, { a: 4, b: null, c: undefined, d: 5, e: e }) // should be unchanged
assert.deepStrictEqual(o3, { a: 4, b: null, c: undefined, d: 5, e })
assert.deepStrictEqual(o2, { a: 4, b: null, c: undefined, d: 5, e }) // should be unchanged
})
it('should ignore inherited properties when extending an object', function () {
@ -112,7 +112,7 @@ describe('object', function () {
it('should deep extend an object with all properties of an other object', function () {
const e = { f: { g: 3 } }
const o1 = { a: 2, b: 3 }
const o2 = { a: 4, b: null, c: undefined, d: 5, e: e }
const o2 = { a: 4, b: null, c: undefined, d: 5, e }
const o3 = deepExtend(o1, o2)
assert.strictEqual(o1, o3)
@ -287,8 +287,8 @@ describe('object', function () {
describe('traverse', function () {
it('should traverse an existing path into an object', function () {
const a = {}
const b = { a: a }
const c = { b: b }
const b = { a }
const c = { b }
assert.strictEqual(traverse(c), c)
assert.strictEqual(traverse(c, ''), c)
@ -299,8 +299,8 @@ describe('object', function () {
it('should append missing piece of a path', function () {
const a = {}
const b = { a: a }
const c = { b: b }
const b = { a }
const c = { b }
assert.strictEqual(traverse(c), c)
assert.strictEqual(traverse(c, ''), c)
@ -326,7 +326,7 @@ describe('object', function () {
})
describe('get', function () {
it('should get nested properties from an object', () => {
it('should get nested properties from an object', function () {
const object = {
a: 2,
b: {
@ -346,7 +346,7 @@ describe('object', function () {
})
describe('set', function () {
it('should set a nested property in an object', () => {
it('should set a nested property in an object', function () {
assert.deepStrictEqual(set({}, [], 2), {})
assert.deepStrictEqual(set({}, 'a', 2), { a: 2 })
assert.deepStrictEqual(set({ a: 2 }, 'b.c', 3), { a: 2, b: { c: 3 } })
@ -355,12 +355,12 @@ describe('object', function () {
})
describe('pick', function () {
it('should pick the selected properties', () => {
it('should pick the selected properties', function () {
const object = { a: 1, b: 2, c: 3 }
assert.deepStrictEqual(pick(object, ['a', 'c', 'd']), { a: 1, c: 3 })
})
it('should pick nested properties', () => {
it('should pick nested properties', function () {
const object = {
a: 1,
b: {
@ -375,7 +375,7 @@ describe('object', function () {
assert.deepStrictEqual(pick(object, ['a', 'b.c', 'foo', 'b.foo']), { a: 1, b: { c: 2 } })
})
it('should pick and transform nested properties', () => {
it('should pick and transform nested properties', function () {
const object = {
a: 1,
b: {
@ -398,7 +398,7 @@ describe('object', function () {
})
describe('deepFlatten', function () {
it('should flatten nested object properties', () => {
it('should flatten nested object properties', function () {
assert.deepStrictEqual(deepFlatten({
obj: { a: 2, b: 3 },
c: 4,
@ -406,7 +406,7 @@ describe('object', function () {
}), { a: 2, b: 3, c: 4, d: 5 })
})
it('should merge duplicate values when flatting nested object properties', () => {
it('should merge duplicate values when flatting nested object properties', function () {
assert.deepStrictEqual(deepFlatten({
obj: { a: 2 },
foo: { bar: { a: 3 } }

View File

@ -112,7 +112,7 @@ describe('string', function () {
assert.strictEqual(format(true), 'true')
})
it('should limit the length of output with a truncate option', () => {
it('should limit the length of output with a truncate option', function () {
const result = format('01234567890123456789', { truncate: 17 })
assert.strictEqual(result.length, 17)
assert.ok(endsWith(result, '...'))

3025
types/index.d.ts vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff