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

70 lines
2.7 KiB
JavaScript

const assert = require('assert')
const math = require('../../../src/main')
const mode = math.mode
const DenseMatrix = math.type.DenseMatrix
describe('mode', function () {
it('should return the mode accurately for one dimensional array', function () {
assert.deepStrictEqual(mode([1, 2.7, 3.2, 4, 2.7]), [2.7])
assert.deepStrictEqual(mode([13, 24, 35, 46, 13]), [13])
assert.deepStrictEqual(mode([1, 5, -5, 1]), [1])
})
it('should return the correct mode when there are more than one values of mode', function () {
assert.deepStrictEqual(mode([1, 2.7, 3.2, 3.2, 4, 2.7]), [3.2, 2.7])
assert.deepStrictEqual(mode([13, 24, 35, 46]), [13, 24, 35, 46])
assert.deepStrictEqual(mode(['boston', 'delhi', 'cape town']), ['boston', 'delhi', 'cape town'])
})
it('should return the mode accurately for loose arguments', function () {
assert.deepStrictEqual(mode(2, 1, 4, 3, 1), [1])
assert.deepStrictEqual(mode('a', 'b', 'c', 'b'), ['b'])
})
it('should return the mode of booleans', function () {
assert.deepStrictEqual(mode(true, true, false), [true])
assert.deepStrictEqual(mode(true, [false, false]), [false])
})
it('should return the mode correctly for different datatypes', function () {
assert.deepStrictEqual(mode(2, 1, 'f', 3.5, 1.0), [1])
assert.deepStrictEqual(mode('a', 'b', 4, 'b'), ['b'])
})
it('should not throw an error if the input contains mixture of array and non-array values', function () {
assert.deepStrictEqual(mode(1, [3], [1, 2, 3, 7], 3, [8]), [3])
assert.deepStrictEqual(mode([1], 3, [3]), [3])
assert.deepStrictEqual(mode([13, 24], [35, 46]), [13, 24, 35, 46])
assert.deepStrictEqual(mode([], 0), [0])
})
it('should return NaN if any of the inputs contains NaN', function () {
assert.throws(function () { mode(NaN) }, /Cannot calculate mode/)
assert.throws(function () { mode([NaN]) }, /Cannot calculate mode/)
assert.throws(function () { mode([1, NaN]) }, /Cannot calculate mode/)
})
it('should throw appropriate error if no parameters are assigned', function () {
assert.throws(function () { mode([]) })
assert.throws(function () { mode() })
})
/* TODO :
it('should throw appropriate error if parameters contain array of arrays or nested arrays', function(){
assert.throws(function() {mode([1][3][3])})
assert.throws(function() {mode([a[b, a]])})
})
*/
it('should return the mode of a 1D matrix', function () {
assert.deepStrictEqual(mode(new DenseMatrix([1, 3, 5, 2, -5, 3])), [3])
})
it('should return the mode of a 2D matrix', function () {
assert.deepStrictEqual(mode(new DenseMatrix([
[1, 4, 0],
[3, 0, 5]
])), [0])
})
})