public void BestMaximumFitness_GetResultValue_AllNegative() { 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)-5, 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)-4, result); }
public void BestMaximumFitness_GetResultValue_NullPopulation() { GeneticAlgorithm algorithm = new MockGeneticAlgorithm { SelectionOperator = new MockSelectionOperator(), GeneticEntitySeed = new MockEntity(), PopulationSeed = new MockPopulation(), FitnessEvaluator = new MockFitnessEvaluator(), }; algorithm.Metrics.Add(new BestMaximumFitness()); BestMaximumFitness target = new BestMaximumFitness(); target.Initialize(algorithm); Assert.Throws <ArgumentNullException>(() => target.GetResultValue(null)); }