Skip to content

Commit

Permalink
Fixed #765: FunctionAssignmentNode.toString() returning a string in…
Browse files Browse the repository at this point in the history
…compatible with the function assignment syntax
  • Loading branch information
josdejong committed Dec 18, 2016
1 parent 3c704a6 commit 79993ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
@@ -1,6 +1,12 @@
# History


## not yet released, version 3.8.2

- Fixed #765: `FunctionAssignmentNode.toString()` returning a string
incompatible with the function assignment syntax.


## 2016-12-15, version 3.8.1

- Implemented function `mad` (median absolute deviation). Thanks @ruhleder.
Expand Down
3 changes: 1 addition & 2 deletions lib/expression/node/FunctionAssignmentNode.js
Expand Up @@ -139,8 +139,7 @@ function factory (type, config, load, typed) {
if (needParenthesis(this, parenthesis)) {
expr = '(' + expr + ')';
}
return 'function ' + this.name +
'(' + this.params.join(', ') + ') = ' + expr;
return this.name + '(' + this.params.join(', ') + ') = ' + expr;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions test/expression/node/FunctionAssignmentNode.test.js
Expand Up @@ -284,7 +284,7 @@ describe('FunctionAssignmentNode', function() {

it ('should respect the \'all\' parenthesis option', function () {
var expr = math.parse('f(x)=x+1');
assert.equal(expr.toString({parenthesis: 'all'}), 'function f(x) = (x + 1)');
assert.equal(expr.toString({parenthesis: 'all'}), 'f(x) = (x + 1)');
assert.equal(expr.toTex({parenthesis: 'all'}), '\\mathrm{f}\\left(x\\right):=\\left( x+1\\right)');
});

Expand All @@ -294,7 +294,7 @@ describe('FunctionAssignmentNode', function() {
var o = new OperatorNode('+', 'add', [a, x]);
var n = new FunctionAssignmentNode('f', ['x'], o);

assert.equal(n.toString(), 'function f(x) = 2 + x');
assert.equal(n.toString(), 'f(x) = 2 + x');
});

it ('should stringify a FunctionAssignmentNode conataining an AssignmentNode', function () {
Expand All @@ -303,7 +303,7 @@ describe('FunctionAssignmentNode', function() {
var n1 = new AssignmentNode(new SymbolNode('a'), a);
var n = new FunctionAssignmentNode('f', ['x'], n1);

assert.equal(n.toString(), 'function f(x) = (a = 2)');
assert.equal(n.toString(), 'f(x) = (a = 2)');
});

it ('should stringify a FunctionAssignmentNode with custom toString', function () {
Expand Down

0 comments on commit 79993ce

Please sign in to comment.