private double test_function(Node n) { double fitness = 0; foreach (var value in _values) { variableSetVisitor.SetVariable(n, "A", value[0]); variableSetVisitor.SetVariable(n, "B", value[1]); evalVisitor.VisitNode(n); fitness -= Math.Abs(value[2] - evalVisitor.Result); } return(fitness); }
public void test_evaluation_with_var(string text, double expectedResult) { Node n = new Analyser().Analyse(new StringTokenizer(text)); VariableSetVisitor setVisitor = new VariableSetVisitor(); setVisitor.SetVariable(n, "a", 3.0); EvalVisitor visitor = new EvalVisitor(); visitor.VisitNode(n); double result = visitor.Result; Assert.That(result, Is.EqualTo(expectedResult)); }