mathjs/test/function/utils/clone.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

88 lines
2.3 KiB
JavaScript

const assert = require('assert')
const math = require('../../../src/main')
describe('clone', function () {
it('should clone a boolean', function () {
assert.strictEqual(math.clone(true), true)
assert.strictEqual(math.clone(false), false)
})
it('should clone null', function () {
assert.strictEqual(math.clone(null), null)
})
it('should clone a number', function () {
let a = 1
const b = math.clone(a)
a = 2
assert.strictEqual(a, 2)
assert.strictEqual(b, 1)
})
it('should throw an error on wrong number of arguments', function () {
assert.throws(function () { math.clone() }, /TypeError: Too few arguments/)
assert.throws(function () { math.clone(2, 4) }, /TypeError: Too many arguments/)
})
it('should clone a bignumber', function () {
const a = math.bignumber('2.3e500')
const b = math.clone(a)
assert.deepStrictEqual(a, b)
})
it('should clone a string', function () {
let a = 'hello world'
const b = math.clone(a)
a = 'bye!'
assert.strictEqual(a, 'bye!')
assert.strictEqual(b, 'hello world')
})
it('should clone a complex number', function () {
const a = math.complex(2, 3)
const b = math.clone(a)
assert.notStrictEqual(a, b)
a.re = 5
assert.strictEqual(a.toString(), '5 + 3i')
assert.strictEqual(b.toString(), '2 + 3i')
})
it('should clone a unit', function () {
const a = math.unit('5mm')
const b = math.clone(a)
a.value = 10
assert.strictEqual(a.toString(), '10 m')
assert.strictEqual(b.toString(), '5 mm')
})
it('should clone a fraction', function () {
const a = math.fraction(2, 3)
const b = math.clone(a)
assert.deepStrictEqual(a, b)
})
it('should clone an array', function () {
const a = [1, 2, [3, 4]]
const b = math.clone(a)
a[2][1] = 5
assert.strictEqual(b[2][1], 4)
})
it('should clone a matrix', function () {
let a = math.matrix([[1, 2], [3, 4]])
let b = math.clone(a)
a.valueOf()[0][0] = 5
assert.strictEqual(b.valueOf()[0][0], 1)
a = math.matrix([1, 2, math.complex(2, 3), 4])
b = math.clone(a)
a.valueOf()[2].re = 5
assert.strictEqual(b.valueOf()[2].re, 2)
})
it('should LaTeX clone', function () {
const expression = math.parse('clone(1)')
assert.strictEqual(expression.toTex(), '\\mathrm{clone}\\left(1\\right)')
})
})