| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | |
| | | 4 | | namespace WireMock.Matchers |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// MatchScores |
| | | 8 | | /// </summary> |
| | | 9 | | public static class MatchScores |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// The tolerance |
| | | 13 | | /// </summary> |
| | | 14 | | public const double Tolerance = 0.0001; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// The default mismatch score |
| | | 18 | | /// </summary> |
| | | 19 | | public const double Mismatch = 0.0; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// The default perfect match score |
| | | 23 | | /// </summary> |
| | | 24 | | public const double Perfect = 1.0; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// The almost perfect match score |
| | | 28 | | /// </summary> |
| | | 29 | | public const double AlmostPerfect = 0.99; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Convert a bool to the score. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="value">if set to <c>true</c> [value].</param> |
| | | 35 | | /// <returns>score</returns> |
| | | 36 | | public static double ToScore(bool value) |
| | 718 | 37 | | { |
| | 718 | 38 | | return value ? Perfect : Mismatch; |
| | 718 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Calculates the score from multiple funcs. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="values">The values.</param> |
| | | 45 | | /// <returns>average score</returns> |
| | | 46 | | public static double ToScore(IEnumerable<bool> values) |
| | 408 | 47 | | { |
| | 408 | 48 | | return values.Any() ? values.Select(ToScore).Average() : Mismatch; |
| | 408 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Calculates the score from multiple funcs. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="values">The values.</param> |
| | | 55 | | /// <returns>average score</returns> |
| | | 56 | | public static double ToScore(IEnumerable<double> values) |
| | 4 | 57 | | { |
| | 4 | 58 | | return values.Any() ? values.Average() : Mismatch; |
| | 4 | 59 | | } |
| | | 60 | | } |
| | | 61 | | } |