src/GenFx.Tests/CrossoverOperatorTest.cs
/// <summary>
/// Tests that the crossover works correctly when the crossover rate is not hit.
/// </summary>
Tests that the crossover works correctly when the crossover rate is not hit.
Tests that the crossover works correctly when the crossover rate is not hit .
[Fact]
        public void CrossoverOperator_Crossover_NoOp()
        {
            double crossoverRate = 0; 
            MockGeneticAlgorithm algorithm = GetGeneticAlgorithm(crossoverRate);
            FakeCrossoverOperator op = (FakeCrossoverOperator)algorithm.CrossoverOperator;
            op.Initialize(algorithm);
            MockEntity entity1 = new MockEntity();
            entity1.Initialize(algorithm);
            entity1.Identifier = "1";
            MockEntity entity2 = new MockEntity();
            entity2.Initialize(algorithm);
            entity2.Identifier = "3";
            IList<GeneticEntity> geneticEntities = op.Crossover(new GeneticEntity[] { entity1, entity2 }).ToList();
            Assert.Same(entity1, geneticEntities[0]);
            Assert.Same(entity2, geneticEntities[1]);
        }
[ Fact ] public void CrossoverOperator_Crossover_NoOp ( ) { double crossoverRate = 0 ; MockGeneticAlgorithm algorithm = GetGeneticAlgorithm ( crossoverRate ) ; FakeCrossoverOperator op = ( FakeCrossoverOperator ) algorithm . CrossoverOperator ; op . Initialize ( algorithm ) ; MockEntity entity1 = new MockEntity ( ) ; entity1 . Initialize ( algorithm ) ; entity1 . Identifier = " " ; MockEntity entity2 = new MockEntity ( ) ; entity2 . Initialize ( algorithm ) ; entity2 . Identifier = " " ; IList < GeneticEntity > geneticEntities = op . Crossover ( new GeneticEntity [ ] { entity1 , entity2 } ) . ToList ( ) ; Assert . Same ( entity1 , geneticEntities [ 0 ] ) ; Assert . Same ( entity2 , geneticEntities [ 1 ] ) ; }
Tests that the crossover works correctly when the crossover rate is not hit.
Tests that the crossover works correctly when the crossover rate is not hit .
// force crossover not to occur