mathjs/test/index.test.js
greenkeeper[bot] c5971b371a Update standard to the latest version 🚀 (#1226)
* chore(package): update standard to version 12.0.0

* update to new lint version with --fix

I believe this mainly adds whitespace to `{}`'s.

* Replace assert.equal with assert.strictEqual

This breaks a lot of tests which I will endevour to fix in the next
commits.

* Fix most errors due to assert.strictEquals

Some instances of `strictEquals` are replaced by `deepEquals`.
`toString` has been used to make some string comparisions explicit.
Tests will still fail untill #1236 and #1237 are fixed.

* Fix assertion erros due to -0

With node 10, assert.strictEqual no longer considers `0 === -0`.
I missed these first time round as I was using node 8.

* Put toString correct side of bracket

I was converting the constructor to a string rather
than the result of the computation. Oops.

* Fixed #1236: quantileSeq has inconsistant return

* Update package-lock

* Fixed #1237: norm sometimes returning a complex number instead of number

* Fix cli tests

* More changes for standardjs, and fixes in unit tests
2018-09-08 16:33:58 +02:00

84 lines
2.3 KiB
JavaScript

const assert = require('assert')
const math = require('../src/main')
describe('factory', function () {
it('should get a default instance of mathjs', function () {
assert.strictEqual(typeof math, 'object')
assert.deepStrictEqual(math.config(), {
matrix: 'Matrix',
number: 'number',
precision: 64,
predictable: false,
epsilon: 1e-12,
randomSeed: null
})
})
it('should create an instance of math.js with custom configuration', function () {
const math1 = math.create({
matrix: 'Array',
number: 'BigNumber'
})
assert.strictEqual(typeof math1, 'object')
assert.deepStrictEqual(math1.config(), {
matrix: 'Array',
number: 'BigNumber',
precision: 64,
predictable: false,
epsilon: 1e-12,
randomSeed: null
})
})
it('two instances of math.js should be isolated from each other', function () {
const math1 = math.create()
const math2 = math.create({
matrix: 'Array'
})
assert.notStrictEqual(math, math1)
assert.notStrictEqual(math, math2)
assert.notStrictEqual(math1, math2)
assert.notDeepStrictEqual(math1.config(), math2.config())
assert.notDeepStrictEqual(math.config(), math2.config())
// changing config should not affect the other
math1.config({ number: 'BigNumber' })
assert.strictEqual(math.config().number, 'number')
assert.strictEqual(math1.config().number, 'BigNumber')
assert.strictEqual(math2.config().number, 'number')
})
it('should apply configuration using the config function', function () {
const math1 = math.create()
const config = math1.config()
assert.deepStrictEqual(config, {
matrix: 'Matrix',
number: 'number',
precision: 64,
predictable: false,
epsilon: 1e-12,
randomSeed: null
})
// restore the original config
math1.config(config)
})
// TODO: test whether the namespace is correct: has functions like sin, constants like pi, objects like type and error.
it('should throw an error when ES5 is not supported', function () {
const create = Object.create
Object.create = undefined // fake missing Object.create function
assert.throws(function () {
math.create()
}, /ES5 not supported/)
// restore Object.create
Object.create = create
})
})