mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Fix unit tests broken on Nodejs 6 and 8 (no proper NaN assertions)
This commit is contained in:
parent
b6ab40cf88
commit
56a52f6dfd
@ -64,8 +64,7 @@ function factory (type, config, load, typed) {
|
||||
function _sqrtNumber (x) {
|
||||
if (isNaN(x)) {
|
||||
return NaN
|
||||
}
|
||||
else if (x >= 0 || config.predictable) {
|
||||
} else if (x >= 0 || config.predictable) {
|
||||
return Math.sqrt(x)
|
||||
} else {
|
||||
return new type.Complex(x, 0).sqrt()
|
||||
|
||||
@ -90,8 +90,7 @@ function factory (type, config, load, typed) {
|
||||
try {
|
||||
if (isNaN(value) && typeof value === 'number') {
|
||||
max = NaN
|
||||
}
|
||||
else if (max === undefined || larger(value, max)) {
|
||||
} else if (max === undefined || larger(value, max)) {
|
||||
max = value
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@ -90,8 +90,7 @@ function factory (type, config, load, typed) {
|
||||
try {
|
||||
if (isNaN(value) && typeof value === 'number') {
|
||||
min = NaN
|
||||
}
|
||||
else if (min === undefined || smaller(value, min)) {
|
||||
} else if (min === undefined || smaller(value, min)) {
|
||||
min = value
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@ -44,12 +44,12 @@ describe('mad', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(mad([NaN]), NaN)
|
||||
assert.strictEqual(mad([1, NaN]), NaN)
|
||||
assert.strictEqual(mad([NaN, 1]), NaN)
|
||||
assert.strictEqual(mad([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(mad([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(mad(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(mad([NaN])))
|
||||
assert(isNaN(mad([1, NaN])))
|
||||
assert(isNaN(mad([NaN, 1])))
|
||||
assert(isNaN(mad([1, 3, NaN])))
|
||||
assert(isNaN(mad([NaN, NaN, NaN])))
|
||||
assert(isNaN(mad(NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error if called with invalid number of arguments', function () {
|
||||
|
||||
@ -67,12 +67,12 @@ describe('max', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(max([NaN]), NaN)
|
||||
assert.strictEqual(max([1, NaN]), NaN)
|
||||
assert.strictEqual(max([NaN, 1]), NaN)
|
||||
assert.strictEqual(max([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(max([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(max(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(max([NaN])))
|
||||
assert(isNaN(max([1, NaN])))
|
||||
assert(isNaN(max([NaN, 1])))
|
||||
assert(isNaN(max([1, 3, NaN])))
|
||||
assert(isNaN(max([NaN, NaN, NaN])))
|
||||
assert(isNaN(max(NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error when called multiple arrays or matrices', function () {
|
||||
|
||||
@ -73,12 +73,12 @@ describe('mean', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(mean([NaN]), NaN)
|
||||
assert.strictEqual(mean([1, NaN]), NaN)
|
||||
assert.strictEqual(mean([NaN, 1]), NaN)
|
||||
assert.strictEqual(mean([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(mean([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(mean(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(mean([NaN])))
|
||||
assert(isNaN(mean([1, NaN])))
|
||||
assert(isNaN(mean([NaN, 1])))
|
||||
assert(isNaN(mean([1, 3, NaN])))
|
||||
assert(isNaN(mean([NaN, NaN, NaN])))
|
||||
assert(isNaN(mean(NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error if called with invalid number of arguments', function () {
|
||||
|
||||
@ -68,12 +68,12 @@ describe('median', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(median([NaN]), NaN)
|
||||
assert.strictEqual(median([1, NaN]), NaN)
|
||||
assert.strictEqual(median([NaN, 1]), NaN)
|
||||
assert.strictEqual(median([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(median([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(median(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(median([NaN])))
|
||||
assert(isNaN(median([1, NaN])))
|
||||
assert(isNaN(median([NaN, 1])))
|
||||
assert(isNaN(median([1, 3, NaN])))
|
||||
assert(isNaN(median([NaN, NaN, NaN])))
|
||||
assert(isNaN(median(NaN, NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error if called with invalid number of arguments', function () {
|
||||
|
||||
@ -76,12 +76,12 @@ describe('min', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(min([NaN]), NaN)
|
||||
assert.strictEqual(min([1, NaN]), NaN)
|
||||
assert.strictEqual(min([NaN, 1]), NaN)
|
||||
assert.strictEqual(min([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(min([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(min(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(min([NaN])))
|
||||
assert(isNaN(min([1, NaN])))
|
||||
assert(isNaN(min([NaN, 1])))
|
||||
assert(isNaN(min([1, 3, NaN])))
|
||||
assert(isNaN(min([NaN, NaN, NaN])))
|
||||
assert(isNaN(min(NaN, NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error when called multiple arrays or matrices', function () {
|
||||
|
||||
@ -50,12 +50,12 @@ describe('prod', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(prod([NaN]), NaN)
|
||||
assert.strictEqual(prod([1, NaN]), NaN)
|
||||
assert.strictEqual(prod([NaN, 1]), NaN)
|
||||
assert.strictEqual(prod([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(prod([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(prod(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(prod([NaN])))
|
||||
assert(isNaN(prod([1, NaN])))
|
||||
assert(isNaN(prod([NaN, 1])))
|
||||
assert(isNaN(prod([1, 3, NaN])))
|
||||
assert(isNaN(prod([NaN, NaN, NaN])))
|
||||
assert(isNaN(prod(NaN, NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error if called with invalid number of arguments', function () {
|
||||
|
||||
@ -43,12 +43,12 @@ describe('std', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(std([NaN]), NaN)
|
||||
assert.strictEqual(std([1, NaN]), NaN)
|
||||
assert.strictEqual(std([NaN, 1]), NaN)
|
||||
assert.strictEqual(std([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(std([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(std(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(std([NaN])))
|
||||
assert(isNaN(std([1, NaN])))
|
||||
assert(isNaN(std([NaN, 1])))
|
||||
assert(isNaN(std([1, 3, NaN])))
|
||||
assert(isNaN(std([NaN, NaN, NaN])))
|
||||
assert(isNaN(std(NaN, NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error in case of unknown type of normalization', function () {
|
||||
|
||||
@ -62,12 +62,12 @@ describe('sum', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(sum([NaN]), NaN)
|
||||
assert.strictEqual(sum([1, NaN]), NaN)
|
||||
assert.strictEqual(sum([NaN, 1]), NaN)
|
||||
assert.strictEqual(sum([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(sum([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(sum(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(sum([NaN])))
|
||||
assert(isNaN(sum([1, NaN])))
|
||||
assert(isNaN(sum([NaN, 1])))
|
||||
assert(isNaN(sum([1, 3, NaN])))
|
||||
assert(isNaN(sum([NaN, NaN, NaN])))
|
||||
assert(isNaN(sum(NaN, NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error if called with invalid number of arguments', function () {
|
||||
|
||||
@ -41,12 +41,12 @@ describe('variance', function () {
|
||||
})
|
||||
|
||||
it('should return NaN if any of the inputs contains NaN', function () {
|
||||
assert.strictEqual(variance([NaN]), NaN)
|
||||
assert.strictEqual(variance([1, NaN]), NaN)
|
||||
assert.strictEqual(variance([NaN, 1]), NaN)
|
||||
assert.strictEqual(variance([1, 3, NaN]), NaN)
|
||||
assert.strictEqual(variance([NaN, NaN, NaN]), NaN)
|
||||
assert.strictEqual(variance(NaN, NaN, NaN), NaN)
|
||||
assert(isNaN(variance([NaN])))
|
||||
assert(isNaN(variance([1, NaN])))
|
||||
assert(isNaN(variance([NaN, 1])))
|
||||
assert(isNaN(variance([1, 3, NaN])))
|
||||
assert(isNaN(variance([NaN, NaN, NaN])))
|
||||
assert(isNaN(variance(NaN, NaN, NaN)))
|
||||
})
|
||||
|
||||
it('should throw an error in case of unknown type of normalization', function () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user