mathjs/test/function/arithmetic/hypot.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

55 lines
2.2 KiB
JavaScript

// test hypot
const assert = require('assert')
const approx = require('../../../tools/approx')
const math = require('../../../src/main')
const hypot = math.hypot
const bignumber = math.bignumber
describe('hypot', function () {
it('should return the hypot of numbers', function () {
assert.strictEqual(hypot(3, 4), 5)
assert.strictEqual(hypot(3, -4), 5)
approx.equal(hypot(3, 4, 5), 7.0710678118654755)
assert.strictEqual(hypot(-2), 2)
assert.strictEqual(hypot(0), 0)
assert.strictEqual(hypot(Infinity), Infinity)
})
it('should return the hypot of BigNumbers', function () {
assert.deepStrictEqual(hypot(bignumber(3), bignumber(4)), bignumber(5))
assert.deepStrictEqual(hypot(bignumber(3), bignumber(-4)), bignumber(5))
assert.deepStrictEqual(hypot(bignumber(3), bignumber(4), bignumber(5)),
bignumber('7.07106781186547524400844362104849039284835937688474036588339869'))
assert.deepStrictEqual(hypot(bignumber(-2)), bignumber(2))
})
it('should return the hypot of an Array with numbers', function () {
assert.strictEqual(hypot([3, 4]), 5)
})
it('should return the hypot of an Matrix with numbers', function () {
assert.strictEqual(hypot(math.matrix([3, 4])), 5)
})
it('should return the hypot of an Array with mixed numbers and BigNumbers', function () {
assert.deepStrictEqual(hypot([3, bignumber(4)]), bignumber(5))
})
it('should throw an error in case of invalid number of arguments', function () {
assert.throws(function () { hypot() }, /TypeError: Too few arguments/)
assert.throws(function () { hypot([], 2) }, /TypeError: Too many arguments/)
})
it('should throw an error in case of unsupported types', function () {
assert.throws(function () { hypot(new Date()) }, /TypeError: Unexpected type of argument/)
assert.throws(function () { hypot([new Date()]) }, /TypeError: Unexpected type of argument/)
assert.throws(function () { hypot([2, 3, math.complex()]) }, /TypeError: Unexpected type of argument/)
assert.throws(function () { hypot(undefined) }, /TypeError: Unexpected type of argument/)
})
it('should LaTeX hypot', function () {
const expression = math.parse('hypot(3,4)')
assert.strictEqual(expression.toTex(), '\\hypot\\left(3,4\\right)')
})
})