src/GenFx.Components.Tests/MultiPointCrossoverOperatorTest.cs
/// <summary>
/// Tests that the <see cref="MultiPointCrossoverOperator.GenerateCrossover"/> method
/// works correctly when crossing entities with the same lengths over three points.
/// </summary>
Tests that the  method
works correctly when crossing entities with the same lengths over three points.
Tests that the method works correctly when crossing entities with the same lengths over three points .
[Fact]
        public void MultiPointCrossoverOperator_GenerateCrossover_ThreePointsSameLength()
        {
            MultiPointCrossoverOperator op = new MultiPointCrossoverOperator
            {
                CrossoverPointCount = 3,
                CrossoverRate = 1
            };
            MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                GeneticEntitySeed = new TestEntity()
            };
            op.Initialize(algorithm);
            TestEntity entity1 = new TestEntity();
            entity1.InnerList.AddRange(new object[] { 0, 1, 2, 3, 4 });
            TestEntity entity2 = new TestEntity();
            entity2.InnerList.AddRange(new object[] { 4, 2, 1, 0, 0 });
            List<GeneticEntity> parents = new List<GeneticEntity>
            {
                entity1,
                entity2
            };
            RandomNumberService.Instance = new FakeRandomNumberService(5,
                new Queue<int>(new int[] { 0, 3, 4 }));
            PrivateObject accessor = new PrivateObject(op);
            IEnumerable<GeneticEntity> result = (IEnumerable<GeneticEntity>)accessor.Invoke(
                "GenerateCrossover", parents);
            Assert.Equal(2, result.Count());
            TestEntity resultEntity1 = (TestEntity)result.ElementAt(0);
            TestEntity resultEntity2 = (TestEntity)result.ElementAt(1);
            Assert.Equal(new int[] { 4, 2, 1, 3, 0 }, (IEnumerable)resultEntity1);
            Assert.Equal(new int[] { 0, 1, 2, 0, 4 }, (IEnumerable)resultEntity2);
        }
[ Fact ] public void MultiPointCrossoverOperator_GenerateCrossover_ThreePointsSameLength ( ) { MultiPointCrossoverOperator op = new MultiPointCrossoverOperator { CrossoverPointCount = 3 , CrossoverRate = 1 } ; MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm { GeneticEntitySeed = new TestEntity ( ) } ; op . Initialize ( algorithm ) ; TestEntity entity1 = new TestEntity ( ) ; entity1 . InnerList . AddRange ( new object [ ] { 0 , 1 , 2 , 3 , 4 } ) ; TestEntity entity2 = new TestEntity ( ) ; entity2 . InnerList . AddRange ( new object [ ] { 4 , 2 , 1 , 0 , 0 } ) ; List < GeneticEntity > parents = new List < GeneticEntity > { entity1 , entity2 } ; RandomNumberService . Instance = new FakeRandomNumberService ( 5 , new Queue < int > ( new int [ ] { 0 , 3 , 4 } ) ) ; PrivateObject accessor = new PrivateObject ( op ) ; IEnumerable < GeneticEntity > result = ( IEnumerable < GeneticEntity > ) accessor . Invoke ( " " , parents ) ; Assert . Equal ( 2 , result . Count ( ) ) ; TestEntity resultEntity1 = ( TestEntity ) result . ElementAt ( 0 ) ; TestEntity resultEntity2 = ( TestEntity ) result . ElementAt ( 1 ) ; Assert . Equal ( new int [ ] { 4 , 2 , 1 , 3 , 0 } , ( IEnumerable ) resultEntity1 ) ; Assert . Equal ( new int [ ] { 0 , 1 , 2 , 0 , 4 } , ( IEnumerable ) resultEntity2 ) ; }
Tests that the  method
works correctly when crossing entities with the same lengths over three points.
Tests that the method works correctly when crossing entities with the same lengths over three points .