@@ -6,7 +6,7 @@ import scala.reflect.internal.util.SourceFile
66/**
77 * @author Stephen Samuel */
88class Coverage
9- extends StatementCoverage with
9+ extends CoverageMetrics with
1010 MethodBuilders with
1111 java.io.Serializable with
1212 ClassBuilders with
@@ -49,18 +49,18 @@ trait ClassBuilders {
4949 def classCount : Int = classes.size
5050}
5151
52- case class MeasuredMethod (name : String , statements : Iterable [MeasuredStatement ]) extends StatementCoverage
52+ case class MeasuredMethod (name : String , statements : Iterable [MeasuredStatement ]) extends CoverageMetrics
5353
5454case class MeasuredClass (name : String , statements : Iterable [MeasuredStatement ])
55- extends StatementCoverage with MethodBuilders with Numerics
55+ extends CoverageMetrics with MethodBuilders with Numerics
5656
5757case class MeasuredPackage (name : String , statements : Iterable [MeasuredStatement ])
58- extends StatementCoverage with ClassCoverage with ClassBuilders {
58+ extends CoverageMetrics with ClassCoverage with ClassBuilders {
5959 def files = Nil // statements.groupBy(_.source).map(arg => MeasuredFile(arg._1, arg._2))
6060}
6161
6262case class MeasuredFile (source : SourceFile , statements : Iterable [MeasuredStatement ])
63- extends StatementCoverage with ClassCoverage with ClassBuilders {
63+ extends CoverageMetrics with ClassCoverage with ClassBuilders {
6464 def lineStatus (lineNumber : Int ): LineStatus = {
6565 statements.filter(_.line == lineNumber) match {
6666 case i if i.isEmpty => NotInstrumented
@@ -78,6 +78,7 @@ case class MeasuredStatement(location: Location,
7878 start : Int ,
7979 line : Int ,
8080 desc : String ,
81+ branch : Boolean ,
8182 var count : Int = 0 ) extends java.io.Serializable {
8283 def invoked (): Unit = count = count + 1
8384}
@@ -87,17 +88,24 @@ trait Numerics {
8788 def loc = statements.map(stmt => stmt.location.fqn + " :" + stmt.line).toSet.size
8889}
8990
90- case class Location (_package : String , _class : String , classType : ClassType , method : Option [ String ] )
91+ case class Location (_package : String , _class : String , classType : ClassType , method : String )
9192 extends java.io.Serializable {
9293 val fqn = (_package + " ." ).replace(" <empty>." , " " ) + _class
9394}
9495
95- trait StatementCoverage {
96+ trait CoverageMetrics {
9697 val statements : Iterable [MeasuredStatement ]
97- def statementCoverage : Double = invokedStatements / statements.size.toDouble
98+ def statementCount : Int = statements.count(! _.branch)
99+ def invokedStatements : Iterable [MeasuredStatement ] = statements.filter(_.count > 0 )
100+ def invokedStatementCount = invokedStatements.size
101+ def statementCoverage : Double = invokedStatements / statementCount.toDouble
98102 def statementCoverageFormatted : String = " %.2f" .format(statementCoverage * 100 )
99- def statementCount : Int = statements.size
100- def invokedStatements : Int = statements.count(_.count > 0 )
103+ def branches : Iterable [MeasuredStatement ] = statements.filter(_.branch)
104+ def branchCount : Int = branches.size
105+ def invokedBranches : Iterable [MeasuredStatement ] = branches.filter(_.count > 0 )
106+ def invokedBranchesCount = invokedBranches.size
107+ def branchCoverage : Double = invokedBranchesCount / branchCount.toDouble
108+ def branchCoverageFormatted : String = " %.2f" .format(branchCoverage * 100 )
101109}
102110
103111trait ClassCoverage {
0 commit comments