You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
if the input is a static value then the extension function works correctly
[Test]
public async Task EvaluateCustomMathFunction_PositiveNumber()
{
// Arrange
var exp = new Expression("Pos(-5)");
// Act
var result = await CustomExpressionEvaluation.EvaluateCustomMathFunction(exp);
// Assert
Assert.That(result, Is.EqualTo(0)); // The method should return 0 for negative input
}
what am i missing in my implementation of the extension method?
i have also opened a discussion for it on #22
The text was updated successfully, but these errors were encountered:
I never used EvaluateOptions.IterateParameters, and it looks to me that IterateParameters implementation is broken.
But I think it's easy to work around this limitation:
privatestaticasync Task NCalcExtensionFunctions(stringname,FunctionArgsargs){if(name=="Pos"){vartemp=await args.Parameters[0].EvaluateAsync();
args.Result = Convert.ToDouble(temp)>0?temp:0;}}publicstaticasyncTask<object[]>EvaluateArray(stringexpression,Dictionary<string,object>parameters){varexpr=new Expression(expression, EvaluateOptions.None);
expr.EvaluateFunctionAsync +=NCalcExtensionFunctions;// convert array parameters to scalar parametersvarcount= parameters.Values.OfType<Array>().Min(p => p.Length);varresults=newList<object>();for(vari=0;i<count;i++){// get parametersforeach(var pair in parameters){
expr.Parameters[pair.Key]=((Array)pair.Value).GetValue(i);}// save results
results.Add(await expr.EvaluateAsync());}return results.ToArray();}
i have implemented a extension function in ncalc-async like so
the line
always returns zero in case of parameterized input
following is a test case with parameterized input
if the input is a static value then the extension function works correctly
what am i missing in my implementation of the extension method?
i have also opened a discussion for it on #22
The text was updated successfully, but these errors were encountered: