From 9eda1ac33cd56fdf5ad2e6b43c6b93e86e4fc194 Mon Sep 17 00:00:00 2001 From: Diego Mijelshon Date: Thu, 10 Dec 2020 13:32:52 -0300 Subject: [PATCH] Fix parsing of nested function with multiple parameters --- Tests/FunctionTests.cs | 14 ++++++++++++++ dotMath/EquationCompiler.cs | 3 +++ 2 files changed, 17 insertions(+) diff --git a/Tests/FunctionTests.cs b/Tests/FunctionTests.cs index e7ebd58..2d5567b 100644 --- a/Tests/FunctionTests.cs +++ b/Tests/FunctionTests.cs @@ -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() { @@ -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() { diff --git a/dotMath/EquationCompiler.cs b/dotMath/EquationCompiler.cs index 3d0897e..810b546 100644 --- a/dotMath/EquationCompiler.cs +++ b/dotMath/EquationCompiler.cs @@ -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());