Beispiel #1
0
        public void Entity_CopyTo()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                PopulationSeed    = new MockPopulation(),
                SelectionOperator = new MockSelectionOperator(),
                FitnessEvaluator  = new MockFitnessEvaluator(),
                GeneticEntitySeed = new MockEntity()
            };
            MockEntity entity = new MockEntity();

            entity.Initialize(algorithm);
            entity.Age = 10;
            entity.ScaledFitnessValue = 10;
            PrivateObject accessor = new PrivateObject(entity, new PrivateType(typeof(GeneticEntity)));

            accessor.SetField("rawFitnessValue", 123);

            MockEntity newEntity = new MockEntity();

            newEntity.Initialize(algorithm);
            entity.CopyTo(newEntity);

            Assert.Equal(entity.Age, newEntity.Age);
            Assert.Equal(entity.RawFitnessValue, newEntity.RawFitnessValue);
            Assert.Equal(entity.ScaledFitnessValue, newEntity.ScaledFitnessValue);
        }