src/GenFx.Components.Tests/MetricLoggerTest.cs
/// <summary>
/// Tests that the <see cref="MetricLogger.OnFitnessEvaluated"/> method works correctly.
/// </summary>
Tests that the  method works correctly.
Tests that the method works correctly .
[Fact]
        public void MetricLogger_FitnessEvaluated()
        {
            MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm();
            algorithm.Metrics.Add(new TestMetric1());
            algorithm.Metrics.Add(new TestMetric2());
            algorithm.Metrics.Add(new TestMetric3());
            MetricLogger logger = new MetricLogger
            {
                TraceCategory = "test"
            };
            logger.Initialize(algorithm);
            Assert.Equal(String.Empty, this.traceListener.Output.ToString());
            GeneticEnvironment environment = new GeneticEnvironment(algorithm);
            environment.Populations.Add(new MockPopulation { Index = 0 });
            environment.Populations.Add(new MockPopulation { Index = 1 });
            PrivateObject accessor = new PrivateObject(logger);
            accessor.Invoke("OnFitnessEvaluated", environment, 0);
            string[] lines = this.traceListener.Output.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            Assert.Equal(24, lines.Length);
            this.VerifyMetricOutput(lines.Take(4).ToArray(), logger.TraceCategory, "Metric 1", "1:0", 0, 0);
            this.VerifyMetricOutput(lines.Skip(4).Take(4).ToArray(), logger.TraceCategory, "Metric 2", "2:0", 0, 0);
            this.VerifyMetricOutput(lines.Skip(8).Take(4).ToArray(), logger.TraceCategory, typeof(TestMetric3).FullName, "3:0", 0, 0);
            this.VerifyMetricOutput(lines.Skip(12).Take(4).ToArray(), logger.TraceCategory, "Metric 1", "1:1", 1, 0);
            this.VerifyMetricOutput(lines.Skip(16).Take(4).ToArray(), logger.TraceCategory, "Metric 2", "2:1", 1, 0);
            this.VerifyMetricOutput(lines.Skip(20).Take(4).ToArray(), logger.TraceCategory, typeof(TestMetric3).FullName, "3:1", 1, 0);
        }
[ Fact ] public void MetricLogger_FitnessEvaluated ( ) { MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm ( ) ; algorithm . Metrics . Add ( new TestMetric1 ( ) ) ; algorithm . Metrics . Add ( new TestMetric2 ( ) ) ; algorithm . Metrics . Add ( new TestMetric3 ( ) ) ; MetricLogger logger = new MetricLogger { TraceCategory = " " } ; logger . Initialize ( algorithm ) ; Assert . Equal ( String . Empty , this . traceListener . Output . ToString ( ) ) ; GeneticEnvironment environment = new GeneticEnvironment ( algorithm ) ; environment . Populations . Add ( new MockPopulation { Index = 0 } ) ; environment . Populations . Add ( new MockPopulation { Index = 1 } ) ; PrivateObject accessor = new PrivateObject ( logger ) ; accessor . Invoke ( " " , environment , 0 ) ; string [ ] lines = this . traceListener . Output . ToString ( ) . Split ( new string [ ] { Environment . NewLine } , StringSplitOptions . RemoveEmptyEntries ) ; Assert . Equal ( 24 , lines . Length ) ; this . VerifyMetricOutput ( lines . Take ( 4 ) . ToArray ( ) , logger . TraceCategory , " " , " " , 0 , 0 ) ; this . VerifyMetricOutput ( lines . Skip ( 4 ) . Take ( 4 ) . ToArray ( ) , logger . TraceCategory , " " , " " , 0 , 0 ) ; this . VerifyMetricOutput ( lines . Skip ( 8 ) . Take ( 4 ) . ToArray ( ) , logger . TraceCategory , typeof ( TestMetric3 ) . FullName , " " , 0 , 0 ) ; this . VerifyMetricOutput ( lines . Skip ( 12 ) . Take ( 4 ) . ToArray ( ) , logger . TraceCategory , " " , " " , 1 , 0 ) ; this . VerifyMetricOutput ( lines . Skip ( 16 ) . Take ( 4 ) . ToArray ( ) , logger . TraceCategory , " " , " " , 1 , 0 ) ; this . VerifyMetricOutput ( lines . Skip ( 20 ) . Take ( 4 ) . ToArray ( ) , logger . TraceCategory , typeof ( TestMetric3 ) . FullName , " " , 1 , 0 ) ; }
Tests that the  method works correctly.
Tests that the method works correctly .