| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | |
| | | 4 | | namespace WireMock.Matchers.Request |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// RequestMatchResult |
| | | 8 | | /// </summary> |
| | | 9 | | public class RequestMatchResult : IComparable |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Gets or sets the match-score. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <value> |
| | | 15 | | /// The match-score. |
| | | 16 | | /// </value> |
| | 1822 | 17 | | public double TotalScore { get; private set; } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets or sets the total number of matches. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <value> |
| | | 23 | | /// The total number of matches. |
| | | 24 | | /// </value> |
| | 1863 | 25 | | public int TotalNumber { get; private set; } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets or sets a value indicating whether this instance is perfect match. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <value> |
| | | 31 | | /// <c>true</c> if this instance is perfect match; otherwise, <c>false</c>. |
| | | 32 | | /// </value> |
| | 315 | 33 | | public bool IsPerfectMatch => Math.Abs(TotalScore - TotalNumber) < MatchScores.Tolerance; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets the match percentage. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <value> |
| | | 39 | | /// The match percentage. |
| | | 40 | | /// </value> |
| | 40 | 41 | | public double AverageTotalScore => TotalNumber == 0 ? 0.0 : TotalScore / TotalNumber; |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Gets the match details. |
| | | 45 | | /// </summary> |
| | 751 | 46 | | public IList<KeyValuePair<Type, double>> MatchDetails { get; } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Initializes a new instance of the <see cref="RequestMatchResult"/> class. |
| | | 50 | | /// </summary> |
| | 730 | 51 | | public RequestMatchResult() => MatchDetails = new List<KeyValuePair<Type, double>>(); |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Adds the score. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <param name="matcherType">The matcher Type.</param> |
| | | 57 | | /// <param name="score">The score.</param> |
| | | 58 | | /// <returns>The score.</returns> |
| | | 59 | | public double AddScore(Type matcherType, double score) |
| | 716 | 60 | | { |
| | 716 | 61 | | TotalScore += score; |
| | 716 | 62 | | TotalNumber++; |
| | 716 | 63 | | MatchDetails.Add(new KeyValuePair<Type, double>(matcherType, score)); |
| | | 64 | | |
| | 716 | 65 | | return score; |
| | 716 | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Compares the current instance with another object of the same type and returns an integer that indicates whe |
| | | 70 | | /// </summary> |
| | | 71 | | /// <param name="obj">An object to compare with this instance.</param> |
| | | 72 | | /// <returns> |
| | | 73 | | /// A value that indicates the relative order of the objects being compared. The return value has these meanings |
| | | 74 | | /// </returns> |
| | | 75 | | public int CompareTo(object obj) |
| | 1 | 76 | | { |
| | 1 | 77 | | var compareObj = (RequestMatchResult)obj; |
| | | 78 | | |
| | 1 | 79 | | return compareObj.AverageTotalScore.CompareTo(AverageTotalScore); |
| | 1 | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |