< Summary

Information
Class: DirectSight.Parser.Analysis.MethodMetric
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/MethodMetric.cs
Line coverage
91%
Covered lines: 55
Uncovered lines: 5
Coverable lines: 60
Total lines: 151
Line coverage: 91.6%
Branch coverage
94%
Covered branches: 17
Total branches: 18
Branch coverage: 94.4%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
ToString()100%110%
Equals(...)100%66100%
GetHashCode()100%11100%
AddMetric(...)100%11100%
AddMetrics(...)100%11100%
Merge(...)91.66%121293.54%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace DirectSight.Parser.Analysis;
 6
 7/// <summary>
 8/// Represents the metrics of a method.
 9/// </summary>
 10public class MethodMetric
 11{
 12    /// <summary>
 13    /// List of metrics.
 14    /// </summary>
 299615    private readonly List<Metric> metrics = [];
 16
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="MethodMetric"/> class.
 19    /// </summary>
 20    /// <param name="fullName">The full method name.</param>
 21    /// <param name="shortName">The short method name.</param>
 22    /// <param name="metrics">The metrics.</param>
 299623    public MethodMetric(string fullName, string shortName, IEnumerable<Metric> metrics)
 299624    {
 299625        this.FullName = fullName;
 299626        this.ShortName = shortName;
 299627        this.AddMetrics(metrics);
 299628    }
 29
 30    /// <summary>
 31    /// Gets the list of metrics.
 32    /// </summary>
 61533    public IEnumerable<Metric> Metrics => this.metrics;
 34
 35    /// <summary>
 36    /// Gets the full name of the method.
 37    /// </summary>
 641038    public string FullName { get; }
 39
 40    /// <summary>
 41    /// Gets the name of the method.
 42    /// </summary>
 7343    public string ShortName { get; }
 44
 45    /// <summary>
 46    /// Gets the line number.
 47    /// </summary>
 48    /// <value>
 49    /// The line number.
 50    /// </value>
 770051    public int? Line { get; internal set; }
 52
 53    /// <summary>
 54    /// Returns a <see cref="string" /> that represents this instance.
 55    /// </summary>
 56    /// <returns>
 57    /// A <see cref="string" /> that represents this instance.
 58    /// </returns>
 59    public override string ToString()
 060    {
 061        return this.ShortName;
 062    }
 63
 64    /// <summary>
 65    /// Determines whether the specified <see cref="object"/> is equal to this instance.
 66    /// </summary>
 67    /// <param name="obj">The <see cref="object"/> to compare with this instance.</param>
 68    /// <returns>
 69    ///   <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.
 70    /// </returns>
 71    public override bool Equals(object obj)
 167472    {
 167473        if (obj == null || !obj.GetType().Equals(typeof(MethodMetric)))
 274        {
 275            return false;
 76        }
 77        else
 167278        {
 167279            var methodMetric = (MethodMetric)obj;
 167280            return methodMetric.FullName.Equals(this.FullName) && methodMetric.Line == this.Line;
 81        }
 167482    }
 83
 84    /// <summary>
 85    /// Returns a hash code for this instance.
 86    /// </summary>
 87    /// <returns>
 88    /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 89    /// </returns>
 298890    public override int GetHashCode() => this.FullName.GetHashCode() + this.Line.GetHashCode();
 91
 92    /// <summary>
 93    /// Adds the given metric.
 94    /// </summary>
 95    /// <param name="metric">The metric.</param>
 96    internal void AddMetric(Metric metric)
 297    {
 298        this.metrics.Add(metric);
 299    }
 100
 101    /// <summary>
 102    /// Adds the given metrics.
 103    /// </summary>
 104    /// <param name="metrics">The metrics to add.</param>
 105    internal void AddMetrics(IEnumerable<Metric> metrics)
 2996106    {
 2996107        this.metrics.AddRange(metrics);
 2996108    }
 109
 110    /// <summary>
 111    /// Merges the given method metric with the current instance.
 112    /// </summary>
 113    /// <param name="methodMetric">The method metric to merge.</param>
 114    internal void Merge(MethodMetric methodMetric)
 752115    {
 752116        if (methodMetric == null)
 0117        {
 0118            throw new ArgumentNullException(nameof(methodMetric));
 119        }
 120
 9574121        foreach (var metric in methodMetric.metrics)
 3659122        {
 14485123            var existingMetric = this.metrics.FirstOrDefault(m => m.Name == metric.Name);
 3659124            if (existingMetric != null)
 3658125            {
 3658126                if (existingMetric.Value.HasValue)
 3656127                {
 3656128                    if (metric.Value.HasValue)
 3655129                    {
 3655130                        if (metric.MergeOrder == MetricMergeOrder.HigherIsBetter)
 1503131                        {
 1503132                            existingMetric.Value = Math.Max(existingMetric.Value.Value, metric.Value.Value);
 1503133                        }
 134                        else
 2152135                        {
 2152136                            existingMetric.Value = Math.Min(existingMetric.Value.Value, metric.Value.Value);
 2152137                        }
 3655138                    }
 3656139                }
 140                else
 2141                {
 2142                    existingMetric.Value = metric.Value;
 2143                }
 3658144            }
 145            else
 1146            {
 1147                this.AddMetric(metric);
 1148            }
 3659149        }
 752150    }
 151}