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

111 lines
4.4 KiB
JavaScript

const assert = require('assert')
const math = require('../../../src/main')
const approx = require('../../../tools/approx')
const pi = math.pi
const complex = math.complex
const matrix = math.matrix
const unit = math.unit
const atan = math.atan
const tan = math.tan
const bigmath = math.create({ number: 'BigNumber', precision: 20 })
const atanBig = bigmath.atan
const Big = bigmath.bignumber
describe('atan', function () {
it('should return the arctan of a boolean', function () {
approx.equal(atan(true), 0.25 * pi)
approx.equal(atan(false), 0)
})
it('should return the arctan of a number', function () {
approx.equal(atan(-1) / pi, -0.25)
approx.equal(atan(-0.5) / pi, -0.147583617650433)
approx.equal(atan(0) / pi, 0)
approx.equal(atan(0.5) / pi, 0.147583617650433)
approx.equal(atan(1) / pi, 0.25)
})
it('should return the arctan of a bignumber', function () {
const arg1 = Big(-1)
const arg2 = Big(-0.5)
const arg3 = Big(0)
const arg6 = Big(2)
const arg7 = Big(Infinity)
assert.deepStrictEqual(atanBig(arg1), Big('-0.78539816339744830962'))
assert.deepStrictEqual(atanBig(arg2), Big('-0.46364760900080611621'))
assert.deepStrictEqual(atanBig(arg3), Big(0))
assert.deepStrictEqual(atanBig(Big(0.5)), Big('0.46364760900080611621'))
assert.deepStrictEqual(atanBig(Big(1)), Big('0.78539816339744830962'))
assert.deepStrictEqual(atanBig(arg6), Big('1.107148717794090503'))
assert.deepStrictEqual(atanBig(arg7).toString(), '1.5707963267948966192')
// Ensure the arguments where not changed
assert.deepStrictEqual(arg1, Big(-1))
assert.deepStrictEqual(arg2, Big(-0.5))
assert.deepStrictEqual(arg3, Big(0))
assert.deepStrictEqual(arg6, Big(2))
assert.deepStrictEqual(arg7.toString(), 'Infinity')
// Hit Newton's method case
bigmath.config({ precision: 61 })
assert.deepStrictEqual(atanBig(Big(0.9)), Big('0.7328151017865065916407920727342802519857556793582560863105069'))
})
it('should be the inverse function of tan', function () {
approx.equal(atan(tan(-1)), -1)
approx.equal(atan(tan(0)), 0)
approx.equal(atan(tan(0.1)), 0.1)
approx.equal(atan(tan(0.5)), 0.5)
approx.equal(atan(tan(2)), -1.14159265358979)
})
it('should be the inverse function of bignumber tan', function () {
bigmath.config({ precision: 20 })
assert.deepStrictEqual(atanBig(bigmath.tan(Big(-1))), Big(-1))
assert.deepStrictEqual(atanBig(bigmath.tan(Big(0))), Big(0))
assert.deepStrictEqual(atanBig(bigmath.tan(Big(0.1))), Big(0.1))
assert.deepStrictEqual(atanBig(bigmath.tan(Big(0.5))), Big(0.5))
assert.deepStrictEqual(atanBig(bigmath.tan(Big(2))), Big('-1.1415926535897932385'))
assert.deepStrictEqual(atanBig(bigmath.tan(bigmath.pi.div(2))).toString(), '-1.570796326794895205')
})
it('should return the arctan of a complex number', function () {
const re = 1.409921049596575
const im = 0.229072682968539
approx.deepEqual(atan(complex('2+3i')), complex(re, im))
approx.deepEqual(atan(complex('2-3i')), complex(re, -im))
approx.deepEqual(atan(complex('-2+3i')), complex(-re, im))
approx.deepEqual(atan(complex('-2-3i')), complex(-re, -im))
approx.deepEqual(atan(complex('i')), complex(0, Infinity))
approx.deepEqual(atan(complex('-i')), complex(0, -Infinity))
approx.deepEqual(atan(complex('1')), complex(0.785398163397448, 0))
approx.deepEqual(atan(complex('1+i')), complex(1.017221967897851, 0.402359478108525))
})
it('should throw an error if called with a unit', function () {
assert.throws(function () { atan(unit('45deg')) })
assert.throws(function () { atan(unit('5 celsius')) })
})
it('should throw an error if called with a string', function () {
assert.throws(function () { atan('string') })
})
it('should calculate the arctan element-wise for arrays and matrices', function () {
// matrix, array, range
const atan123 = [0.785398163397448, 1.107148717794090, 1.249045772398254]
approx.deepEqual(atan([1, 2, 3]), atan123)
approx.deepEqual(atan(matrix([1, 2, 3])), matrix(atan123))
})
it('should throw an error in case of invalid number of arguments', function () {
assert.throws(function () { atan() }, /TypeError: Too few arguments/)
assert.throws(function () { atan(1, 2) }, /TypeError: Too many arguments/)
})
it('should LaTeX atan', function () {
const expression = math.parse('atan(10)')
assert.strictEqual(expression.toTex(), '\\tan^{-1}\\left(10\\right)')
})
})