コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }