< Summary

Information
Class: DirectSight.Common.MathExtensions
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Common/MathExtensions.cs
Line coverage
88%
Covered lines: 15
Uncovered lines: 2
Coverable lines: 17
Total lines: 50
Line coverage: 88.2%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
CalculatePercentage(...)50%2266.66%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Common/MathExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace DirectSight.Common;
 5
 6/// <summary>
 7/// Math extensions.
 8/// </summary>
 9internal static class MathExtensions
 10{
 111    private static int maximumDecimalPlaces = 1;
 12
 113    private static double factor = 1000;
 14
 115    private static int divisor = 10;
 16
 17    /// <summary>
 18    /// Gets or sets the maximum decimal places for coverage quotas / percentages.
 19    /// </summary>
 20    public static int MaximumDecimalPlaces
 21    {
 22        get
 223        {
 224            return maximumDecimalPlaces;
 225        }
 26
 27        set
 2028        {
 2029            maximumDecimalPlaces = Math.Min(8, Math.Max(0, value));
 2030            factor = 100 * Math.Pow(10, maximumDecimalPlaces);
 2031            divisor = (int)Math.Pow(10, maximumDecimalPlaces);
 2032        }
 33    }
 34
 35    /// <summary>
 36    /// Creates a <see cref="HashSet&lt;T&gt;"/> from an <see cref="IEnumerable&lt;T&gt;"/>.
 37    /// </summary>
 38    /// <param name="number1">The first number.</param>
 39    /// <param name="number2">The second number.</param>
 40    /// <returns>The percentage.</returns>
 41    internal static decimal CalculatePercentage(int number1, int number2)
 628842    {
 628843        if (number2 == 0)
 044        {
 045            throw new ArgumentException("Number must not be 0", nameof(number2));
 46        }
 47
 628848        return (decimal)Math.Truncate(factor * (double)number1 / (double)number2) / divisor;
 628849    }
 50}