using System; using System.Collections.Generic; namespace WireMock.Matchers.Request { /// /// RequestMatchResult /// public class RequestMatchResult : IComparable { /// /// Gets or sets the match-score. /// /// /// The match-score. /// public double TotalScore { get; private set; } /// /// Gets or sets the total number of matches. /// /// /// The total number of matches. /// public int TotalNumber { get; private set; } /// /// Gets or sets a value indicating whether this instance is perfect match. /// /// /// true if this instance is perfect match; otherwise, false. /// public bool IsPerfectMatch => Math.Abs(TotalScore - TotalNumber) < MatchScores.Tolerance; /// /// Gets the match percentage. /// /// /// The match percentage. /// public double AverageTotalScore => TotalNumber == 0 ? 0.0 : TotalScore / TotalNumber; /// /// Gets the match details. /// public IList> MatchDetails { get; private set; } /// /// Initializes a new instance of the class. /// public RequestMatchResult() => MatchDetails = new List>(); /// /// Adds the score. /// /// The matcher Type. /// The score. /// The score. public double AddScore(Type matcherType, double score) { TotalScore += score; TotalNumber++; MatchDetails.Add(new KeyValuePair(matcherType, score)); return score; } /// /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. /// /// An object to compare with this instance. /// /// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes in the sort order. Zero This instance occurs in the same position in the sort order as . Greater than zero This instance follows in the sort order. /// /// public int CompareTo(object obj) { var compareObj = (RequestMatchResult)obj; return compareObj.AverageTotalScore.CompareTo(AverageTotalScore); } } }