mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
Note for this to work in a broad variety of contexts, has to also allow identical expressions to cancel regardless of whether subtraction is always defined; but this seems safe in general, that x-x is 0 even if x does not generally have an additive inverse (for example, when working in the positive context). Resolves #1260.
33 lines
1003 B
JavaScript
33 lines
1003 B
JavaScript
import assert from 'assert'
|
|
import math from '../../../../src/defaultInstance.js'
|
|
|
|
function assertFalse (val) {
|
|
assert(!val)
|
|
}
|
|
|
|
describe('symbolicEqual', function () {
|
|
it('relates anything to itself', function () {
|
|
assert(math.symbolicEqual('x', 'x'))
|
|
assert(math.symbolicEqual('foo(x)', 'foo(x)'))
|
|
})
|
|
|
|
it('does not relate different variables', function () {
|
|
assertFalse(math.symbolicEqual('x', 'y'))
|
|
assertFalse(math.symbolicEqual('foo(x)+bar(x)', 'foo(x)+bar(y)'))
|
|
})
|
|
|
|
it('handles various manipulations', function () {
|
|
assert(math.symbolicEqual('3x', 'x*3'))
|
|
assert(math.symbolicEqual('x*y', 'y*x'))
|
|
assert(math.symbolicEqual('x*y^2', 'y*x*y'))
|
|
assert(math.symbolicEqual('x*(2y - y -y)', '0*z'))
|
|
})
|
|
|
|
it('responds to context', function () {
|
|
assertFalse(math.symbolicEqual(
|
|
'x*y', 'y*x', { context: { multiply: { commutative: false } } }))
|
|
assert(math.symbolicEqual(
|
|
'abs(x)', 'x', { context: math.simplify.positiveContext }))
|
|
})
|
|
})
|