Skip to content

Commit

Permalink
Merge pull request lucaslorentz#18 from lucaslorentz/refactorings
Browse files Browse the repository at this point in the history
Add method to get instruction line numbers
  • Loading branch information
lucaslorentz authored Feb 9, 2018
2 parents a414897 + 6836702 commit 1bde5e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 11 additions & 1 deletion src/MiniCover/Model/InstrumentedInstruction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MiniCover.Model
using System.Collections.Generic;

namespace MiniCover.Model
{
public class InstrumentedInstruction
{
Expand All @@ -12,5 +14,13 @@ public class InstrumentedInstruction
public string Method { get; set; }
public string MethodFullName { get; set; }
public string Instruction { get; set; }

public IEnumerable<int> GetLines()
{
for (var lineIndex = StartLine; lineIndex <= EndLine; lineIndex++)
{
yield return lineIndex;
}
}
}
}
9 changes: 4 additions & 5 deletions src/MiniCover/Reports/BaseReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public virtual int Execute(InstrumentationResult result, float threshold)
foreach (var kvFile in files)
{
var lines = kvFile.Value.Instructions
.SelectMany(i => Enumerable.Range(i.StartLine, i.EndLine - i.StartLine + 1))
.SelectMany(i => i.GetLines())
.Distinct()
.Count();

var hitInstructions = kvFile.Value.Instructions.Where(h => hits.Contains(h.Id)).ToArray();
var coveredLines = hitInstructions
.SelectMany(i => Enumerable.Range(i.StartLine, i.EndLine - i.StartLine + 1))
var coveredLines = kvFile.Value.Instructions
.Where(h => hits.Contains(h.Id))
.SelectMany(i => i.GetLines())
.Distinct()
.Count();

Expand All @@ -48,7 +48,6 @@ public virtual int Execute(InstrumentationResult result, float threshold)
var fileColor = coveragePercentage >= threshold ? ConsoleColor.Green : ConsoleColor.Red;

WriteReport(kvFile, lines, coveredLines, coveragePercentage, fileColor);

}

WriteDetailedReport(result, files, hits);
Expand Down
8 changes: 3 additions & 5 deletions src/MiniCover/Reports/HtmlReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ protected override void WriteDetailedReport(InstrumentationResult result, IDicti

var uncoveredLineNumbers = new HashSet<int>();
var coveredLineNumbers = new HashSet<int>();
foreach(var i in kvFile.Value.Instructions)
foreach (var i in kvFile.Value.Instructions)
{
if (hits.Contains(i.Id))
{
for (var lineIndex = i.StartLine; lineIndex <= i.EndLine; lineIndex++)
coveredLineNumbers.Add(lineIndex);
coveredLineNumbers.UnionWith(i.GetLines());
}
else
{
for (var lineIndex = i.StartLine; lineIndex <= i.EndLine; lineIndex++)
uncoveredLineNumbers.Add(lineIndex);
uncoveredLineNumbers.UnionWith(i.GetLines());
}
}

Expand Down

0 comments on commit 1bde5e8

Please sign in to comment.