mathjs/test/function/complex/arg.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

74 lines
2.7 KiB
JavaScript

const assert = require('assert')
const approx = require('../../../tools/approx')
const math = require('../../../src/main')
const arg = math.arg
describe('arg', function () {
it('should compute the argument of a boolean', function () {
assert.strictEqual(arg(true), 0)
assert.strictEqual(arg(false), 0)
})
it('should compute the argument of a number', function () {
assert.strictEqual(arg(1), 0)
assert.strictEqual(arg(2), 0)
assert.strictEqual(arg(0), 0)
approx.equal(arg(-2), 3.141592653589793)
})
it('should compute the argument of a bignumber', function () {
assert.deepStrictEqual(arg(math.bignumber(1)), math.bignumber(0))
assert.deepStrictEqual(arg(math.bignumber(-2)),
math.bignumber('3.141592653589793238462643383279502884197169399375105820974944592'))
})
it('should compute the argument of a complex number correctly', function () {
assert.strictEqual(arg(math.complex('0')) / math.pi, 0)
assert.strictEqual(arg(math.complex('1 + 0i')) / math.pi, 0)
assert.strictEqual(arg(math.complex('1 + i')) / math.pi, 0.25)
assert.strictEqual(arg(math.complex('0 + i')) / math.pi, 0.5)
assert.strictEqual(arg(math.complex('-1 + i')) / math.pi, 0.75)
assert.strictEqual(arg(math.complex('-1 + 0i')) / math.pi, 1)
assert.strictEqual(arg(math.complex('-1 - i')) / math.pi, -0.75)
assert.strictEqual(arg(math.complex('0 - i')) / math.pi, -0.5)
assert.strictEqual(arg(math.complex('1 - i')) / math.pi, -0.25)
assert.strictEqual(arg(math.i) / math.pi, 0.5)
})
it('should calculate the argument for each element in a matrix', function () {
assert.deepStrictEqual(math.divide(arg([
math.i, math.unaryMinus(math.i), math.add(1, math.i)
]), math.pi), [
0.5, -0.5, 0.25
])
assert.deepStrictEqual(math.matrix(math.divide(arg([
math.i, math.unaryMinus(math.i), math.add(1, math.i)
]), math.pi)).valueOf(), [
0.5, -0.5, 0.25
])
})
it('should compute the argument of a real number correctly', function () {
assert.strictEqual(arg(2) / math.pi, 0)
assert.strictEqual(arg(-2) / math.pi, 1)
})
it('should throw an error if used with a string', function () {
assert.throws(function () { arg('string') })
})
it('should throw an error if used with a unit', function () {
assert.throws(function () { arg(math.unit('5cm')) })
})
it('should throw an error in case of invalid number of arguments', function () {
assert.throws(function () { arg() }, /TypeError: Too few arguments/)
assert.throws(function () { arg(1, 2) }, /TypeError: Too many arguments/)
})
it('should LaTeX arg', function () {
const expression = math.parse('arg(1+i)')
assert.strictEqual(expression.toTex(), '\\arg\\left(1+ i\\right)')
})
})