src/GenFx.Components.Tests/MeanTreeSizeTest.cs
/// <summary>
/// Tests that the GetResultValue method works correctly.
/// </summary>
Tests that the GetResultValue method works correctly.
Tests that the GetResultValue method works correctly .
[Fact]
        public void MeanTreeSize_GetResultValue()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                SelectionOperator = new MockSelectionOperator(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                GeneticEntitySeed = new TestTreeEntity(),
                PopulationSeed = new SimplePopulation(),
            };
            algorithm.Metrics.Add(new MeanTreeSize());
            MeanTreeSize target = new MeanTreeSize();
            target.Initialize(algorithm);
            SimplePopulation population = new SimplePopulation();
            population.Initialize(algorithm);
            TreeEntityBase entity = new TestTreeEntity();
            entity.Initialize(algorithm);
            entity.SetRootNode(new TreeNode());
            entity.RootNode.ChildNodes.Add(new TreeNode());
            entity.RootNode.ChildNodes.Add(new TreeNode());
            entity.RootNode.ChildNodes[0].ChildNodes.Add(new TreeNode());
            population.Entities.Add(entity);
            entity = new TestTreeEntity();
            entity.Initialize(algorithm);
            entity.SetRootNode(new TreeNode());
            population.Entities.Add(entity);
            entity = new TestTreeEntity();
            entity.Initialize(algorithm);
            entity.SetRootNode(new TreeNode());
            entity.RootNode.ChildNodes.Add(new TreeNode());
            population.Entities.Add(entity);
            object result = target.GetResultValue(population);
            Assert.Equal(2.33, Math.Round((double)result, 2));
        }
[ Fact ] public void MeanTreeSize_GetResultValue ( ) { GeneticAlgorithm algorithm = new MockGeneticAlgorithm { SelectionOperator = new MockSelectionOperator ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , GeneticEntitySeed = new TestTreeEntity ( ) , PopulationSeed = new SimplePopulation ( ) , } ; algorithm . Metrics . Add ( new MeanTreeSize ( ) ) ; MeanTreeSize target = new MeanTreeSize ( ) ; target . Initialize ( algorithm ) ; SimplePopulation population = new SimplePopulation ( ) ; population . Initialize ( algorithm ) ; TreeEntityBase entity = new TestTreeEntity ( ) ; entity . Initialize ( algorithm ) ; entity . SetRootNode ( new TreeNode ( ) ) ; entity . RootNode . ChildNodes . Add ( new TreeNode ( ) ) ; entity . RootNode . ChildNodes . Add ( new TreeNode ( ) ) ; entity . RootNode . ChildNodes [ 0 ] . ChildNodes . Add ( new TreeNode ( ) ) ; population . Entities . Add ( entity ) ; entity = new TestTreeEntity ( ) ; entity . Initialize ( algorithm ) ; entity . SetRootNode ( new TreeNode ( ) ) ; population . Entities . Add ( entity ) ; entity = new TestTreeEntity ( ) ; entity . Initialize ( algorithm ) ; entity . SetRootNode ( new TreeNode ( ) ) ; entity . RootNode . ChildNodes . Add ( new TreeNode ( ) ) ; population . Entities . Add ( entity ) ; object result = target . GetResultValue ( population ) ; Assert . Equal ( 2.33 , Math . Round ( ( double ) result , 2 ) ) ; }
Tests that the GetResultValue method works correctly.
Tests that the GetResultValue method works correctly .