Summary

Class:WireMock.Matchers.SimMetricsMatcher
Assembly:WireMock.Net
File(s):C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\SimMetricsMatcher.cs
Covered lines:29
Uncovered lines:17
Coverable lines:46
Total lines:125
Line coverage:63%
Branch coverage:10.5%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
IsMatch(...)0010
GetStringMetricType()000.190.105
GetPatterns()0010
.ctor(...)0010
.ctor(...)0010
.ctor(...)0010
.ctor(...)0010

File(s)

C:\Users\StefHeyenrath\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="IStringMatcher" />
 14    public class SimMetricsMatcher : IStringMatcher
 15    {
 16        private readonly string[] _patterns;
 17        private readonly SimMetricType _simMetricType;
 18
 19        /// <inheritdoc cref="IMatcher.MatchBehaviour"/>
 420        public MatchBehaviour MatchBehaviour { get; }
 21
 22        /// <summary>
 23        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 24        /// </summary>
 25        /// <param name="pattern">The pattern.</param>
 26        /// <param name="simMetricType">The SimMetric Type</param>
 527        public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : thi
 528        {
 529        }
 30
 31        /// <summary>
 32        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 33        /// </summary>
 34        /// <param name="matchBehaviour">The match behaviour.</param>
 35        /// <param name="pattern">The pattern.</param>
 36        /// <param name="simMetricType">The SimMetric Type</param>
 337        public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern, SimMetricType simMetricType = 
 338        {
 339        }
 40
 41        /// <summary>
 42        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 43        /// </summary>
 44        /// <param name="patterns">The patterns.</param>
 45        /// <param name="simMetricType">The SimMetric Type</param>
 546        public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein) : 
 547        {
 548        }
 49
 50        /// <summary>
 51        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 52        /// </summary>
 53        /// <param name="matchBehaviour">The match behaviour.</param>
 54        /// <param name="patterns">The patterns.</param>
 55        /// <param name="simMetricType">The SimMetric Type</param>
 856        public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType
 857        {
 858            Check.NotNullOrEmpty(patterns, nameof(patterns));
 59
 860            MatchBehaviour = matchBehaviour;
 861            _patterns = patterns;
 862            _simMetricType = simMetricType;
 863        }
 64
 65        /// <inheritdoc cref="IStringMatcher.IsMatch"/>
 66        public double IsMatch(string input)
 467        {
 468            IStringMetric m = GetStringMetricType();
 69
 1270            return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_patterns.Select(p => m.GetSimilarit
 471        }
 72
 73        private IStringMetric GetStringMetricType()
 474        {
 475            switch (_simMetricType)
 76            {
 77                case SimMetricType.BlockDistance:
 078                    return new BlockDistance();
 79                case SimMetricType.ChapmanLengthDeviation:
 080                    return new ChapmanLengthDeviation();
 81                case SimMetricType.CosineSimilarity:
 082                    return new CosineSimilarity();
 83                case SimMetricType.DiceSimilarity:
 084                    return new DiceSimilarity();
 85                case SimMetricType.EuclideanDistance:
 086                    return new EuclideanDistance();
 87                case SimMetricType.JaccardSimilarity:
 088                    return new JaccardSimilarity();
 89                case SimMetricType.Jaro:
 090                    return new Jaro();
 91                case SimMetricType.JaroWinkler:
 092                    return new JaroWinkler();
 93                case SimMetricType.MatchingCoefficient:
 094                    return new MatchingCoefficient();
 95                case SimMetricType.MongeElkan:
 096                    return new MongeElkan();
 97                case SimMetricType.NeedlemanWunch:
 098                    return new NeedlemanWunch();
 99                case SimMetricType.OverlapCoefficient:
 0100                    return new OverlapCoefficient();
 101                case SimMetricType.QGramsDistance:
 0102                    return new QGramsDistance();
 103                case SimMetricType.SmithWaterman:
 0104                    return new SmithWaterman();
 105                case SimMetricType.SmithWatermanGotoh:
 0106                    return new SmithWatermanGotoh();
 107                case SimMetricType.SmithWatermanGotohWindowedAffine:
 0108                    return new SmithWatermanGotohWindowedAffine();
 109                case SimMetricType.ChapmanMeanLength:
 0110                    return new ChapmanMeanLength();
 111                default:
 4112                    return new Levenstein();
 113            }
 4114        }
 115
 116        /// <inheritdoc cref="IStringMatcher.GetPatterns"/>
 117        public string[] GetPatterns()
 3118        {
 3119            return _patterns;
 3120        }
 121
 122        /// <inheritdoc cref="IMatcher.Name"/>
 1123        public string Name => $"SimMetricsMatcher.{_simMetricType}";
 124    }
 125}