src/GenFx.Components.Tests/InversionOperatorTest.cs
/// <summary>
/// Tests that the Mutate method works correctly.
/// </summary>
Tests that the Mutate method works correctly.
Tests that the Mutate method works correctly .
[Fact]
        public void InversionOperator_Mutate()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                SelectionOperator = new MockSelectionOperator(),
                PopulationSeed = new MockPopulation(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                GeneticEntitySeed = new BinaryStringEntity
                {
                    MinimumStartingLength = 4,
                    MaximumStartingLength = 4
                },
                MutationOperator = new InversionOperator
                {
                    MutationRate = 1
                }
            };
            algorithm.GeneticEntitySeed.Initialize(algorithm);
            InversionOperator op = (InversionOperator)algorithm.MutationOperator;
            op.Initialize(algorithm);
            BinaryStringEntity entity = (BinaryStringEntity)algorithm.GeneticEntitySeed.CreateNewAndInitialize();
            entity.Age = 10;
            entity.Initialize(algorithm);
            entity[0] = true;
            entity[1] = true;
            entity[2] = false;
            entity[3] = true;
            FakeRandomUtil randomUtil = new FakeRandomUtil();
            RandomNumberService.Instance = randomUtil;
            randomUtil.RandomValue = 1;
            GeneticEntity mutant = op.Mutate(entity);
            Assert.Equal("1011", mutant.Representation);
            Assert.Equal(0, mutant.Age);
        }
[ Fact ] public void InversionOperator_Mutate ( ) { GeneticAlgorithm algorithm = new MockGeneticAlgorithm { SelectionOperator = new MockSelectionOperator ( ) , PopulationSeed = new MockPopulation ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , GeneticEntitySeed = new BinaryStringEntity { MinimumStartingLength = 4 , MaximumStartingLength = 4 } , MutationOperator = new InversionOperator { MutationRate = 1 } } ; algorithm . GeneticEntitySeed . Initialize ( algorithm ) ; InversionOperator op = ( InversionOperator ) algorithm . MutationOperator ; op . Initialize ( algorithm ) ; BinaryStringEntity entity = ( BinaryStringEntity ) algorithm . GeneticEntitySeed . CreateNewAndInitialize ( ) ; entity . Age = 10 ; entity . Initialize ( algorithm ) ; entity [ 0 ] = true ; entity [ 1 ] = true ; entity [ 2 ] = false ; entity [ 3 ] = true ; FakeRandomUtil randomUtil = new FakeRandomUtil ( ) ; RandomNumberService . Instance = randomUtil ; randomUtil . RandomValue = 1 ; GeneticEntity mutant = op . Mutate ( entity ) ; Assert . Equal ( " " , mutant . Representation ) ; Assert . Equal ( 0 , mutant . Age ) ; }
Tests that the Mutate method works correctly.
Tests that the Mutate method works correctly .