-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#612 Increase percentage accuracy in reports
- Loading branch information
1 parent
baf099b
commit 0a8ce85
Showing
18 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
src/AngularComponents/src/app/components/coverageinfo/viewmodels/helper.class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/ReportGenerator.Core.Test/Common/MathExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Palmmedia.ReportGenerator.Core.Common; | ||
using Xunit; | ||
|
||
namespace Palmmedia.ReportGenerator.Core.Test.Common | ||
{ | ||
public class MathExtensionsTest | ||
{ | ||
[Theory] | ||
[InlineData(1, 1000, 1, 0.1)] | ||
[InlineData(1, 10000, 1, 0)] | ||
[InlineData(1, 100000, 1, 0)] | ||
|
||
[InlineData(1, 1000, 2, 0.1)] | ||
[InlineData(1, 10000, 2, 0.01)] | ||
[InlineData(1, 100000, 2, 0)] | ||
|
||
[InlineData(1, 1000, 3, 0.1)] | ||
[InlineData(1, 10000, 3, 0.01)] | ||
[InlineData(1, 100000, 3, 0.001)] | ||
public void CalculatePercentage(int number1, int number2, int maximumDecimalPlaces, decimal expected) | ||
{ | ||
MathExtensions.MaximumDecimalPlaces = maximumDecimalPlaces; | ||
decimal result = MathExtensions.CalculatePercentage(number1, number2); | ||
Assert.Equal(expected, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Palmmedia.ReportGenerator.Core.Common | ||
{ | ||
/// <summary> | ||
/// Math extensions. | ||
/// </summary> | ||
internal static class MathExtensions | ||
{ | ||
private static int maximumDecimalPlaces = 1; | ||
|
||
private static double factor = 1000; | ||
|
||
private static int divisor = 10; | ||
|
||
/// <summary> | ||
/// Gets or sets the maximum decimal places for coverage quotas / percentages. | ||
/// </summary> | ||
public static int MaximumDecimalPlaces | ||
{ | ||
get | ||
{ | ||
return maximumDecimalPlaces; | ||
} | ||
|
||
set | ||
{ | ||
maximumDecimalPlaces = Math.Min(8, Math.Max(0, value)); | ||
factor = 100 * Math.Pow(10, maximumDecimalPlaces); | ||
divisor = (int)Math.Pow(10, maximumDecimalPlaces); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a <see cref="HashSet<T>"/> from an <see cref="IEnumerable<T>"/>. | ||
/// </summary> | ||
/// <param name="number1">The first number.</param> | ||
/// <param name="number2">The second number.</param> | ||
/// <returns>The percentage.</returns> | ||
internal static decimal CalculatePercentage(int number1, int number2) | ||
{ | ||
if (number2 == 0) | ||
{ | ||
throw new ArgumentException("Number must not be 0", nameof(number2)); | ||
} | ||
|
||
return (decimal)Math.Truncate(factor * (double)number1 / (double)number2) / divisor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/ReportGenerator.Core/Reporting/Builders/Rendering/resources/main.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters