src/GenFx.Tests/GeneticAlgorithmTest.cs
/// <summary>
/// Tests that the ApplyCrossover method works correctly.
/// </summary>
Tests that the ApplyCrossover method works correctly.
Tests that the ApplyCrossover method works correctly .
[Fact]
        public void GeneticAlgorithm_ApplyCrossover()
        {
            GeneticAlgorithm algorithm = new TestGeneticAlgorithm
            {
                PopulationSeed = new MockPopulation(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                SelectionOperator = new MockSelectionOperator(),
                GeneticEntitySeed = new MockEntity(),
                CrossoverOperator = new MockCrossoverOperator
                {
                    CrossoverRate = 1
                }
            };
            MockCrossoverOperator crossoverOp = (MockCrossoverOperator)algorithm.CrossoverOperator;
            crossoverOp.Initialize(algorithm);
            algorithm.CrossoverOperator = crossoverOp;
            PrivateObject algAccessor = new PrivateObject(algorithm);
            MockEntity entity1 = new MockEntity();
            entity1.Initialize(algorithm);
            MockEntity entity2 = new MockEntity();
            entity2.Initialize(algorithm);
            IList<GeneticEntity> geneticEntities = (IList<GeneticEntity>)algAccessor.Invoke("ApplyCrossover", algorithm.PopulationSeed, new GeneticEntity[] { entity1, entity2 });
            Assert.Equal(2, geneticEntities.Count);
            Assert.Equal(1, crossoverOp.DoCrossoverCallCount);
        }
[ Fact ] public void GeneticAlgorithm_ApplyCrossover ( ) { GeneticAlgorithm algorithm = new TestGeneticAlgorithm { PopulationSeed = new MockPopulation ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , SelectionOperator = new MockSelectionOperator ( ) , GeneticEntitySeed = new MockEntity ( ) , CrossoverOperator = new MockCrossoverOperator { CrossoverRate = 1 } } ; MockCrossoverOperator crossoverOp = ( MockCrossoverOperator ) algorithm . CrossoverOperator ; crossoverOp . Initialize ( algorithm ) ; algorithm . CrossoverOperator = crossoverOp ; PrivateObject algAccessor = new PrivateObject ( algorithm ) ; MockEntity entity1 = new MockEntity ( ) ; entity1 . Initialize ( algorithm ) ; MockEntity entity2 = new MockEntity ( ) ; entity2 . Initialize ( algorithm ) ; IList < GeneticEntity > geneticEntities = ( IList < GeneticEntity > ) algAccessor . Invoke ( " " , algorithm . PopulationSeed , new GeneticEntity [ ] { entity1 , entity2 } ) ; Assert . Equal ( 2 , geneticEntities . Count ) ; Assert . Equal ( 1 , crossoverOp . DoCrossoverCallCount ) ; }
Tests that the ApplyCrossover method works correctly.
Tests that the ApplyCrossover method works correctly .