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

83 lines
3.1 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 sech = math.sech
const bigmath = math.create({ precision: 20 })
const biggermath = math.create({ number: 'BigNumber', precision: 21 })
describe('sech', function () {
it('should return the sech of a boolean', function () {
approx.equal(sech(true), 0.64805427366389)
approx.equal(sech(false), 1)
})
it('should return the sech of a number', function () {
approx.equal(sech(0), 1)
approx.equal(sech(pi), 0.086266738334054)
approx.equal(sech(1), 0.64805427366389)
approx.equal(sech(2), 0.26580222883408)
approx.equal(sech(3), 0.099327927419433)
})
it('should return the sech of a bignumber', function () {
const sechBig = bigmath.sech
const Big = bigmath.bignumber
assert.deepStrictEqual(sechBig(Big(0)), Big(1))
assert.deepStrictEqual(sechBig(Big(1)), Big('0.64805427366388539957'))
assert.deepStrictEqual(sechBig(Big(2)), Big('0.26580222883407969212'))
assert.deepStrictEqual(sechBig(Big(3)), Big('0.099327927419433207829'))
/* Pass in extra digits to pi. */
assert.deepStrictEqual(sechBig(biggermath.pi), Big('0.086266738334054414697'))
})
it('should return the sech of a complex number', function () {
approx.deepEqual(sech(complex('1')), complex(0.64805427366389, 0))
approx.deepEqual(sech(complex('i')), complex(1.8508157176809, 0))
approx.deepEqual(sech(complex('2 + i')), complex(0.15117629826558, -0.22697367539372))
})
it('should return the sech of an angle', function () {
approx.equal(sech(unit('90deg')), 0.39853681533839)
approx.equal(sech(unit('-45deg')), 0.75493970871413)
assert(math.type.isBigNumber(sech(unit(math.bignumber(90), 'deg'))))
approx.equal(sech(unit(math.bignumber(90), 'deg')).toNumber(), 0.39853681533839)
approx.deepEqual(sech(unit(complex('2 + i'), 'rad')), complex(0.15117629826558, -0.22697367539372))
})
it('should throw an error if called with an invalid unit', function () {
assert.throws(function () { sech(unit('5 celsius')) })
})
it('should throw an error if called with a string', function () {
assert.throws(function () { sech('string') })
})
const sech123 = [0.64805427366389, 0.26580222883408, 0.099327927419433]
it('should return the sech of each element of an array', function () {
approx.deepEqual(sech([1, 2, 3]), sech123)
})
it('should return the sech of each element of a matrix', function () {
approx.deepEqual(sech(matrix([1, 2, 3])), matrix(sech123))
})
it('should throw an error in case of invalid number of arguments', function () {
assert.throws(function () { sech() }, /TypeError: Too few arguments/)
assert.throws(function () { sech(1, 2) }, /TypeError: Too many arguments/)
})
it('should LaTeX sech', function () {
const expression = math.parse('sech(1)')
assert.strictEqual(expression.toTex(), '\\mathrm{sech}\\left(1\\right)')
})
})