< Summary

Information
Class: DirectSight.Parser.Analysis.Metric
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/Metric.cs
Line coverage
94%
Covered lines: 80
Uncovered lines: 5
Coverable lines: 85
Total lines: 239
Line coverage: 94.1%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor(...)100%11100%
.ctor(...)50%22100%
.ctor(...)100%11100%
.ctor(...)100%11100%
BranchCoverage(...)100%11100%
SequenceCoverage(...)100%11100%
CyclomaticComplexity(...)100%11100%
NPathComplexity(...)100%11100%
CrapScore(...)100%11100%
ToString()100%110%
Equals(...)50%4475%
GetHashCode()100%11100%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/Metric.cs

#LineLine coverage
 1using System;
 2
 3namespace DirectSight.Parser.Analysis;
 4
 5/// <summary>
 6/// Represents a metric, which is a key/value pair.
 7/// </summary>
 8public class Metric
 9{
 10    /// <summary>
 11    /// The cyclomatic complexity URI.
 12    /// </summary>
 113    private static readonly Uri CyclomaticComplexityUri = new Uri("https://en.wikipedia.org/wiki/Cyclomatic_complexity")
 14
 15    /// <summary>
 16    /// The code coverage URI.
 17    /// </summary>
 118    private static readonly Uri CodeCoverageUri = new Uri("https://en.wikipedia.org/wiki/Code_coverage");
 19
 20    /// <summary>
 21    /// The n path complexity URI.
 22    /// </summary>
 123    private static readonly Uri NPathComplexityUri = new Uri("https://modess.io/npath-complexity-cyclomatic-complexity-e
 24
 25    /// <summary>
 26    /// The crap score URI.
 27    /// </summary>
 128    private static readonly Uri CrapScoreUri = new Uri("https://googletesting.blogspot.de/2011/02/this-code-is-crap.html
 29
 30    /// <summary>
 31    /// The MC/DC Uri.
 32    /// </summary>
 133    private static readonly Uri McdcCoverageUri = new Uri("https://en.wikipedia.org/wiki/Modified_condition/decision_cov
 34
 35    /// <summary>
 36    /// Initializes a new instance of the <see cref="Metric"/> class.
 37    /// </summary>
 38    /// <param name="name">The name.</param>
 39    /// <param name="explanationUrl">The explanation url.</param>
 40    /// <param name="metricType">The type of the metric.</param>
 41    /// <param name="value">The value.</param>
 42    public Metric(string name, Uri explanationUrl, MetricType metricType, decimal? value)
 1043        : this(name, name, explanationUrl, metricType, value)
 1044    {
 1045    }
 46
 47    /// <summary>
 48    /// Initializes a new instance of the <see cref="Metric"/> class.
 49    /// </summary>
 50    /// <param name="name">The name.</param>
 51    /// <param name="abbreviation">The abbreviation.</param>
 52    /// <param name="explanationUrl">The explanation url.</param>
 53    /// <param name="metricType">The type of the metric.</param>
 54    /// <param name="value">The value.</param>
 1474355    public Metric(string name, string abbreviation, Uri explanationUrl, MetricType metricType, decimal? value)
 1474356    {
 1474357        this.Name = name ?? throw new ArgumentNullException(nameof(name));
 1474358        this.Abbreviation = abbreviation.ToLowerInvariant().Replace(" ", string.Empty);
 1474359        this.ExplanationUrl = explanationUrl;
 1474360        this.MetricType = metricType;
 1474361        this.Value = value;
 1474362    }
 63
 64    /// <summary>
 65    /// Initializes a new instance of the <see cref="Metric"/> class.
 66    /// </summary>
 67    /// <param name="name">The name.</param>
 68    /// <param name="explanationUrl">The explanation url.</param>
 69    /// <param name="metricType">The type of the metric.</param>
 70    /// <param name="value">The value.</param>
 71    /// <param name="mergeOrder">The merge order.</param>
 72    public Metric(string name, Uri explanationUrl, MetricType metricType, decimal? value, MetricMergeOrder mergeOrder)
 273        : this(name, name, explanationUrl, metricType, value)
 274    {
 275        this.MergeOrder = mergeOrder;
 276    }
 77
 78    /// <summary>
 79    /// Initializes a new instance of the <see cref="Metric"/> class.
 80    /// </summary>
 81    /// <param name="name">The name.</param>
 82    /// <param name="abbreviation">The abbreviation.</param>
 83    /// <param name="explanationUrl">The explanation url.</param>
 84    /// <param name="metricType">The type of the metric.</param>
 85    /// <param name="value">The value.</param>
 86    /// <param name="mergeOrder">The merge order.</param>
 87    public Metric(string name, string abbreviation, Uri explanationUrl, MetricType metricType, decimal? value, MetricMer
 875788        : this(name, abbreviation, explanationUrl, metricType, value)
 875789    {
 875790        this.MergeOrder = mergeOrder;
 875791    }
 92
 93    /// <summary>
 94    /// Gets the merge order.
 95    /// </summary>
 365596    public MetricMergeOrder MergeOrder { get; }
 97
 98    /// <summary>
 99    /// Gets the name.
 100    /// </summary>
 25651101    public string Name { get; }
 102
 103    /// <summary>
 104    /// Gets the abbreviation.
 105    /// </summary>
 10106    public string Abbreviation { get; }
 107
 108    /// <summary>
 109    /// Gets the explanation url.
 110    /// </summary>
 290111    public Uri ExplanationUrl { get; }
 112
 113    /// <summary>
 114    /// Gets the metric type.
 115    /// </summary>
 792116    public MetricType MetricType { get; }
 117
 118    /// <summary>
 119    /// Gets the value.
 120    /// </summary>
 34341121    public decimal? Value { get; internal set; }
 122
 123    /// <summary>
 124    /// Initializes a new instance of the <see cref="Metric"/> class which represents branch coverage.
 125    /// </summary>
 126    /// <param name="value">The value.</param>
 127    /// <returns>The metric.</returns>
 128    public static Metric BranchCoverage(decimal? value)
 2987129    {
 2987130        return new Metric(
 2987131            "Branch coverage",
 2987132            "bcov",
 2987133            CodeCoverageUri,
 2987134            MetricType.CoveragePercentual,
 2987135            value);
 2987136    }
 137
 138    /// <summary>
 139    /// Initializes a new instance of the <see cref="Metric"/> class which represents sequence coverage.
 140    /// </summary>
 141    /// <param name="value">The value.</param>
 142    /// <returns>The metric.</returns>
 143    public static Metric SequenceCoverage(decimal? value)
 2987144    {
 2987145        return new Metric(
 2987146            "Sequence coverage",
 2987147            "seq",
 2987148            CodeCoverageUri,
 2987149            MetricType.CoveragePercentual,
 2987150            value);
 2987151    }
 152
 153    /// <summary>
 154    /// Initializes a new instance of the <see cref="Metric"/> class which represents cyclomatic complexity.
 155    /// </summary>
 156    /// <param name="value">The value.</param>
 157    /// <returns>The metric.</returns>
 158    public static Metric CyclomaticComplexity(decimal? value)
 2987159    {
 2987160        return new Metric(
 2987161            "Cyclomatic complexity",
 2987162            "cc",
 2987163            CyclomaticComplexityUri,
 2987164            MetricType.CodeQuality,
 2987165            value,
 2987166            MetricMergeOrder.LowerIsBetter);
 2987167    }
 168
 169    /// <summary>
 170    /// Initializes a new instance of the <see cref="Metric"/> class which represents NPath complexity.
 171    /// </summary>
 172    /// <param name="value">The value.</param>
 173    /// <returns>The metric.</returns>
 174    public static Metric NPathComplexity(decimal? value)
 2885175    {
 2885176        return new Metric(
 2885177            "NPath complexity",
 2885178            "npth",
 2885179            NPathComplexityUri,
 2885180            MetricType.CodeQuality,
 2885181            value,
 2885182            MetricMergeOrder.LowerIsBetter);
 2885183    }
 184
 185    /// <summary>
 186    /// Initializes a new instance of the <see cref="Metric"/> class which represents crap score.
 187    /// </summary>
 188    /// <param name="value">The value.</param>
 189    /// <returns>The metric.</returns>
 190    public static Metric CrapScore(decimal? value)
 2885191    {
 2885192        return new Metric(
 2885193            "Crap Score",
 2885194            "crp",
 2885195            CrapScoreUri,
 2885196            MetricType.CodeQuality,
 2885197            value,
 2885198            MetricMergeOrder.LowerIsBetter);
 2885199    }
 200
 201    /// <summary>
 202    /// Returns a <see cref="string" /> that represents this instance.
 203    /// </summary>
 204    /// <returns>
 205    /// A <see cref="string" /> that represents this instance.
 206    /// </returns>
 207    public override string ToString()
 0208    {
 0209        return $"{this.Name}: {this.Value}";
 0210    }
 211
 212    /// <summary>
 213    /// Determines whether the specified <see cref="object"/> is equal to this instance.
 214    /// </summary>
 215    /// <param name="obj">The <see cref="object"/> to compare with this instance.</param>
 216    /// <returns>
 217    ///   <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.
 218    /// </returns>
 219    public override bool Equals(object obj)
 1300220    {
 1300221        if (obj == null || !obj.GetType().Equals(typeof(Metric)))
 0222        {
 0223            return false;
 224        }
 225        else
 1300226        {
 1300227            var metric = (Metric)obj;
 1300228            return metric.Name.Equals(this.Name);
 229        }
 1300230    }
 231
 232    /// <summary>
 233    /// Returns a hash code for this instance.
 234    /// </summary>
 235    /// <returns>
 236    /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 237    /// </returns>
 360238    public override int GetHashCode() => this.Name.GetHashCode();
 239}