Merge pull request #747 from josdejong/fix-operatornode-clone

OperatorNode: fix: implicit multiplication was not cloned
This commit is contained in:
Max Bruckner 2016-11-11 13:53:32 +07:00 committed by GitHub
commit e19fedcd42
2 changed files with 11 additions and 1 deletions

View File

@ -101,7 +101,7 @@ function factory (type, config, load, typed, math) {
* @return {OperatorNode}
*/
OperatorNode.prototype.clone = function () {
return new OperatorNode(this.op, this.fn, this.args.slice(0));
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit);
};
/**

View File

@ -176,6 +176,16 @@ describe('OperatorNode', function() {
assert.strictEqual(d.args[1], c.args[1]);
});
it ('should clone implicit multiplications', function () {
var two = new ConstantNode(2);
var x = new SymbolNode('x');
var node = new OperatorNode('*', 'multiply', [two, x], true);
assert.equal('2 x', node.toString());
assert.strictEqual(true, node.clone().implicit);
assert.equal(node.toString(), node.clone().toString());
});
it ('test equality another Node', function () {
var a = new OperatorNode('+', 'add', [new SymbolNode('x'), new ConstantNode(2)]);
var b = new OperatorNode('+', 'add', [new SymbolNode('x'), new ConstantNode(2)]);