@@ -138,7 +138,9 @@ void GetSequencePoints() {
138138 sp . EndColumn = ( int ) GetDecimalAttributeValue ( xSPoint . Attribute ( "ec" ) ) ;
139139 sp . VisitCount = ( int ) GetDecimalAttributeValue ( xSPoint . Attribute ( "vc" ) ) ;
140140 sp . Offset = ( int ) GetDecimalAttributeValue ( xSPoint . Attribute ( "offset" ) ) ;
141- sp . BranchCoverage = true ;
141+ sp . BranchExitsCount = ( int ) GetDecimalAttributeValue ( xSPoint . Attribute ( "bec" ) ) ;
142+ sp . BranchExitsVisit = ( int ) GetDecimalAttributeValue ( xSPoint . Attribute ( "bev" ) ) ;
143+ sp . BranchCoverage = ( sp . BranchExitsCount == sp . BranchExitsVisit ) ;
142144 sp . Content = String . Empty ;
143145 sp . Length = 0 ;
144146
@@ -306,46 +308,21 @@ void GetBranchRatio () {
306308 // This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Ensures)
307309 if ( this . BodyFinalSP == null ) { return ; } // empty body
308310
309- // Connect Sequence & Branches
310- IEnumerator < CodeCoverageSequencePoint > SPEnumerator = this . SequencePoints . GetEnumerator ( ) ;
311- CodeCoverageSequencePoint currSeqPoint = this . BodyStartSP ;
312- int nextSeqPointOffset = BodyStartSP . Offset ;
313-
314- foreach ( var bp in this . BranchPoints ) {
315-
316- // ignore branches outside of method body offset range
317- if ( bp . Offset < BodyStartSP . Offset )
318- continue ;
319- if ( bp . Offset > BodyFinalSP . Offset )
320- break ;
321-
322- // Sync with SequencePoint
323- while ( nextSeqPointOffset < bp . Offset ) {
324- currSeqPoint = SPEnumerator . Current ;
325- if ( SPEnumerator . MoveNext ( ) ) {
326- nextSeqPointOffset = SPEnumerator . Current . Offset ;
327- } else {
328- nextSeqPointOffset = int . MaxValue ;
329- }
330- }
331- if ( currSeqPoint . Branches == null ) {
332- currSeqPoint . Branches = new List < CodeCoverageBranchPoint > ( ) ;
333- }
334- // Add Branch to Branches
335- currSeqPoint . Branches . Add ( bp ) ;
336- }
337-
338- // Merge sp.Branches on exit-offset
339311 // Calculate Method Branch coverage
340312 int totalBranchVisit = 0 ;
341313 int totalBranchCount = 0 ;
342- int pointBranchVisit = 0 ;
343- int pointBranchCount = 0 ;
344- Dictionary < int , CodeCoverageBranchPoint > bpExits = new Dictionary < int , CodeCoverageBranchPoint > ( ) ;
345314 foreach ( var sp in this . SequencePoints ) {
346315
347- // SequencePoint covered & has branches?
348- if ( sp . VisitCount != 0 && sp . Branches != null ) {
316+ // SequencePoint is visited?
317+ if ( sp . VisitCount != 0 ) {
318+
319+ // Don't want branch coverage of ccrewrite(n)
320+ // SequencePoint's with offset before and after method body
321+ if ( sp . Offset < BodyStartSP . Offset ||
322+ sp . Offset > BodyFinalSP . Offset ) {
323+ sp . BranchCoverage = true ;
324+ continue ; // skip
325+ }
349326
350327 // 1) Generated "in" code for IEnumerables contains hidden "try/catch/finally" branches that
351328 // one do not want or cannot cover by test-case because is handled earlier at same method.
@@ -360,36 +337,13 @@ void GetBranchRatio () {
360337 sp . Content . StartsWith ( "Contract." ) ||
361338 sp . Content . StartsWith ( "Contract " )
362339 ) {
363- sp . Branches = null ;
340+ sp . BranchCoverage = true ;
364341 continue ; // skip
365342 }
366343
367- // Merge sp.Branches on OffsetEnd using bpExits key
368- bpExits . Clear ( ) ;
369- foreach ( var bp in sp . Branches ) {
370- if ( ! bpExits . ContainsKey ( bp . OffsetEnd ) ) {
371- bpExits [ bp . OffsetEnd ] = bp ; // insert branch
372- } else {
373- bpExits [ bp . OffsetEnd ] . VisitCount += bp . VisitCount ; // update branch
374- }
375- }
376-
377- // Compute branch coverage
378- pointBranchVisit = 0 ;
379- pointBranchCount = 0 ;
380- foreach ( var bp in bpExits . Values ) {
381- pointBranchVisit += bp . VisitCount == 0 ? 0 : 1 ;
382- pointBranchCount += 1 ;
383- }
384- // Not full coverage?
385- if ( pointBranchVisit != pointBranchCount ) {
386- sp . BranchCoverage = false ; // => part-covered
387- }
388- totalBranchVisit += pointBranchVisit ;
389- totalBranchCount += pointBranchCount ;
344+ totalBranchCount += sp . BranchExitsCount ;
345+ totalBranchVisit += sp . BranchExitsVisit ;
390346 }
391- if ( sp . Branches != null )
392- sp . Branches = null ; // release memory
393347 }
394348
395349 this . BranchCoverageRatio = ( totalBranchCount != 0 ) ? new Tuple < int , int > ( totalBranchVisit , totalBranchCount ) : null ;
0 commit comments