src/GenFx.Tests/GeneticAlgorithmTest.cs
/// <summary>
/// Tests that the <see cref="GeneticAlgorithm"/> can be serialized and deserialized.
/// </summary>
Tests that the  can be serialized and deserialized.
Tests that the can be serialized and deserialized .
[Fact]
        public void GeneticAlgorithm_Serialization()
        {
            MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                CrossoverOperator = new MockCrossoverOperator(),
                ElitismStrategy = new MockElitismStrategy(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                FitnessScalingStrategy = new MockFitnessScalingStrategy(),
                GeneticEntitySeed = new MockEntity(),
                MinimumEnvironmentSize = 10,
                MutationOperator = new MockMutationOperator(),
                PopulationSeed = new MockPopulation(),
                SelectionOperator = new MockSelectionOperator(),
                Terminator = new MockTerminator()
            };
            algorithm.Metrics.Add(new MockMetric());
            algorithm.Metrics.Add(new MockMetric2());
            algorithm.Plugins.Add(new MockPlugin());
            algorithm.Plugins.Add(new MockPlugin2());
            MockGeneticAlgorithm result = (MockGeneticAlgorithm)SerializationHelper.TestSerialization(
                algorithm, algorithm.GetAllComponents().Select(c => c.GetType()));
            Assert.Equal(10, result.MinimumEnvironmentSize);
            Assert.IsType<MockCrossoverOperator>(result.CrossoverOperator);
            Assert.IsType<MockElitismStrategy>(result.ElitismStrategy);
            Assert.IsType<MockFitnessEvaluator>(result.FitnessEvaluator);
            Assert.IsType<MockFitnessScalingStrategy>(result.FitnessScalingStrategy);
            Assert.IsType<MockEntity>(result.GeneticEntitySeed);
            Assert.IsType<MockMutationOperator>(result.MutationOperator);
            Assert.IsType<MockPopulation>(result.PopulationSeed);
            Assert.IsType<MockSelectionOperator>(result.SelectionOperator);
            Assert.IsType<MockTerminator>(result.Terminator);
            Assert.IsType<MockMetric>(result.Metrics[0]);
            Assert.IsType<MockMetric2>(result.Metrics[1]);
            Assert.IsType<MockPlugin>(result.Plugins[0]);
            Assert.IsType<MockPlugin2>(result.Plugins[1]);
        }
[ Fact ] public void GeneticAlgorithm_Serialization ( ) { MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm { CrossoverOperator = new MockCrossoverOperator ( ) , ElitismStrategy = new MockElitismStrategy ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , FitnessScalingStrategy = new MockFitnessScalingStrategy ( ) , GeneticEntitySeed = new MockEntity ( ) , MinimumEnvironmentSize = 10 , MutationOperator = new MockMutationOperator ( ) , PopulationSeed = new MockPopulation ( ) , SelectionOperator = new MockSelectionOperator ( ) , Terminator = new MockTerminator ( ) } ; algorithm . Metrics . Add ( new MockMetric ( ) ) ; algorithm . Metrics . Add ( new MockMetric2 ( ) ) ; algorithm . Plugins . Add ( new MockPlugin ( ) ) ; algorithm . Plugins . Add ( new MockPlugin2 ( ) ) ; MockGeneticAlgorithm result = ( MockGeneticAlgorithm ) SerializationHelper . TestSerialization ( algorithm , algorithm . GetAllComponents ( ) . Select ( c => c . GetType ( ) ) ) ; Assert . Equal ( 10 , result . MinimumEnvironmentSize ) ; Assert . IsType < MockCrossoverOperator > ( result . CrossoverOperator ) ; Assert . IsType < MockElitismStrategy > ( result . ElitismStrategy ) ; Assert . IsType < MockFitnessEvaluator > ( result . FitnessEvaluator ) ; Assert . IsType < MockFitnessScalingStrategy > ( result . FitnessScalingStrategy ) ; Assert . IsType < MockEntity > ( result . GeneticEntitySeed ) ; Assert . IsType < MockMutationOperator > ( result . MutationOperator ) ; Assert . IsType < MockPopulation > ( result . PopulationSeed ) ; Assert . IsType < MockSelectionOperator > ( result . SelectionOperator ) ; Assert . IsType < MockTerminator > ( result . Terminator ) ; Assert . IsType < MockMetric > ( result . Metrics [ 0 ] ) ; Assert . IsType < MockMetric2 > ( result . Metrics [ 1 ] ) ; Assert . IsType < MockPlugin > ( result . Plugins [ 0 ] ) ; Assert . IsType < MockPlugin2 > ( result . Plugins [ 1 ] ) ; }
Tests that the  can be serialized and deserialized.
Tests that the can be serialized and deserialized .