public void IntExpressionParser_Parse_ValidInputFunctionsTest( string input, string[] variableNames, int[] parameters, int expectedValue) { var factory = new IntExpressionParserFactory(); //Add some non standard functions which will be tested var functions = new[] { new Function <int>("sum", (param) => { return((args) => param[0](args) + param[1](args)); }), new Function <int>("diff", (param) => { return((args) => param[0](args) - param[1](args)); }), new Function <int>("mult", (param) => { return((args) => param[0](args) * param[1](args)); }), new Function <int>("div", (param) => { return((args) => param[0](args) / param[1](args)); }), }; factory.Functions = functions; var expressionParser = factory.Create(variableNames); var handler = expressionParser.Parse(input); int value = handler(parameters); Assert.That(value, Is.EqualTo(expectedValue)); }
public void RuleParser_ParseParamCondition_ValidInputTest(string input, string[] variableNames, int[] variableValues, bool expectedOutput) { var expressionParserFactory = new IntExpressionParserFactory(); var parser = new RuleParser <int>(new ModuleParser <int>(expressionParserFactory), expressionParserFactory); var intParser = expressionParserFactory.Create(variableNames); var handler = parser.ParseParamCondition(input, intParser); var output = handler(variableValues); Assert.That(output, Is.EqualTo(expectedOutput)); }