mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
* Add `.js` extension to source file imports * Specify package `exports` in `package.json` Specify package type as `commonjs` (It's good to be specific) * Move all compiled scripts into `lib` directory Remove ./number.js (You can use the compiled ones in `./lib/*`) Tell node that the `esm` directory is type `module` and enable tree shaking. Remove unused files from packages `files` property * Allow importing of package.json * Make library ESM first * - Fix merge conflicts - Refactor `bundleAny` into `defaultInstance.js` and `browserBundle.cjs` - Refactor unit tests to be able to run with plain nodejs (no transpiling) - Fix browser examples * Fix browser and browserstack tests * Fix running unit tests on Node 10 (which has no support for modules) * Fix node.js examples (those are still commonjs) * Remove the need for `browserBundle.cjs` * Generate minified bundle only * [Security] Bump node-fetch from 2.6.0 to 2.6.1 (#1963) Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. **This update includes a security fix.** - [Release notes](https://github.com/bitinn/node-fetch/releases) - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Cleanup console.log * Add integration tests to test the entry points (commonjs/esm, full/number only) * Create backward compatibility error messages in the files moved/removed since v8 * Describe breaking changes in HISTORY.md * Bump karma from 5.2.1 to 5.2.2 (#1965) Bumps [karma](https://github.com/karma-runner/karma) from 5.2.1 to 5.2.2. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v5.2.1...v5.2.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Lee Langley-Rees <lee@greenimp.co.uk> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
190 lines
8.5 KiB
JavaScript
190 lines
8.5 KiB
JavaScript
// test and
|
|
import assert from 'assert'
|
|
|
|
import math from '../../../../src/defaultInstance.js'
|
|
const bignumber = math.bignumber
|
|
const complex = math.complex
|
|
const matrix = math.matrix
|
|
const sparse = math.sparse
|
|
const unit = math.unit
|
|
const and = math.and
|
|
|
|
describe('and', function () {
|
|
it('should and two numbers correctly', function () {
|
|
assert.strictEqual(and(1, 1), true)
|
|
assert.strictEqual(and(-1, 1), true)
|
|
assert.strictEqual(and(-1, -1), true)
|
|
assert.strictEqual(and(0, -1), false)
|
|
assert.strictEqual(and(1, 0), false)
|
|
assert.strictEqual(and(1, NaN), false)
|
|
assert.strictEqual(and(NaN, 1), false)
|
|
assert.strictEqual(and(1e10, 0.019209), true)
|
|
assert.strictEqual(and(-1.0e-100, 1.0e-100), true)
|
|
assert.strictEqual(and(Infinity, -Infinity), true)
|
|
})
|
|
|
|
it('should and two complex numbers', function () {
|
|
assert.strictEqual(and(complex(1, 1), complex(1, 1)), true)
|
|
assert.strictEqual(and(complex(0, 1), complex(1, 1)), true)
|
|
assert.strictEqual(and(complex(1, 0), complex(1, 1)), true)
|
|
assert.strictEqual(and(complex(1, 1), complex(0, 1)), true)
|
|
assert.strictEqual(and(complex(1, 1), complex(1, 0)), true)
|
|
assert.strictEqual(and(complex(1, 0), complex(1, 0)), true)
|
|
assert.strictEqual(and(complex(0, 1), complex(0, 1)), true)
|
|
assert.strictEqual(and(complex(0, 0), complex(1, 1)), false)
|
|
assert.strictEqual(and(complex(0, 0), complex(0, 1)), false)
|
|
assert.strictEqual(and(complex(0, 0), complex(1, 0)), false)
|
|
assert.strictEqual(and(complex(1, 1), complex(0, 0)), false)
|
|
assert.strictEqual(and(complex(0, 1), complex(0, 0)), false)
|
|
assert.strictEqual(and(complex(1, 0), complex(0, 0)), false)
|
|
assert.strictEqual(and(complex(), complex(1, 1)), false)
|
|
assert.strictEqual(and(complex(0), complex(1, 1)), false)
|
|
assert.strictEqual(and(complex(1), complex(1, 1)), true)
|
|
assert.strictEqual(and(complex(1, 1), complex()), false)
|
|
assert.strictEqual(and(complex(1, 1), complex(0)), false)
|
|
assert.strictEqual(and(complex(1, 1), complex(1)), true)
|
|
})
|
|
|
|
it('should and mixed numbers and complex numbers', function () {
|
|
assert.strictEqual(and(complex(1, 1), 1), true)
|
|
assert.strictEqual(and(complex(1, 1), 0), false)
|
|
assert.strictEqual(and(1, complex(1, 1)), true)
|
|
assert.strictEqual(and(0, complex(1, 1)), false)
|
|
assert.strictEqual(and(complex(0, 0), 1), false)
|
|
assert.strictEqual(and(1, complex(0, 0)), false)
|
|
})
|
|
|
|
it('should and two booleans', function () {
|
|
assert.strictEqual(and(true, true), true)
|
|
assert.strictEqual(and(true, false), false)
|
|
assert.strictEqual(and(false, true), false)
|
|
assert.strictEqual(and(false, false), false)
|
|
})
|
|
|
|
it('should and mixed numbers and booleans', function () {
|
|
assert.strictEqual(and(2, true), true)
|
|
assert.strictEqual(and(2, false), false)
|
|
assert.strictEqual(and(0, true), false)
|
|
assert.strictEqual(and(true, 2), true)
|
|
assert.strictEqual(and(false, 2), false)
|
|
})
|
|
|
|
it('should and bignumbers', function () {
|
|
assert.strictEqual(and(bignumber(1), bignumber(1)), true)
|
|
assert.strictEqual(and(bignumber(-1), bignumber(1)), true)
|
|
assert.strictEqual(and(bignumber(-1), bignumber(-1)), true)
|
|
assert.strictEqual(and(bignumber(0), bignumber(-1)), false)
|
|
assert.strictEqual(and(bignumber(1), bignumber(0)), false)
|
|
assert.strictEqual(and(bignumber(1), bignumber(NaN)), false)
|
|
assert.strictEqual(and(bignumber(NaN), bignumber(1)), false)
|
|
assert.strictEqual(and(bignumber('1e+10'), bignumber(0.19209)), true)
|
|
assert.strictEqual(and(bignumber('-1.0e-100'), bignumber('1.0e-100')), true)
|
|
assert.strictEqual(and(bignumber(Infinity), bignumber(-Infinity)), true)
|
|
})
|
|
|
|
it('should and mixed numbers and bignumbers', function () {
|
|
assert.strictEqual(and(bignumber(2), 3), true)
|
|
assert.strictEqual(and(2, bignumber(2)), true)
|
|
assert.strictEqual(and(0, bignumber(2)), false)
|
|
assert.strictEqual(and(2, bignumber(0)), false)
|
|
assert.strictEqual(and(bignumber(0), 2), false)
|
|
assert.strictEqual(and(bignumber(2), 0), false)
|
|
})
|
|
|
|
it('should and two units', function () {
|
|
assert.strictEqual(and(unit('100cm'), unit('10inch')), true)
|
|
assert.strictEqual(and(unit('100cm'), unit('0 inch')), false)
|
|
assert.strictEqual(and(unit('0cm'), unit('1m')), false)
|
|
assert.strictEqual(and(unit('m'), unit('1m')), false)
|
|
assert.strictEqual(and(unit('1dm'), unit('m')), false)
|
|
assert.strictEqual(and(unit('-100cm'), unit('-10inch')), true)
|
|
assert.strictEqual(and(unit(5, 'km'), unit(100, 'gram')), true)
|
|
assert.strictEqual(and(unit(5, 'km'), unit(0, 'gram')), false)
|
|
assert.strictEqual(and(unit(0, 'km'), unit(100, 'gram')), false)
|
|
|
|
assert.strictEqual(and(unit(bignumber(0), 'm'), unit(bignumber(0), 'm')), false)
|
|
assert.strictEqual(and(unit(bignumber(1), 'm'), unit(bignumber(0), 'm')), false)
|
|
assert.strictEqual(and(unit(bignumber(0), 'm'), unit(bignumber(1), 'm')), false)
|
|
assert.strictEqual(and(unit(bignumber(1), 'm'), unit(bignumber(1), 'm')), true)
|
|
})
|
|
|
|
describe('Array', function () {
|
|
it('should and array - scalar', function () {
|
|
assert.deepStrictEqual(and(10, [0, 2]), [false, true])
|
|
assert.deepStrictEqual(and([0, 2], 10), [false, true])
|
|
})
|
|
|
|
it('should and array - array', function () {
|
|
assert.deepStrictEqual(and([0, 1, 0, 12], [0, 0, 1, 22]), [false, false, false, true])
|
|
assert.deepStrictEqual(and([], []), [])
|
|
})
|
|
|
|
it('should and array - dense matrix', function () {
|
|
assert.deepStrictEqual(and([0, 1, 0, 12], matrix([0, 0, 1, 22])), matrix([false, false, false, true]))
|
|
assert.deepStrictEqual(and([], matrix([])), matrix([]))
|
|
})
|
|
|
|
it('should and array - sparse matrix', function () {
|
|
assert.deepStrictEqual(and([[0, 1], [0, 12]], sparse([[0, 0], [1, 22]])), sparse([[false, false], [false, true]]))
|
|
})
|
|
})
|
|
|
|
describe('DenseMatrix', function () {
|
|
it('should and dense matrix - scalar', function () {
|
|
assert.deepStrictEqual(and(10, matrix([0, 2])), matrix([false, true]))
|
|
assert.deepStrictEqual(and(matrix([0, 2]), 10), matrix([false, true]))
|
|
})
|
|
|
|
it('should and dense matrix - array', function () {
|
|
assert.deepStrictEqual(and(matrix([0, 1, 0, 12]), [0, 0, 1, 22]), matrix([false, false, false, true]))
|
|
assert.deepStrictEqual(and(matrix([]), []), matrix([]))
|
|
})
|
|
|
|
it('should and dense matrix - dense matrix', function () {
|
|
assert.deepStrictEqual(and(matrix([0, 1, 0, 12]), matrix([0, 0, 1, 22])), matrix([false, false, false, true]))
|
|
assert.deepStrictEqual(and(matrix([]), matrix([])), matrix([]))
|
|
})
|
|
|
|
it('should and dense matrix - sparse matrix', function () {
|
|
assert.deepStrictEqual(and(matrix([[0, 1], [0, 12]]), sparse([[0, 0], [1, 22]])), sparse([[false, false], [false, true]]))
|
|
})
|
|
})
|
|
|
|
describe('SparseMatrix', function () {
|
|
it('should and sparse matrix - scalar', function () {
|
|
assert.deepStrictEqual(and(10, sparse([[0], [2]])), sparse([[false], [true]]))
|
|
assert.deepStrictEqual(and(sparse([[0], [2]]), 10), sparse([[false], [true]]))
|
|
})
|
|
|
|
it('should and sparse matrix - array', function () {
|
|
assert.deepStrictEqual(and(sparse([[0, 1], [0, 12]]), [[0, 0], [1, 22]]), sparse([[false, false], [false, true]]))
|
|
})
|
|
|
|
it('should and sparse matrix - dense matrix', function () {
|
|
assert.deepStrictEqual(and(sparse([[0, 1], [0, 12]]), matrix([[0, 0], [1, 22]])), sparse([[false, false], [false, true]]))
|
|
})
|
|
|
|
it('should and sparse matrix - sparse matrix', function () {
|
|
assert.deepStrictEqual(and(sparse([[0, 1], [0, 12]]), sparse([[0, 0], [1, 22]])), sparse([[false, false], [false, true]]))
|
|
})
|
|
})
|
|
|
|
it('should throw an error in case of invalid number of arguments', function () {
|
|
assert.throws(function () { and(1) }, /TypeError: Too few arguments/)
|
|
assert.throws(function () { and(1, 2, 3) }, /TypeError: Too many arguments/)
|
|
})
|
|
|
|
it('should throw an error in case of invalid type of arguments', function () {
|
|
assert.throws(function () { and(2, null) }, /TypeError: Unexpected type of argument/)
|
|
assert.throws(function () { and(new Date(), true) }, /TypeError: Unexpected type of argument/)
|
|
assert.throws(function () { and(true, new Date()) }, /TypeError: Unexpected type of argument/)
|
|
assert.throws(function () { and(true, undefined) }, /TypeError: Unexpected type of argument/)
|
|
assert.throws(function () { and(undefined, true) }, /TypeError: Unexpected type of argument/)
|
|
})
|
|
|
|
it('should LaTeX and', function () {
|
|
const expression = math.parse('and(1,2)')
|
|
assert.strictEqual(expression.toTex(), '\\left(1\\wedge2\\right)')
|
|
})
|
|
})
|