mathjs/test/function/matrix/zeros.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

78 lines
2.6 KiB
JavaScript

// test zeros
const assert = require('assert')
const math = require('../../../src/main')
const zeros = math.zeros
const matrix = math.matrix
describe('zeros', function () {
it('should create an empty matrix', function () {
assert.deepStrictEqual(zeros(), matrix())
assert.deepStrictEqual(zeros([]), [])
assert.deepStrictEqual(zeros(matrix([])), matrix())
})
it('should create an empty matrix, sparse', function () {
assert.deepStrictEqual(zeros('sparse'), matrix('sparse'))
assert.deepStrictEqual(zeros([], 'sparse'), matrix([], 'sparse'))
assert.deepStrictEqual(zeros(matrix([]), 'sparse'), matrix('sparse'))
})
it('should create a vector with zeros', function () {
assert.deepStrictEqual(zeros(3), matrix([0, 0, 0]))
assert.deepStrictEqual(zeros(matrix([4])), matrix([0, 0, 0, 0]))
assert.deepStrictEqual(zeros([4]), [0, 0, 0, 0])
assert.deepStrictEqual(zeros(0), matrix([]))
})
it('should create a matrix with bignumber zeros', function () {
const zero = math.bignumber(0)
const three = math.bignumber(3)
assert.deepStrictEqual(zeros(three), matrix([zero, zero, zero]))
assert.deepStrictEqual(zeros([three]), [zero, zero, zero])
})
it('should create a 2D matrix with zeros from an array', function () {
assert.deepStrictEqual(zeros(2, 3), matrix([[0, 0, 0], [0, 0, 0]]))
assert.deepStrictEqual(zeros(3, 2), matrix([[0, 0], [0, 0], [0, 0]]))
assert.deepStrictEqual(zeros([3, 2]), [[0, 0], [0, 0], [0, 0]])
})
it('should create a matrix with zeros from a matrix', function () {
assert.deepStrictEqual(zeros(matrix([3])), matrix([0, 0, 0]))
assert.deepStrictEqual(zeros(matrix([3, 2])), matrix([[0, 0], [0, 0], [0, 0]]))
})
it('should create a 3D matrix with zeros', function () {
const res = [
[
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
],
[
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
]
assert.deepStrictEqual(zeros(2, 3, 4), matrix(res))
assert.deepStrictEqual(zeros(matrix([2, 3, 4])), matrix(res))
assert.deepStrictEqual(zeros([2, 3, 4]), res)
})
// TODO: test setting `matrix`
it('should create a matrix with zeros with the same size as original matrix', function () {
const a = matrix([[1, 2, 3], [4, 5, 6]])
assert.deepStrictEqual(zeros(math.size(a)).size(), a.size())
})
// TODO: test with invalid input
it('should LaTeX zeros', function () {
const expression = math.parse('zeros(2,3)')
assert.strictEqual(expression.toTex(), '\\mathrm{zeros}\\left(2,3\\right)')
})
})