Summary

Class:WireMock.Matchers.SimMetricsMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\SimMetricsMatcher.cs
Covered lines:17
Uncovered lines:23
Coverable lines:40
Total lines:114
Line coverage:42.5%
Branch coverage:5.2%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
.ctor(...)10100100
IsMatch(...)10100100
GetStringMetricType()191919.0510
GetPatterns()1000
GetName()1000

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\SimMetricsMatcher.cs

#LineLine coverage
 1using System.Linq;
 2using JetBrains.Annotations;
 3using SimMetrics.Net;
 4using SimMetrics.Net.API;
 5using SimMetrics.Net.Metric;
 6using WireMock.Validation;
 7
 8namespace WireMock.Matchers
 9{
 10    /// <summary>
 11    /// SimMetricsMatcher
 12    /// </summary>
 13    /// <seealso cref="IMatcher" />
 14    public class SimMetricsMatcher : IMatcher
 15    {
 16        private readonly string[] _patterns;
 17        private readonly SimMetricType _simMetricType;
 18
 19        /// <summary>
 20        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 21        /// </summary>
 22        /// <param name="pattern">The pattern.</param>
 23        /// <param name="simMetricType">The SimMetric Type</param>
 424        public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : thi
 425        {
 426        }
 27
 28        /// <summary>
 29        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 30        /// </summary>
 31        /// <param name="patterns">The patterns.</param>
 32        /// <param name="simMetricType">The SimMetric Type</param>
 433        public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
 434        {
 435            Check.NotEmpty(patterns, nameof(patterns));
 36
 437            _patterns = patterns;
 438            _simMetricType = simMetricType;
 439        }
 40
 41        /// <summary>
 42        /// Determines whether the specified input is match.
 43        /// </summary>
 44        /// <param name="input">The input string</param>
 45        /// <returns>A value between 0.0 - 1.0 of the similarity.</returns>
 46        public double IsMatch(string input)
 447        {
 448            IStringMetric m = GetStringMetricType();
 49
 850            return MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input)));
 451        }
 52
 53        private IStringMetric GetStringMetricType()
 454        {
 455             switch (_simMetricType)
 56            {
 57                case SimMetricType.BlockDistance:
 058                    return new BlockDistance();
 59                case SimMetricType.ChapmanLengthDeviation:
 060                    return new ChapmanLengthDeviation();
 61                case SimMetricType.CosineSimilarity:
 062                    return new CosineSimilarity();
 63                case SimMetricType.DiceSimilarity:
 064                    return new DiceSimilarity();
 65                case SimMetricType.EuclideanDistance:
 066                    return new EuclideanDistance();
 67                case SimMetricType.JaccardSimilarity:
 068                    return new JaccardSimilarity();
 69                case SimMetricType.Jaro:
 070                    return new Jaro();
 71                case SimMetricType.JaroWinkler:
 072                    return new JaroWinkler();
 73                case SimMetricType.MatchingCoefficient:
 074                    return new MatchingCoefficient();
 75                case SimMetricType.MongeElkan:
 076                    return new MongeElkan();
 77                case SimMetricType.NeedlemanWunch:
 078                    return new NeedlemanWunch();
 79                case SimMetricType.OverlapCoefficient:
 080                    return new OverlapCoefficient();
 81                case SimMetricType.QGramsDistance:
 082                    return new QGramsDistance();
 83                case SimMetricType.SmithWaterman:
 084                    return new SmithWaterman();
 85                case SimMetricType.SmithWatermanGotoh:
 086                    return new SmithWatermanGotoh();
 87                case SimMetricType.SmithWatermanGotohWindowedAffine:
 088                    return new SmithWatermanGotohWindowedAffine();
 89                case SimMetricType.ChapmanMeanLength:
 090                    return new ChapmanMeanLength();
 91                default:
 492                    return new Levenstein();
 93            }
 494        }
 95
 96        /// <summary>
 97        /// Gets the pattern.
 98        /// </summary>
 99        /// <returns>Pattern</returns>
 100        public string[] GetPatterns()
 0101        {
 0102            return _patterns;
 0103        }
 104
 105        /// <summary>
 106        /// Gets the name.
 107        /// </summary>
 108        /// <returns>Name</returns>
 109        public string GetName()
 0110        {
 0111            return $"SimMetricsMatcher.{_simMetricType}";
 0112        }
 113    }
 114}