src/GenFx.Tests/ElitismStrategyTest.cs
/// <summary>
/// Tests that ApplyElitism works correctly.
/// </summary>
Tests that ApplyElitism works correctly.
Tests that ApplyElitism works correctly .
[Fact]
        public async Task ElitismStrategy_GetElitistGeneticEntities()
        {
            double elitismRatio = .1;
            int totalGeneticEntities = 100;
            GeneticAlgorithm algorithm = GetGeneticAlgorithm(elitismRatio);
            await algorithm.InitializeAsync();
            MockPopulation population = new MockPopulation();
            population.Initialize(algorithm);
            for (int i = 0; i < totalGeneticEntities; i++)
            {
                MockEntity entity = new MockEntity();
                entity.Initialize(algorithm);
                population.Entities.Add(entity);
            }
            algorithm.Environment.Populations.Add(population);
            MockElitismStrategy strategy = (MockElitismStrategy)algorithm.ElitismStrategy;
            strategy.Initialize(algorithm);
            IList<GeneticEntity> geneticEntities = strategy.GetEliteEntities(population);
            Assert.Equal(Convert.ToInt32(Math.Round(elitismRatio * totalGeneticEntities)), geneticEntities.Count);
        }
[ Fact ] public async Task ElitismStrategy_GetElitistGeneticEntities ( ) { double elitismRatio = .1 ; int totalGeneticEntities = 100 ; GeneticAlgorithm algorithm = GetGeneticAlgorithm ( elitismRatio ) ; await algorithm . InitializeAsync ( ) ; MockPopulation population = new MockPopulation ( ) ; population . Initialize ( algorithm ) ; for ( int i = 0 ; i < totalGeneticEntities ; i ++ ) { MockEntity entity = new MockEntity ( ) ; entity . Initialize ( algorithm ) ; population . Entities . Add ( entity ) ; } algorithm . Environment . Populations . Add ( population ) ; MockElitismStrategy strategy = ( MockElitismStrategy ) algorithm . ElitismStrategy ; strategy . Initialize ( algorithm ) ; IList < GeneticEntity > geneticEntities = strategy . GetEliteEntities ( population ) ; Assert . Equal ( Convert . ToInt32 ( Math . Round ( elitismRatio * totalGeneticEntities ) ) , geneticEntities . Count ) ; }
Tests that ApplyElitism works correctly.
Tests that ApplyElitism works correctly .