mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
* 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
74 lines
2.6 KiB
JavaScript
74 lines
2.6 KiB
JavaScript
const assert = require('assert')
|
|
const math = require('../../src/main')
|
|
const bool = math['boolean']
|
|
|
|
describe('boolean', function () {
|
|
it('should convert a boolean to a boolean', function () {
|
|
assert.strictEqual(bool(true), true)
|
|
assert.strictEqual(bool(false), false)
|
|
})
|
|
|
|
it('should convert null to a boolean', function () {
|
|
assert.strictEqual(bool(null), false)
|
|
})
|
|
|
|
it('should convert a number into a boolean', function () {
|
|
assert.strictEqual(bool(-2), true)
|
|
assert.strictEqual(bool(-1), true)
|
|
assert.strictEqual(bool(0), false)
|
|
assert.strictEqual(bool(1), true)
|
|
assert.strictEqual(bool(2), true)
|
|
})
|
|
|
|
it('should convert a bignumber into a boolean', function () {
|
|
assert.strictEqual(bool(math.bignumber(-2)), true)
|
|
assert.strictEqual(bool(math.bignumber(-1)), true)
|
|
assert.strictEqual(bool(math.bignumber(0)), false)
|
|
assert.strictEqual(bool(math.bignumber(1)), true)
|
|
assert.strictEqual(bool(math.bignumber(2)), true)
|
|
})
|
|
|
|
it('should convert the elements of a matrix or array to booleans', function () {
|
|
assert.deepStrictEqual(bool(math.matrix([1, 0, 1, 1])), math.matrix([true, false, true, true]))
|
|
assert.deepStrictEqual(bool([1, 0, 1, 1]), [true, false, true, true])
|
|
})
|
|
|
|
it('should convert a string into a boolean', function () {
|
|
assert.strictEqual(bool('true'), true)
|
|
assert.strictEqual(bool('false'), false)
|
|
|
|
assert.strictEqual(bool('True'), true)
|
|
assert.strictEqual(bool('False'), false)
|
|
|
|
assert.strictEqual(bool('1'), true)
|
|
assert.strictEqual(bool('0'), false)
|
|
assert.strictEqual(bool(' 0 '), false)
|
|
|
|
assert.strictEqual(bool('2'), true)
|
|
assert.strictEqual(bool(' 4e2 '), true)
|
|
assert.strictEqual(bool(' -4e2 '), true)
|
|
})
|
|
|
|
it('should throw an error if the string is not a valid number', function () {
|
|
assert.throws(function () { bool('') }, /Error: Cannot convert/)
|
|
assert.throws(function () { bool('23a') }, /Error: Cannot convert/)
|
|
})
|
|
|
|
it('should throw an error if there\'s a wrong number of arguments', function () {
|
|
assert.throws(function () { bool(1, 2) }, /TypeError: Too many arguments/)
|
|
})
|
|
|
|
it('should throw an error if used with a complex', function () {
|
|
assert.throws(function () { bool(math.complex(2, 3)) }, /TypeError: Unexpected type of argument/)
|
|
})
|
|
|
|
it('should throw an error if used with a unit', function () {
|
|
assert.throws(function () { bool(math.unit('5cm')) }, /TypeError: Unexpected type of argument/)
|
|
})
|
|
|
|
it('should LaTeX boolean', function () {
|
|
const expression = math.parse('boolean(1)')
|
|
assert.strictEqual(expression.toTex(), '\\mathrm{boolean}\\left(1\\right)')
|
|
})
|
|
})
|