mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
// test OperatorNode
|
|
var assert = require('assert'),
|
|
approx = require('../../../tools/approx'),
|
|
math = require('../../../index')(),
|
|
Node = require('../../../lib/expression/node/Node'),
|
|
ConstantNode = require('../../../lib/expression/node/ConstantNode'),
|
|
OperatorNode = require('../../../lib/expression/node/OperatorNode');
|
|
|
|
describe('OperatorNode', function() {
|
|
|
|
it ('should compile an OperatorNode', function () {
|
|
var a = new ConstantNode('number', '2', math);
|
|
var b = new ConstantNode('number', '3', math);
|
|
var n = new OperatorNode('+', 'add', math.add, [a, b]);
|
|
|
|
var expr = n.compile(math);
|
|
|
|
assert.equal(expr.eval(), 5);
|
|
});
|
|
|
|
it ('should find a OperatorNode', function () {
|
|
// TODO
|
|
});
|
|
|
|
it ('should match a OperatorNode', function () {
|
|
// TODO
|
|
});
|
|
|
|
it ('should stringify a OperatorNode', function () {
|
|
var a = new ConstantNode('number', '2', math);
|
|
var b = new ConstantNode('number', '3', math);
|
|
var n = new OperatorNode('+', 'add', math.add, [a, b]);
|
|
assert.equal(n.toString(), '2 + 3');
|
|
|
|
var n2 = new OperatorNode('!', 'factorial', math.factorial, [b]);
|
|
assert.equal(n2.toString(), '3!');
|
|
|
|
var n3 = new OperatorNode('-', 'unary', math.unary, [b]);
|
|
assert.equal(n3.toString(), '-3');
|
|
});
|
|
|
|
});
|