src/GenFx.Tests/MetricTest.cs
/// <summary>
/// Tests that the Calculate method works correctly.
/// </summary>
Tests that the Calculate method works correctly.
Tests that the Calculate method works correctly .
[Fact]
        public async Task Metric_Calculate()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                MinimumEnvironmentSize = 2,
                GeneticEntitySeed = new MockEntity(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                SelectionOperator = new MockSelectionOperator(),
                PopulationSeed = new MockPopulation()
            };
            algorithm.Metrics.Add(new FakeMetric());
            await algorithm.InitializeAsync();
            FakeMetric metric = (FakeMetric)algorithm.Metrics[0];
            metric.Calculate(algorithm.Environment, 1);
            Assert.Equal(4, metric.GetResultValueCallCount);
            ObservableCollection<MetricResult> results = metric.GetResults(0);
            Assert.Equal(2, results.Count);
            Assert.Equal(0, results[0].GenerationIndex);
            Assert.Equal(0, results[0].PopulationIndex);
            Assert.Equal(1, results[0].ResultValue);
            Assert.Same(metric, results[0].Metric);
            results = metric.GetResults(1);
            Assert.Equal(0, results[0].GenerationIndex);
            Assert.Equal(1, results[0].PopulationIndex);
            Assert.Equal(2, results[0].ResultValue);
            Assert.Same(metric, results[0].Metric);
        }
[ Fact ] public async Task Metric_Calculate ( ) { GeneticAlgorithm algorithm = new MockGeneticAlgorithm { MinimumEnvironmentSize = 2 , GeneticEntitySeed = new MockEntity ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , SelectionOperator = new MockSelectionOperator ( ) , PopulationSeed = new MockPopulation ( ) } ; algorithm . Metrics . Add ( new FakeMetric ( ) ) ; await algorithm . InitializeAsync ( ) ; FakeMetric metric = ( FakeMetric ) algorithm . Metrics [ 0 ] ; metric . Calculate ( algorithm . Environment , 1 ) ; Assert . Equal ( 4 , metric . GetResultValueCallCount ) ; ObservableCollection < MetricResult > results = metric . GetResults ( 0 ) ; Assert . Equal ( 2 , results . Count ) ; Assert . Equal ( 0 , results [ 0 ] . GenerationIndex ) ; Assert . Equal ( 0 , results [ 0 ] . PopulationIndex ) ; Assert . Equal ( 1 , results [ 0 ] . ResultValue ) ; Assert . Same ( metric , results [ 0 ] . Metric ) ; results = metric . GetResults ( 1 ) ; Assert . Equal ( 0 , results [ 0 ] . GenerationIndex ) ; Assert . Equal ( 1 , results [ 0 ] . PopulationIndex ) ; Assert . Equal ( 2 , results [ 0 ] . ResultValue ) ; Assert . Same ( metric , results [ 0 ] . Metric ) ; }
Tests that the Calculate method works correctly.
Tests that the Calculate method works correctly .