Skip to content

Commit

Permalink
Fix branch % (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Feb 23, 2024
1 parent ad2b27a commit c5b0d4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Testing/Coverage/CoverageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class CoverageBase
/// <summary>
/// Covered lines (OutOfScript are not taken into account)
/// </summary>
public int CoveredBranches => Branches.Where(u => !u.OutOfScript && u.Hits > 0).Count();
public int CoveredBranches => Branches.Where(u => !u.OutOfScript).Sum(u => u.Hits);

/// <summary>
/// All lines that have been touched
Expand Down
23 changes: 11 additions & 12 deletions src/Neo.SmartContract.Testing/Coverage/CoverageBranch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;

namespace Neo.SmartContract.Testing.Coverage
Expand All @@ -24,17 +23,17 @@ public class CoverageBranch
/// <summary>
/// Hits
/// </summary>
public int Hits => (PositivePathHits > 0 ? 1 : 0) + (NegativePathHits > 0 ? 1 : 0);
public int Hits => (HitsPath1 > 0 ? 1 : 0) + (HitsPath2 > 0 ? 1 : 0);

/// <summary>
/// Positive path hits
/// Path 2 hits
/// </summary>
public int PositivePathHits { get; set; }
public int HitsPath1 { get; set; }

/// <summary>
/// Negative Path hits
/// Path 2 hits
/// </summary>
public int NegativePathHits { get; set; }
public int HitsPath2 { get; set; }

/// <summary>
/// Constructor
Expand All @@ -54,8 +53,8 @@ public CoverageBranch(int offset, bool outOfScript = false)
/// <param name="value">Value</param>
public void Hit(bool value)
{
if (value) PositivePathHits++;
else NegativePathHits++;
if (value) HitsPath1++;
else HitsPath2++;
}

/// <summary>
Expand All @@ -64,8 +63,8 @@ public void Hit(bool value)
/// <param name="value">Value</param>
public void Hit(CoverageBranch value)
{
PositivePathHits += value.PositivePathHits;
NegativePathHits += value.NegativePathHits;
HitsPath1 += value.HitsPath1;
HitsPath2 += value.HitsPath2;
}

/// <summary>
Expand All @@ -76,8 +75,8 @@ public CoverageBranch Clone()
{
return new CoverageBranch(Offset, OutOfScript)
{
NegativePathHits = NegativePathHits,
PositivePathHits = PositivePathHits
HitsPath1 = HitsPath1,
HitsPath2 = HitsPath2
};
}
}
Expand Down

0 comments on commit c5b0d4f

Please sign in to comment.