src/GenFx.Components.Tests/SteadyStateGeneticAlgorithmTest.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 SteadyStateGeneticAlgorithm_CreateNextGeneration_FixedCount()
        {
            SteadyStateGeneticAlgorithm algorithm = new SteadyStateGeneticAlgorithm
            {
                GeneticEntitySeed = new MockEntity(),
                PopulationSeed = new SimplePopulation(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                PopulationReplacementValue = new PopulationReplacementValue(2, ReplacementValueKind.FixedCount),
                SelectionOperator = new MockSelectionOperator
                {
                    SelectionBasedOnFitnessType = FitnessType.Scaled
                },
                CrossoverOperator = new MockCrossoverOperator
                {
                    CrossoverRate = 1
                },
                MutationOperator = new MockMutationOperator
                {
                    MutationRate = 1
                }
            };
            algorithm.SelectionOperator = new MockSelectionOperator { SelectionBasedOnFitnessType = FitnessType.Scaled };
            algorithm.SelectionOperator.Initialize(algorithm);
            algorithm.CrossoverOperator = new MockCrossoverOperator { CrossoverRate = 1 };
            algorithm.CrossoverOperator.Initialize(algorithm);
            algorithm.MutationOperator = new MockMutationOperator { MutationRate = 1 };
            algorithm.MutationOperator.Initialize(algorithm);
            algorithm.FitnessEvaluator = new MockFitnessEvaluator();
            algorithm.FitnessEvaluator.Initialize(algorithm);
            await algorithm.InitializeAsync();
            PrivateObject ssAccessor = new PrivateObject(algorithm);
            SimplePopulation population = GetPopulation(algorithm, 3);
            int prevPopCount = population.Entities.Count;
            await (Task)ssAccessor.Invoke("CreateNextGenerationAsync", population);
            Assert.Equal(1, ((MockSelectionOperator)algorithm.SelectionOperator).DoSelectCallCount);
            Assert.Equal(1, ((MockCrossoverOperator)algorithm.CrossoverOperator).DoCrossoverCallCount);
            Assert.Equal(2, ((MockMutationOperator)algorithm.MutationOperator).DoMutateCallCount);
            Assert.Equal(prevPopCount, population.Entities.Count);
        }
[ Fact ] public async Task SteadyStateGeneticAlgorithm_CreateNextGeneration_FixedCount ( ) { SteadyStateGeneticAlgorithm algorithm = new SteadyStateGeneticAlgorithm { GeneticEntitySeed = new MockEntity ( ) , PopulationSeed = new SimplePopulation ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , PopulationReplacementValue = new PopulationReplacementValue ( 2 , ReplacementValueKind . FixedCount ) , SelectionOperator = new MockSelectionOperator { SelectionBasedOnFitnessType = FitnessType . Scaled } , CrossoverOperator = new MockCrossoverOperator { CrossoverRate = 1 } , MutationOperator = new MockMutationOperator { MutationRate = 1 } } ; algorithm . SelectionOperator = new MockSelectionOperator { SelectionBasedOnFitnessType = FitnessType . Scaled } ; algorithm . SelectionOperator . Initialize ( algorithm ) ; algorithm . CrossoverOperator = new MockCrossoverOperator { CrossoverRate = 1 } ; algorithm . CrossoverOperator . Initialize ( algorithm ) ; algorithm . MutationOperator = new MockMutationOperator { MutationRate = 1 } ; algorithm . MutationOperator . Initialize ( algorithm ) ; algorithm . FitnessEvaluator = new MockFitnessEvaluator ( ) ; algorithm . FitnessEvaluator . Initialize ( algorithm ) ; await algorithm . InitializeAsync ( ) ; PrivateObject ssAccessor = new PrivateObject ( algorithm ) ; SimplePopulation population = GetPopulation ( algorithm , 3 ) ; int prevPopCount = population . Entities . Count ; await ( Task ) ssAccessor . Invoke ( " " , population ) ; Assert . Equal ( 1 , ( ( MockSelectionOperator ) algorithm . SelectionOperator ) . DoSelectCallCount ) ; Assert . Equal ( 1 , ( ( MockCrossoverOperator ) algorithm . CrossoverOperator ) . DoCrossoverCallCount ) ; Assert . Equal ( 2 , ( ( MockMutationOperator ) algorithm . MutationOperator ) . DoMutateCallCount ) ; Assert . Equal ( prevPopCount , population . Entities . Count ) ; }
Tests that the CreateNextGeneration method works correctly.
Tests that the CreateNextGeneration method works correctly .