src/GenFx.Components.Tests/MultiDemeGeneticAlgorithmTest.cs
/// <summary>
/// Tests that the CreateNextGeneration method works correctly.
/// </summary>
Tests that the CreateNextGeneration method works correctly.
Tests that the CreateNextGeneration method works correctly .
[Fact]
        public async Task MultiDemeGeneticAlgorithm_CreateNextGeneration_Async()
        {
            TestMultiDemeGeneticAlgorithm algorithm = new TestMultiDemeGeneticAlgorithm
            {
                FitnessEvaluator = new MockFitnessEvaluator(),
                GeneticEntitySeed = new MockEntity(),
                PopulationSeed = new SimplePopulation
                {
                    MinimumPopulationSize = 3
                },
                MigrantCount = 1,
                SelectionOperator = new MockSelectionOperator
                {
                    SelectionBasedOnFitnessType = FitnessType.Raw
                }
            };
            MockSelectionOperator selectionOp = new MockSelectionOperator();
            algorithm.SelectionOperator = selectionOp;
            await algorithm.InitializeAsync();
            PrivateObject accessor = new PrivateObject(algorithm);
            algorithm.Environment.Populations.Add(GetPopulation(algorithm));
            algorithm.Environment.Populations.Add(GetPopulation(algorithm));
            SimplePopulation population = GetPopulation(algorithm);
            algorithm.Environment.Populations.Add(population);
            int prevPopCount = population.Entities.Count;
            await (Task)accessor.Invoke("CreateNextGenerationAsync", population);
            Assert.Equal(1, selectionOp.DoSelectCallCount);
            Assert.Equal(prevPopCount, population.Entities.Count);
        }
[ Fact ] public async Task MultiDemeGeneticAlgorithm_CreateNextGeneration_Async ( ) { TestMultiDemeGeneticAlgorithm algorithm = new TestMultiDemeGeneticAlgorithm { FitnessEvaluator = new MockFitnessEvaluator ( ) , GeneticEntitySeed = new MockEntity ( ) , PopulationSeed = new SimplePopulation { MinimumPopulationSize = 3 } , MigrantCount = 1 , SelectionOperator = new MockSelectionOperator { SelectionBasedOnFitnessType = FitnessType . Raw } } ; MockSelectionOperator selectionOp = new MockSelectionOperator ( ) ; algorithm . SelectionOperator = selectionOp ; await algorithm . InitializeAsync ( ) ; PrivateObject accessor = new PrivateObject ( algorithm ) ; algorithm . Environment . Populations . Add ( GetPopulation ( algorithm ) ) ; algorithm . Environment . Populations . Add ( GetPopulation ( algorithm ) ) ; SimplePopulation population = GetPopulation ( algorithm ) ; algorithm . Environment . Populations . Add ( population ) ; int prevPopCount = population . Entities . Count ; await ( Task ) accessor . Invoke ( " " , population ) ; Assert . Equal ( 1 , selectionOp . DoSelectCallCount ) ; Assert . Equal ( prevPopCount , population . Entities . Count ) ; }
Tests that the CreateNextGeneration method works correctly.
Tests that the CreateNextGeneration method works correctly .