/// <summary> /// Store tournament results. /// </summary> /// <param name="results"> /// The results. /// </param> private void StoreTournamentResults(MiniTournamentResult <TResult> results) { lock (this._genomeToTournamentResultsLock) { for (var rank = 0; rank < results.AllFinishedOrdered.Count; rank++) { var participant = results.AllFinishedOrdered[rank]; // update the rank if (!this.GenomeToTournamentResults.TryGetValue(participant, out var allObservedParticipantResults)) { allObservedParticipantResults = new List <GenomeTournamentResult>(); this.GenomeToTournamentResults[participant] = allObservedParticipantResults; } var result = new GenomeTournamentResult() { TournamentRank = rank + 1, TournamentId = results.MiniTournamentId, Generation = this._selectCommand.CurrentGeneration, }; allObservedParticipantResults.Add(result); } } }
public void NumberOfParticipantsIsComputedCorrectly() { var result = new MiniTournamentResult <TestResult>(5, this._allFinishedOrdered, this._winnerResults); Assert.True( this._allFinishedOrdered.Count == result.NumberOfParticipants, "Number of participants should equal the number of genomes in total ordering."); }
/// <summary> /// Sends evaluation information to <see cref="GenomeEvaluationDelegatorBase{TInstance, TResult}.CommandIssuer"/>. /// </summary> /// <param name="orderedGenomes"><see cref="ImmutableGenome"/>s ordered by run results.</param> protected override void SendInformationToCommandIssuer(ImmutableList <ImmutableGenome> orderedGenomes) { var winners = orderedGenomes.Take(this._numberOfWinners); // Send information to issuer. var miniTournamentWinners = new MiniTournamentResult <TResult>( this._miniTournament.MiniTournamentId, orderedGenomes, winners.ToDictionary(winner => winner, winner => this.FindCurrentRunResults(winner).ToImmutableList())); this.CommandIssuer.Tell(miniTournamentWinners); }
public void WinnerResultsIsSetCorrectly() { var result = new MiniTournamentResult <TestResult>(5, this._allFinishedOrdered, this._winnerResults); var results = result.WinnerResults; Assert.Equal(this._winners.Count, results.Count); foreach (var winner in this._winners) { Console.WriteLine($"Checking results for {winner}..."); Assert.Equal(this._winnerResults[winner], results[winner]); } }
public void MessageIsImmutable() { var result = new MiniTournamentResult <TestResult>(5, this._allFinishedOrdered, this._winnerResults); // Properties are immutable by type, so just check what happens if mutable parts of input are changed. this._allFinishedOrdered.Clear(); this._winnerResults.Clear(); // The message should now be different from the input. Assert.NotEqual( this._allFinishedOrdered.Count, result.AllFinishedOrdered.Count); Assert.NotEqual( this._winnerResults.Count, result.WinnerResults.Count); }
/// <summary> /// Adds a result. /// </summary> /// <param name="result">The result.</param> public void AddResult(MiniTournamentResult <TResult> result) { this.StoreTournamentResults(result); this._miniTournamentResults.Add(result); }
public void AllFinishedOrderedIsSetCorrectly() { var result = new MiniTournamentResult <TestResult>(5, this._allFinishedOrdered, this._winnerResults); Assert.Equal(this._allFinishedOrdered, result.AllFinishedOrdered); }