src/GenFx.Wpf.Tests/MetricsChartTest.cs
/// <summary>
/// Tests that the chart refreshes the series when the fitness is evaluated for the initial generation.
/// </summary>
Tests that the chart refreshes the series when the fitness is evaluated for the initial generation.
Tests that the chart refreshes the series when the fitness is evaluated for the initial generation .
[StaFact]
        public void MetricsChart_RefreshSeriesOnFitnessEvaluated()
        {
            TestPopulation population = new TestPopulation();
            TestAlgorithm algorithm = new TestAlgorithm();
            Metric metric1 = Mock.Of<Metric>();
            List<MetricResult> metric1Results = new List<MetricResult>
            {
                new MetricResult(0, 0, 3, metric1),
                new MetricResult(0, 1, 4, metric1)
            };
            metric1.GetResults(0).AddRange(metric1Results);
            algorithm.Metrics.Add(metric1);
            MetricsChart chart = new MetricsChart
            {
                Algorithm = algorithm,
                Population = population
            };
            Assert.Single(chart.PlotModel.Series);
            chart.PlotModel.Series.Clear();
            PrivateObject algorithmAccessor = new PrivateObject(algorithm, new PrivateType(typeof(GeneticAlgorithm)));
            algorithmAccessor.Invoke("OnFitnessEvaluated",
                new EnvironmentFitnessEvaluatedEventArgs(new GeneticEnvironment(algorithm), 0));
            Assert.Single(chart.PlotModel.Series);
        }
[ StaFact ] public void MetricsChart_RefreshSeriesOnFitnessEvaluated ( ) { TestPopulation population = new TestPopulation ( ) ; TestAlgorithm algorithm = new TestAlgorithm ( ) ; Metric metric1 = Mock . Of < Metric > ( ) ; List < MetricResult > metric1Results = new List < MetricResult > { new MetricResult ( 0 , 0 , 3 , metric1 ) , new MetricResult ( 0 , 1 , 4 , metric1 ) } ; metric1 . GetResults ( 0 ) . AddRange ( metric1Results ) ; algorithm . Metrics . Add ( metric1 ) ; MetricsChart chart = new MetricsChart { Algorithm = algorithm , Population = population } ; Assert . Single ( chart . PlotModel . Series ) ; chart . PlotModel . Series . Clear ( ) ; PrivateObject algorithmAccessor = new PrivateObject ( algorithm , new PrivateType ( typeof ( GeneticAlgorithm ) ) ) ; algorithmAccessor . Invoke ( " " , new EnvironmentFitnessEvaluatedEventArgs ( new GeneticEnvironment ( algorithm ) , 0 ) ) ; Assert . Single ( chart . PlotModel . Series ) ; }
Tests that the chart refreshes the series when the fitness is evaluated for the initial generation.
Tests that the chart refreshes the series when the fitness is evaluated for the initial generation .
// Clear the series to ensure it gets refreshed when the fitness is evaluated