Skip to content

Commit

Permalink
Fix parsing of nested function with multiple parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
diegose committed Dec 10, 2020
1 parent d6effa6 commit 9eda1ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Tests/FunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ public void NestedFunctions(double a)
Assert.AreEqual(Math.Sin(Math.Cos(Math.Tan(a))), compiler.Calculate());
}

[Test]
public void NestedFunctionsWithMultipleParameters()
{
var compiler = new EquationCompiler("max(1,min(2,3))");
Assert.AreEqual(2, compiler.Calculate());
}

[Test]
public void RangeTest()
{
Expand Down Expand Up @@ -288,6 +295,13 @@ public void IfWithEquation(string condition, bool result, double a, double b, do
Assert.AreEqual((result ? a : b + c), compiler.Calculate());
}

[Test]
public void NestedIf()
{
var compiler = new EquationCompiler("if(1, if(1, 2, 3), 4)");
Assert.AreEqual(2, compiler.Calculate());
}

[Test]
public void MultipleFunctionsPerObject()
{
Expand Down
3 changes: 3 additions & 0 deletions dotMath/EquationCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ private CValue Paren()
isFunction = true;

value = function.SetParameters(parameters);

if (string.Equals(_currentToken, ")") && parameters.Count > 1)
NextToken();
}
else
value = GetVariableByName(_currentToken.ToString());
Expand Down

0 comments on commit 9eda1ac

Please sign in to comment.