-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed to calculate based on the average coverage of the modules #479
Conversation
Diego can you add some tests here https://github.com/tonerdo/coverlet/blob/master/test/coverlet.core.tests/CoverageSummaryTests.cs? |
Just a suggestion... could you use |
src/coverlet.console/Program.cs
Outdated
foreach (var _module in result.Modules) | ||
{ | ||
var linePercent = summary.CalculateLineCoverage(_module.Value).Percent; | ||
var branchPercent = summary.CalculateBranchCoverage(_module.Value).Percent; | ||
var methodPercent = summary.CalculateMethodCoverage(_module.Value).Percent; | ||
|
||
coverageTable.AddRow(Path.GetFileNameWithoutExtension(_module.Key), $"{linePercent}%", $"{branchPercent}%", $"{methodPercent}%"); | ||
coverageTable.AddRow(Path.GetFileNameWithoutExtension(_module.Key), $"{linePercent.ToString("0.00")}%", $"{branchPercent.ToString("0.00")}%", $"{methodPercent.ToString("0.00")}%"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need do ToString("0.00")
. Percent
property already takes care of rounding down to 2 decimal precision.
src/coverlet.console/Program.cs
Outdated
@@ -187,8 +191,8 @@ static int Main(string[] args) | |||
coverageTable.Rows.Clear(); | |||
|
|||
coverageTable.AddColumn(new[] { "", "Line", "Branch", "Method" }); | |||
coverageTable.AddRow("Total", $"{totalLinePercent}%", $"{totalBranchPercent}%", $"{totalMethodPercent}%"); | |||
coverageTable.AddRow("Average", $"{totalLinePercent / numModules}%", $"{totalBranchPercent / numModules}%", $"{totalMethodPercent / numModules}%"); | |||
coverageTable.AddRow("Total", $"{totalLinePercent.ToString("0.00")}%", $"{totalBranchPercent.ToString("0.00")}%", $"{totalMethodPercent.ToString("0.00")}%"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here... Percent
property of CoverageDetails
class takes care of rounding down.
src/coverlet.core/CoverageDetails.cs
Outdated
@@ -6,6 +6,7 @@ public class CoverageDetails | |||
{ | |||
public double Covered { get; internal set; } | |||
public int Total { get; internal set; } | |||
public double AverageModulePercent { get; internal set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought... can we do rounding down to 2 decimal precision here itself? In getter
, we can return value after rounding down to 2 decimal precision at max. So to keep rounding decision at one place.
By this way, we can avoid doing .ToString("0.00")
for displaying average at different place.
Upto @MarcoRossignoli @tonerdo for final thoughts though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with u, at first try I wrote with this approach, just more verbose than ToString("0.00")
, but as u said we have different outputs if only use string format:
Ex: threshold value is "85.25" and lets say line value is "85.2463", then if condition will evaluate to true and we output coverage failed for average threshold. But while displaying, we print "85.25" because we do ToString("0.00") which will do normal rounding.
I realized about it, but I needed another oint of view, tks! I'll work on it
src/coverlet.core/CoverageSummary.cs
Outdated
@@ -53,12 +53,15 @@ public CoverageDetails CalculateLineCoverage(Documents documents) | |||
public CoverageDetails CalculateLineCoverage(Modules modules) | |||
{ | |||
var details = new CoverageDetails(); | |||
var accumPercent = 0.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make it more obvious, can you do var accumPercent = 0.0D
src/coverlet.console/Program.cs
Outdated
@@ -172,13 +172,17 @@ static int Main(string[] args) | |||
var totalBranchPercent = summary.CalculateBranchCoverage(result.Modules).Percent; | |||
var totalMethodPercent = summary.CalculateMethodCoverage(result.Modules).Percent; | |||
|
|||
var averageLinePercent = summary.CalculateLineCoverage(result.Modules).AverageModulePercent; | |||
var averageBranchPercent = summary.CalculateBranchCoverage(result.Modules).AverageModulePercent; | |||
var averageMethodPercent = summary.CalculateMethodCoverage(result.Modules).AverageModulePercent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can reuse objects from line# 171, 172 and 173, then get total percent and average percent from those CoverageDetails
object for each type line, branch and module respectively. This way we avoid doing recalculation and get some perf benefit. What you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it need a refactoring
@MarcoRossignoli I did review since I worked on this section last time. Let me know if you want to remove my comments. I am doing review first time in Github so I am not sure whether I did it right or messed up something. |
@sasivishnu absolutely NOT! |
@MarcoRossignoli Tests added. Maybe I shouldnt 😬 coz:
but I saw a couple of commits... |
@@ -75,8 +75,52 @@ private void SetupData() | |||
_modules.Add("module", documents); | |||
} | |||
|
|||
private void SetupAditionalData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename SetupDataForAverageCalculation
and call inside constructor CoverageSummaryTests
one time togheter with others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename is done,.... but if SetupDataForAverageCalculation is called into the constructor, previous tests will fail because initial data will have two modules.
I want to have two scnearios to test, one with one module(TestCalculateBranchCoverage_OneModule), and other with multiple modules (TestCalculateBranchCoverage_Modules).... what do u think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer custom private fields with custom setup for tests for instance
private Modules _averageCalculationSingleModule;
private Modules _averageCalculationMultiModule;
and load in constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed... pls take a look at line 123 (LMK if its ok) => I want to reuse data from SetupDataSingleModule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it's ok, some nits and LGTM
Were there issues here?I don't think we should touch that code in this PR, better keep the focus on issue topic. |
src/coverlet.core/CoverageDetails.cs
Outdated
private double averageModulePercent; | ||
public double AverageModulePercent | ||
{ | ||
get { return Math.Round(averageModulePercent, 2); ; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: double token ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you do return Math.Floor(averageModulePercent * 100)/100;
To keep consistency with the way Coverlet handles rounding. We round down using floor. You can refer Percent
property below this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Yep, agree with @MarcoRossignoli here. No need to change any alignment as part of this PR. Please open new issue to discuss regarding your alignment proposal. |
There isnt a issue at all, it is just a visual aligment for number. It is not really important so I reverted the code. |
LGTM |
src/coverlet.core/CoverageDetails.cs
Outdated
@@ -6,6 +6,13 @@ public class CoverageDetails | |||
{ | |||
public double Covered { get; internal set; } | |||
public int Total { get; internal set; } | |||
private double averageModulePercent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move this field on top of class and change in _averageModulePercent
public class CoverageDetails
{
private double _averageModulePercent;
public double Covered { get; internal set; }
public int Total { get; internal set; }
public double AverageModulePercent
{
get { return Math.Floor(_averageModulePercent * 100) / 100; }
internal set { _averageModulePercent = value; }
}
public double Percent => Total == 0 ? 100D : Math.Floor((Covered / Total) * 10000) / 100;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coverlet.core/CoverageResult.cs
Outdated
double line = 0; | ||
double branch = 0; | ||
double method = 0; | ||
var line = summary.CalculateLineCoverage(Modules).AverageModulePercent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: double
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done... just one thing: lines 173 to 175 & 225 to 227 are using var
, LMK if var o double is better, I can do a quick push if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please push fast update to keep style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule I follow is "if the type is clear from assignment it's ok var but if it's not clear better make clean".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
|
||
Branches branches = new Branches | ||
{ | ||
new BranchInfo { Line = 1, Hits = 1, Offset = 1, Path = 0, Ordinal = 1 },//covered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add space before comments } // covered
everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thank's Diego!
thank's also to @sasivishnu for help on review!
@tonerdo I merged this stale bug fix. |
Fixes #346
Minor changes to calculate Average (console's table) based on average from all projects. Im not sure if it is ok only to modify CalculateLineCoverage(Modules modules) functions.
Also a change in CoverageResult.cs just to keep same logic, because its switch-case (ThresholdStatistic.Average) was working well (average based on average from all projects).