mathjs/test/function/relational/equalText.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

69 lines
3.2 KiB
JavaScript

// test equalText
const assert = require('assert')
const math = require('../../../src/main')
const bignumber = math.bignumber
const matrix = math.matrix
const sparse = math.sparse
const equalText = math.equalText
describe('equalText', function () {
it('should perform lexical comparison for two strings', function () {
assert.strictEqual(equalText('abd', 'abc'), false)
assert.strictEqual(equalText('abc', 'abc'), true)
assert.strictEqual(equalText('abc', 'abd'), false)
// lexical sorting of strings
assert.strictEqual(equalText('2', '10'), false)
assert.strictEqual(equalText('10', '2'), false)
assert.strictEqual(equalText('10', '10'), true)
assert.strictEqual(equalText('2e3', '2000'), false)
})
describe('Array', function () {
it('should compare array - scalar', function () {
assert.deepStrictEqual(equalText('B', ['A', 'B', 'C']), [false, true, false])
assert.deepStrictEqual(equalText(['A', 'B', 'C'], 'B'), [false, true, false])
})
it('should compare array - array', function () {
assert.deepStrictEqual(equalText([['D', 'E', 'C'], ['B', 'C', 'E']], [['F', 'B', 'C'], ['A', 'D', 'C']]), [[false, false, true], [false, false, false]])
})
it('should compare array - dense matrix', function () {
assert.deepStrictEqual(equalText([['D', 'E', 'C'], ['B', 'C', 'E']], matrix([['F', 'B', 'C'], ['A', 'D', 'C']])), matrix([[false, false, true], [false, false, false]]))
})
})
describe('DenseMatrix', function () {
it('should compare dense matrix - scalar', function () {
assert.deepStrictEqual(equalText('B', matrix(['A', 'B', 'C'])), matrix([false, true, false]))
assert.deepStrictEqual(equalText(matrix(['A', 'B', 'C']), 'B'), matrix([false, true, false]))
})
it('should compare dense matrix - array', function () {
assert.deepStrictEqual(equalText(matrix([['D', 'E', 'C'], ['B', 'C', 'E']]), [['F', 'B', 'C'], ['A', 'D', 'C']]), matrix([[false, false, true], [false, false, false]]))
})
it('should compare dense matrix - dense matrix', function () {
assert.deepStrictEqual(equalText(matrix([['D', 'E', 'C'], ['B', 'C', 'E']]), matrix([['F', 'B', 'C'], ['A', 'D', 'C']])), matrix([[false, false, true], [false, false, false]]))
})
})
it('should throw an error in case of invalid type of arguments', function () {
assert.throws(function () { equalText(1, 2) }, /TypeError: Unexpected type of argument in function compareText/)
assert.throws(function () { equalText('A', sparse([['A', 'B'], ['C', 'D']])) }, /Cannot convert "A" to a number/)
assert.throws(function () { equalText(bignumber(1), '2') }, /TypeError: Unexpected type of argument in function compareText/)
assert.throws(function () { equalText('2', bignumber(1)) }, /TypeError: Unexpected type of argument in function compareText/)
})
it('should throw an error in case of invalid number of arguments', function () {
assert.throws(function () { equalText(1) }, /TypeError: Too few arguments/)
assert.throws(function () { equalText(1, 2, 3) }, /TypeError: Too many arguments/)
})
it('should LaTeX compare', function () {
const expression = math.parse('equalText(1,2)')
assert.strictEqual(expression.toTex(), '\\mathrm{equalText}\\left(1,2\\right)')
})
})