Esempio n. 1
0
        public void MeanTreeSize_GetResultValue_NullPopulation()
        {
            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);
            Assert.Throws <ArgumentNullException>(() => target.GetResultValue(null));
        }
Esempio n. 2
0
        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));
        }