src/GenFx.Components.Tests/BestMaximumFitnessTest.cs
/// <summary>
/// Tests that the correct value is returned from <see cref="BestMaximumFitness.GetResultValue"/>.
/// </summary>
Tests that the correct value is returned from .
Tests that the correct value is returned from .
[Fact]
        public void BestMaximumFitness_GetResultValue()
        {
            MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm();
            MaximumFitness maximumFitness = new MaximumFitness();
            algorithm.Metrics.Add(maximumFitness);
            ObservableCollection<MetricResult> population1Results = maximumFitness.GetResults(0);
            population1Results.Add(new MetricResult(0, 0, (double)5, maximumFitness));
            BestMaximumFitness target = new BestMaximumFitness();
            target.Initialize(algorithm);
            MockPopulation population = new MockPopulation
            {
                Index = 0
            };
            object result = target.GetResultValue(population);
            Assert.Equal((double)5, result);
            population1Results.Add(new MetricResult(1, 0, (double)6, maximumFitness));
            result = target.GetResultValue(population);
            Assert.Equal((double)6, result);
            ObservableCollection<MetricResult> population2Results = maximumFitness.GetResults(1);
            population2Results.Add(new MetricResult(0, 2, (double)10, maximumFitness));
            MockPopulation population2 = new MockPopulation
            {
                Index = 1
            };
            result = target.GetResultValue(population2);
            Assert.Equal((double)10, result);
            population2Results.Add(new MetricResult(1, 1, (double)4, maximumFitness));
            result = target.GetResultValue(population2);
            Assert.Equal((double)10, result);
        }
[ Fact ] public void BestMaximumFitness_GetResultValue ( ) { MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm ( ) ; MaximumFitness maximumFitness = new MaximumFitness ( ) ; algorithm . Metrics . Add ( maximumFitness ) ; ObservableCollection < MetricResult > population1Results = maximumFitness . GetResults ( 0 ) ; population1Results . Add ( new MetricResult ( 0 , 0 , ( double ) 5 , maximumFitness ) ) ; BestMaximumFitness target = new BestMaximumFitness ( ) ; target . Initialize ( algorithm ) ; MockPopulation population = new MockPopulation { Index = 0 } ; object result = target . GetResultValue ( population ) ; Assert . Equal ( ( double ) 5 , result ) ; population1Results . Add ( new MetricResult ( 1 , 0 , ( double ) 6 , maximumFitness ) ) ; result = target . GetResultValue ( population ) ; Assert . Equal ( ( double ) 6 , result ) ; ObservableCollection < MetricResult > population2Results = maximumFitness . GetResults ( 1 ) ; population2Results . Add ( new MetricResult ( 0 , 2 , ( double ) 10 , maximumFitness ) ) ; MockPopulation population2 = new MockPopulation { Index = 1 } ; result = target . GetResultValue ( population2 ) ; Assert . Equal ( ( double ) 10 , result ) ; population2Results . Add ( new MetricResult ( 1 , 1 , ( double ) 4 , maximumFitness ) ) ; result = target . GetResultValue ( population2 ) ; Assert . Equal ( ( double ) 10 , result ) ; }
Tests that the correct value is returned from .
Tests that the correct value is returned from .